Skip to content

Commit

Permalink
Fix IdentityOf tuple introduced in v1.2.0 (#24)
Browse files Browse the repository at this point in the history
Fixes #23

- Upgraded PAPI to `0.4.0` (no longer using the `next` versions).
- Removed unused dependencies
- Migrated to vitest
- Fixed `Identity` object now being a tuple of type
`[IdentityOf,BoundedVec]` introduced as as breaking change in v1.2.0
  • Loading branch information
Bullrich authored Apr 23, 2024
1 parent b01c274 commit a1badee
Show file tree
Hide file tree
Showing 10 changed files with 1,837 additions and 2,120 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /action

COPY package.json yarn.lock ./

COPY collectives.scale relay.scale polkadot-api.json ./
COPY collectives.scale polkadot.scale polkadot-api.json ./

RUN yarn install --frozen-lockfile

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ outputs:

runs:
using: 'docker'
image: 'docker://ghcr.io/paritytech/get-fellows-action/action:1.1.1'
image: 'docker://ghcr.io/paritytech/get-fellows-action/action:1.1.2'
Binary file modified collectives.scale
Binary file not shown.
20 changes: 6 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "get-fellows-action",
"version": "1.1.1",
"version": "1.1.2",
"description": "Fetch all the GitHub handles from the Fellows",
"main": "src/index.ts",
"scripts": {
"start": "node dist",
"build": "ncc build --license LICENSE",
"postinstall": "papi",
"test": "jest",
"test": "vitest",
"fix": "eslint --fix 'src/**/*'",
"lint": "eslint 'src/**/*'"
},
Expand All @@ -24,21 +24,13 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^5.1.1",
"@octokit/webhooks-types": "^7.3.1",
"@polkadot-api/cli": "0.0.1-28172e65e6c4fb53198b9932ff624f8eef05fe68.1.0",
"@polkadot-api/client": "0.0.1-28172e65e6c4fb53198b9932ff624f8eef05fe68.1.0",
"@polkadot-api/node-polkadot-provider": "0.0.1-28172e65e6c4fb53198b9932ff624f8eef05fe68.1.0",
"@polkadot-api/sm-provider": "0.0.1-28172e65e6c4fb53198b9932ff624f8eef05fe68.1.0",
"@substrate/connect-known-chains": "^1.1.2",
"polkadot-api": "^0.4.0",
"smoldot": "2.0.22"
},
"devDependencies": {
"@eng-automation/js-style": "^2.3.0",
"@types/jest": "^29.5.5",
"@eng-automation/js-style": "^2.3.1",
"@vercel/ncc": "^0.38.0",
"jest": "^29.7.0",
"jest-mock-extended": "^3.0.5",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"vitest": "^1.5.0"
}
}
10 changes: 4 additions & 6 deletions polkadot-api.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"relay": {
"outputFolder": "src/codegen",
"chain": "polkadot",
"metadata": "relay.scale"
"polkadot": {
"wsUrl": "wss://rpc.polkadot.io",
"metadata": "polkadot.scale"
},
"collectives": {
"outputFolder": "src/codegen",
"wsUrl": "wss://polkadot-collectives-rpc.polkadot.io",
"metadata": "collectives.scale"
}
}
}
Binary file added polkadot.scale
Binary file not shown.
Binary file removed relay.scale
Binary file not shown.
75 changes: 39 additions & 36 deletions src/fellows.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { createClient, SS58String } from "@polkadot-api/client";
import { getChain } from "@polkadot-api/node-polkadot-provider";
import { getSmProvider } from "@polkadot-api/sm-provider";
import {
polkadot,
polkadot_collectives,
} from "@substrate/connect-known-chains";
import { collectives, polkadot } from "@polkadot-api/descriptors";
import { Binary, createClient, SS58String } from "polkadot-api";
import { chainSpec as polkadotChainSpec } from "polkadot-api/chains/polkadot";
import { chainSpec as collectivesChainSpec } from "polkadot-api/chains/polkadot_collectives";
import { getSmProvider } from "polkadot-api/sm-provider";
import { start } from "smoldot";

import collectiveDescriptor from "./codegen/collectives";
import relayDescriptor from "./codegen/relay";
import { ActionLogger } from "./github/types";

