Skip to content

Commit a1badee

Browse files
authored
Fix IdentityOf tuple introduced in v1.2.0 (#24)
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
1 parent b01c274 commit a1badee

File tree

10 files changed

+1837
-2120
lines changed

10 files changed

+1837
-2120
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ WORKDIR /action
44

55
COPY package.json yarn.lock ./
66

7-
COPY collectives.scale relay.scale polkadot-api.json ./
7+
COPY collectives.scale polkadot.scale polkadot-api.json ./
88

99
RUN yarn install --frozen-lockfile
1010

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ outputs:
1212

1313
runs:
1414
using: 'docker'
15-
image: 'docker://ghcr.io/paritytech/get-fellows-action/action:1.1.1'
15+
image: 'docker://ghcr.io/paritytech/get-fellows-action/action:1.1.2'

collectives.scale

15.8 KB
Binary file not shown.

package.json

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "get-fellows-action",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Fetch all the GitHub handles from the Fellows",
55
"main": "src/index.ts",
66
"scripts": {
77
"start": "node dist",
88
"build": "ncc build --license LICENSE",
99
"postinstall": "papi",
10-
"test": "jest",
10+
"test": "vitest",
1111
"fix": "eslint --fix 'src/**/*'",
1212
"lint": "eslint 'src/**/*'"
1313
},
@@ -24,21 +24,13 @@
2424
"dependencies": {
2525
"@actions/core": "^1.10.1",
2626
"@actions/github": "^5.1.1",
27-
"@octokit/webhooks-types": "^7.3.1",
28-
"@polkadot-api/cli": "0.0.1-28172e65e6c4fb53198b9932ff624f8eef05fe68.1.0",
29-
"@polkadot-api/client": "0.0.1-28172e65e6c4fb53198b9932ff624f8eef05fe68.1.0",
30-
"@polkadot-api/node-polkadot-provider": "0.0.1-28172e65e6c4fb53198b9932ff624f8eef05fe68.1.0",
31-
"@polkadot-api/sm-provider": "0.0.1-28172e65e6c4fb53198b9932ff624f8eef05fe68.1.0",
32-
"@substrate/connect-known-chains": "^1.1.2",
27+
"polkadot-api": "^0.4.0",
3328
"smoldot": "2.0.22"
3429
},
3530
"devDependencies": {
36-
"@eng-automation/js-style": "^2.3.0",
37-
"@types/jest": "^29.5.5",
31+
"@eng-automation/js-style": "^2.3.1",
3832
"@vercel/ncc": "^0.38.0",
39-
"jest": "^29.7.0",
40-
"jest-mock-extended": "^3.0.5",
41-
"ts-jest": "^29.1.1",
42-
"typescript": "^5.2.2"
33+
"typescript": "^5.2.2",
34+
"vitest": "^1.5.0"
4335
}
4436
}

polkadot-api.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{
2-
"relay": {
3-
"outputFolder": "src/codegen",
4-
"chain": "polkadot",
5-
"metadata": "relay.scale"
2+
"polkadot": {
3+
"wsUrl": "wss://rpc.polkadot.io",
4+
"metadata": "polkadot.scale"
65
},
76
"collectives": {
8-
"outputFolder": "src/codegen",
97
"wsUrl": "wss://polkadot-collectives-rpc.polkadot.io",
108
"metadata": "collectives.scale"
119
}
12-
}
10+
}

polkadot.scale

297 KB
Binary file not shown.

relay.scale

-276 KB
Binary file not shown.

src/fellows.ts

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import { createClient, SS58String } from "@polkadot-api/client";
2-
import { getChain } from "@polkadot-api/node-polkadot-provider";
3-
import { getSmProvider } from "@polkadot-api/sm-provider";
4-
import {
5-
polkadot,
6-
polkadot_collectives,
7-
} from "@substrate/connect-known-chains";
1+
import { collectives, polkadot } from "@polkadot-api/descriptors";
2+
import { Binary, createClient, SS58String } from "polkadot-api";
3+
import { chainSpec as polkadotChainSpec } from "polkadot-api/chains/polkadot";
4+
import { chainSpec as collectivesChainSpec } from "polkadot-api/chains/polkadot_collectives";
5+
import { getSmProvider } from "polkadot-api/sm-provider";
86
import { start } from "smoldot";
97

10-
import collectiveDescriptor from "./codegen/collectives";
11-
import relayDescriptor from "./codegen/relay";
128
import { ActionLogger } from "./github/types";
139

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

