Skip to content

Commit 1ec7b8a

Browse files
committed
[ci] Make maintainer check workflow usable from other repositories
For use in reactjs/react.dev
1 parent b65afdd commit 1ec7b8a

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

.github/workflows/shared_check_maintainer.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
actor:
77
required: true
88
type: string
9+
use_local:
10+
required: false
11+
type: boolean
12+
default: false
913
outputs:
1014
is_core_team:
1115
value: ${{ jobs.check_maintainer.outputs.is_core_team }}
@@ -29,8 +33,30 @@ jobs:
2933
script: |
3034
const fs = require('fs');
3135
const actor = '${{ inputs.actor }}';
32-
const data = await fs.readFileSync('./MAINTAINERS', { encoding: 'utf8' });
33-
const maintainers = new Set(data.split('\n'));
36+
const useLocal = ${{ inputs.use_local }};
37+
38+
let content = null;
39+
if (useLocal === true) {
40+
content = await fs.readFileSync('./MAINTAINERS', { encoding: 'utf8' });
41+
} else {
42+
const res = await github.rest.repos.getContent({
43+
owner: 'facebook',
44+
repo: 'react',
45+
path: 'MAINTAINERS',
46+
ref: 'main',
47+
headers: { Accept: 'application/vnd.github+json' }
48+
});
49+
if (res.status !== 200) {
50+
console.error(res);
51+
throw new Error('Unable to fetch MAINTAINERS file');
52+
}
53+
content = Buffer.from(res.data.content, 'base64').toString();
54+
}
55+
if (content === null) {
56+
throw new Error('Unable to retrieve local or http MAINTAINERS file');
57+
}
58+
59+
const maintainers = new Set(content.split('\n'));
3460
if (maintainers.has(actor)) {
3561
console.log(`🟢 ${actor} is a maintainer`);
3662
return true;

.github/workflows/shared_label_core_team_prs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: (Shared) Label Core Team PRs
22

33
on:
4-
pull_request_target:
4+
pull_request:
55

66
env:
77
TZ: /usr/share/zoneinfo/America/Los_Angeles
@@ -10,7 +10,7 @@ env:
1010

1111
jobs:
1212
check_maintainer:
13-
uses: facebook/react/.github/workflows/shared_check_maintainer.yml@main
13+
uses: facebook/react/.github/workflows/shared_check_maintainer.yml@pr32215
1414
with:
1515
actor: ${{ github.event.pull_request.user.login }}
1616

0 commit comments

Comments
 (0)