type FellowData = { address: string; rank: number };
Expand All @@ -26,19 +22,15 @@ export const fetchAllFellows = async (
const smoldot = start();

try {
const relayChain = await smoldot.addChain({
chainSpec: polkadot,
disableJsonRpc: true,
const smoldotRelayChain = await smoldot.addChain({
chainSpec: polkadotChainSpec,
});

const jsonRpcProvider = getSmProvider(smoldotRelayChain);
logger.info("Initializing the relay client");
const relayClient = createClient(
getChain({
provider: getSmProvider(smoldot, polkadot),
keyring: [],
}),
);
const relayApi = relayClient.getTypedApi(relayDescriptor);
const polkadotClient = createClient(jsonRpcProvider);

const relayApi = polkadotClient.getTypedApi(polkadot);

const getGhHandle = async (
address: SS58String,
Expand All @@ -48,14 +40,26 @@ export const fetchAllFellows = async (
await relayApi.query.Identity.IdentityOf.getValue(address);

if (identity) {
const handle = identity.info.additional
.find(([key]) => key.value?.asText() === "github")?.[1]
.value?.asText()
const additional = identity[0].info.additional.find(
([key]) => (key.value as Binary)?.asText() === "github",
);

if (!additional) {
logger.debug(
`'${address}' does not have an additional field named 'github'`,
);
return;
}

const handle = (additional[1].value as Binary)
.asText()
.replace("@", "");

if (handle) {
logger.info(`Found github handle for '${address}': '${handle}'`);
} else {
logger.debug(`'${address}' does not have a GitHub handle`);
return;
}
return handle;
}
Expand All @@ -80,21 +84,23 @@ export const fetchAllFellows = async (
};

logger.info("Initializing the collectives client");
const collectivesClient = createClient(
getChain({
provider: getSmProvider(smoldot, {
potentialRelayChains: [relayChain],
chainSpec: polkadot_collectives,
}),
keyring: [],
}),
);
const collectivesApi = collectivesClient.getTypedApi(collectiveDescriptor);

const collectiveRelayChain = await smoldot.addChain({
chainSpec: collectivesChainSpec,
potentialRelayChains: [smoldotRelayChain],
});
const collectiveJsonRpcProvider = getSmProvider(collectiveRelayChain);
logger.info("Initializing the relay client");
const collectivesClient = createClient(collectiveJsonRpcProvider);
const collectivesApi = collectivesClient.getTypedApi(collectives);

// Pull the members of the FellowshipCollective
const memberEntries =
await collectivesApi.query.FellowshipCollective.Members.getEntries();

// We no longer need the collective client, so let's destroy it
collectivesClient.destroy();

// Build the Array of FellowData and filter out candidates (zero rank members)
const fellows: FellowData[] = memberEntries
.map(({ keyArgs: [address], value: rank }) => {
Expand All @@ -103,9 +109,6 @@ export const fetchAllFellows = async (
.filter(({ rank }) => rank > 0);
logger.debug(JSON.stringify(fellows));

// We no longer need the collectives client, so let's destroy it
collectivesClient.destroy();

// Let's now pull the GH handles of the fellows
const users: FellowObject[] = await Promise.all(
fellows.map(async ({ address, rank }) => {
Expand All @@ -119,7 +122,7 @@ export const fetchAllFellows = async (
logger.info(`Found users: ${JSON.stringify(Array.from(users.entries()))}`);

// We are now done with the relay client
relayClient.destroy();
polkadotClient.destroy();

return users;
} catch (error) {
Expand Down
13 changes: 7 additions & 6 deletions src/test/fellows.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { mock, MockProxy } from "jest-mock-extended";
import { describe, expect, test } from "vitest";

import { fetchAllFellows } from "../fellows";
import { ActionLogger } from "../github/types";

describe("Fellows test", () => {
let logger: MockProxy<ActionLogger>;

beforeEach(() => {
logger = mock<ActionLogger>();
});
const logger: ActionLogger = {
debug: (_: string): void => {},
info: (_: string): void => {},
warn: (_: string | Error): void => {},
error: (_: string | Error): void => {},
};

test("Should fetch fellows", async () => {
const members = await fetchAllFellows(logger);
Expand Down
Loading

0 comments on commit a1badee

Please sign in to comment.