2824
try {
29-
const relayChain = await smoldot.addChain({
30-
chainSpec: polkadot,
31-
disableJsonRpc: true,
25+
const smoldotRelayChain = await smoldot.addChain({
26+
chainSpec: polkadotChainSpec,
3227
});
3328

29+
const jsonRpcProvider = getSmProvider(smoldotRelayChain);
3430
logger.info("Initializing the relay client");
35-
const relayClient = createClient(
36-
getChain({
37-
provider: getSmProvider(smoldot, polkadot),
38-
keyring: [],
39-
}),
40-
);
41-
const relayApi = relayClient.getTypedApi(relayDescriptor);
31+
const polkadotClient = createClient(jsonRpcProvider);
32+
33+
const relayApi = polkadotClient.getTypedApi(polkadot);
4234

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

5042
if (identity) {
51-
const handle = identity.info.additional
52-
.find(([key]) => key.value?.asText() === "github")?.[1]
53-
.value?.asText()
43+
const additional = identity[0].info.additional.find(
44+
([key]) => (key.value as Binary)?.asText() === "github",
45+
);
46+
47+
if (!additional) {
48+
logger.debug(
49+
`'${address}' does not have an additional field named 'github'`,
50+
);
51+
return;
52+
}
53+
54+
const handle = (additional[1].value as Binary)
55+
.asText()
5456
.replace("@", "");
57+
5558
if (handle) {
5659
logger.info(`Found github handle for '${address}': '${handle}'`);
5760
} else {
5861
logger.debug(`'${address}' does not have a GitHub handle`);
62+
return;
5963
}
6064
return handle;
6165
}
@@ -80,21 +84,23 @@ export const fetchAllFellows = async (
8084
};
8185

8286
logger.info("Initializing the collectives client");
83-
const collectivesClient = createClient(
84-
getChain({
85-
provider: getSmProvider(smoldot, {
86-
potentialRelayChains: [relayChain],
87-
chainSpec: polkadot_collectives,
88-
}),
89-
keyring: [],
90-
}),
91-
);
92-
const collectivesApi = collectivesClient.getTypedApi(collectiveDescriptor);
87+
88+
const collectiveRelayChain = await smoldot.addChain({
89+
chainSpec: collectivesChainSpec,
90+
potentialRelayChains: [smoldotRelayChain],
91+
});
92+
const collectiveJsonRpcProvider = getSmProvider(collectiveRelayChain);
93+
logger.info("Initializing the relay client");
94+
const collectivesClient = createClient(collectiveJsonRpcProvider);
95+
const collectivesApi = collectivesClient.getTypedApi(collectives);
9396

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

101+
// We no longer need the collective client, so let's destroy it
102+
collectivesClient.destroy();
103+
98104
// Build the Array of FellowData and filter out candidates (zero rank members)
99105
const fellows: FellowData[] = memberEntries
100106
.map(({ keyArgs: [address], value: rank }) => {
@@ -103,9 +109,6 @@ export const fetchAllFellows = async (
103109
.filter(({ rank }) => rank > 0);
104110
logger.debug(JSON.stringify(fellows));
105111

106-
// We no longer need the collectives client, so let's destroy it
107-
collectivesClient.destroy();
108-
109112
// Let's now pull the GH handles of the fellows
110113
const users: FellowObject[] = await Promise.all(
111114
fellows.map(async ({ address, rank }) => {
@@ -119,7 +122,7 @@ export const fetchAllFellows = async (
119122
logger.info(`Found users: ${JSON.stringify(Array.from(users.entries()))}`);
120123

121124
// We are now done with the relay client
122-
relayClient.destroy();
125+
polkadotClient.destroy();
123126

124127
return users;
125128
} catch (error) {

src/test/fellows.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { mock, MockProxy } from "jest-mock-extended";
1+
import { describe, expect, test } from "vitest";
22

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

66
describe("Fellows test", () => {
7-
let logger: MockProxy<ActionLogger>;
8-
9-
beforeEach(() => {
10-
logger = mock<ActionLogger>();
11-
});
7+
const logger: ActionLogger = {
8+
debug: (_: string): void => {},
9+
info: (_: string): void => {},
10+
warn: (_: string | Error): void => {},
11+
error: (_: string | Error): void => {},
12+
};
1213

1314
test("Should fetch fellows", async () => {
1415
const members = await fetchAllFellows(logger);

0 commit comments

Comments
 (0)