Skip to content

Commit 6f8b7e2

Browse files
authored
Use REST API for fetching members on build (#537)
* Use REST API for fetching members on build * Update Node version for build
1 parent 0b99193 commit 6f8b7e2

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

.github/workflows/ci-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
- uses: actions/checkout@v2
88
- uses: actions/setup-node@v4
99
with:
10-
node-version: '18'
10+
node-version: '22'
1111
- run: yarn
1212
- run: NODE_OPTIONS=--openssl-legacy-provider yarn build
1313
- run: yarn flow

fetch-members.js

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
1-
const { GraphQLClient } = require("graphql-request");
1+
const fetch = require("isomorphic-fetch");
22
const { writeFileSync, existsSync, mkdirSync } = require("fs");
33

44
async function fetchMembers(organisation) {
5-
const token = process.env.GH_TOKEN;
6-
7-
if (!token) {
8-
console.error("'GH_TOKEN' not set. Could not fetch nteract members.");
9-
return [];
10-
}
11-
12-
const client = new GraphQLClient("https://api.github.com/graphql", {
13-
headers: {
14-
Authorization: `Bearer ${token}`
15-
}
16-
});
17-
18-
const query = `{
19-
organization(login: "${organisation}") {
20-
membersWithRole(first: 100) {
21-
totalCount
22-
nodes {
23-
name
24-
login
25-
websiteUrl
26-
avatarUrl
27-
url
28-
}
5+
const url = `https://api.github.com/orgs/${organisation}/public_members`;
6+
7+
try {
8+
const response = await fetch(url, {
9+
headers: {
10+
'Accept': 'application/vnd.github.v3+json',
11+
'User-Agent': 'nteract-member-fetcher'
2912
}
13+
});
14+
15+
if (!response.ok) {
16+
throw new Error(`HTTP error! status: ${response.status}`);
3017
}
31-
}`;
3218

33-
try {
34-
const data = await client.request(query);
35-
return data.organization.membersWithRole.nodes;
19+
const members = await response.json();
20+
21+
return members.map(member => ({
22+
name: member.name || null,
23+
login: member.login,
24+
websiteUrl: member.blog || null,
25+
avatarUrl: member.avatar_url,
26+
url: member.html_url
27+
}));
3628
} catch (e) {
37-
console.error(e);
29+
console.error(`Error fetching members for ${organisation}:`, e);
3830
return [];
3931
}
4032
}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"babel-plugin-styled-components": "2.0.7",
2323
"babel-plugin-transform-flow-strip-types": "6.22.0",
2424
"flow-bin": "0.84.0",
25-
"graphql-request": "1.8.2",
2625
"lint-staged": "12.5.0",
2726
"prettier": "2.6.2"
2827
},

0 commit comments

Comments
 (0)