@samitouri / QOS-React / commits / 0f8a1e02ff

[ci] Make maintainer check workflow usable from other repositories (#32215)

For use in reactjs/react.dev

lauren committed Jan 24, 2025 at 14:41 UTC 0f8a1e02ff036974f29347fa870b1f0e8e78666d
1 file changed +28 -2
.github/workflows/shared_check_maintainer.yml
+28 -2
@@ -6,6 +6,10 @@ on:
6 actor:
7 required: true
8 type: string
9 + is_remote:
10 + required: false
11 + type: boolean
12 + default: false
13 outputs:
14 is_core_team:
15 value: ${{ jobs.check_maintainer.outputs.is_core_team }}
@@ -29,8 +33,30 @@ jobs:
33 script: |
34 const fs = require('fs');
35 const actor = '${{ inputs.actor }}';
32 - const data = await fs.readFileSync('./MAINTAINERS', { encoding: 'utf8' });
33 - const maintainers = new Set(data.split('\n'));
36 + const isRemote = ${{ inputs.is_remote }};
37 +
38 + let content = null;
39 + if (isRemote === true) {
40 + const res = await github.rest.repos.getContent({
41 + owner: 'facebook',
42 + repo: 'react',
43 + path: 'MAINTAINERS',
44 + ref: 'main',
45 + headers: { Accept: 'application/vnd.github+json' }
46 + });
47 + if (res.status !== 200) {
48 + console.error(res);
49 + throw new Error('Unable to fetch MAINTAINERS file');
50 + }
51 + content = Buffer.from(res.data.content, 'base64').toString();
52 + } else {
53 + content = await fs.readFileSync('./MAINTAINERS', { encoding: 'utf8' });
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'));
60 if (maintainers.has(actor)) {
61 console.log(`🟢 ${actor} is a maintainer`);
62 return true;