Repository navigation
182 lines (166 loc) Β· 6.47 KB
/
Copy pathsync-org-cla.yml
File metadata and controls
182 lines (166 loc) Β· 6.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: π Sync Org CLA Signers
on:
schedule:
- cron: '17 * * * *'
workflow_dispatch:
permissions:
contents: read
jobs:
sync:
name: π Sync CLA signers across NativeScript org
runs-on: ubuntu-latest
timeout-minutes: 15
concurrency:
group: cla-signatures-NativeScript/.github
cancel-in-progress: false
permissions:
contents: write
steps:
- name: π¦ Checkout CLA hub
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: master
path: cla-hub
persist-credentials: false
- name: π Checkout org CLA signatures
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: cla-signatures
path: org-cla-signatures
- name: π’ Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: '24'
- name: π Gather new signers across NativeScript org
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const fs = require('node:fs/promises');
const phrase = 'I have read the CLA and I hereby sign the CLA';
const orgName = context.repo.owner;
const signingComments = [];
const importedSigners = [];
// 1. Search recently merged PRs across the entire NativeScript org that contain the signing phrase
try {
const searchRes = await github.rest.search.issuesAndPullRequests({
q: `org:${orgName} is:pr is:merged "${phrase}"`,
sort: 'updated',
order: 'desc',
per_page: 50,
});
for (const item of searchRes.data.items) {
const parts = item.repository_url.split('/');
const repo = parts.at(-1);
const owner = parts.at(-2);
const eligibleLogins = new Set();
if (item.user?.login) eligibleLogins.add(item.user.login.toLowerCase());
const commits = await github.paginate(
github.rest.pulls.listCommits,
{
owner,
repo,
pull_number: item.number,
per_page: 100,
},
);
for (const commit of commits) {
if (commit.author?.login) {
eligibleLogins.add(commit.author.login.toLowerCase());
}
}
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner,
repo,
issue_number: item.number,
per_page: 100,
},
);
for (const comment of comments) {
const login = comment.user?.login;
if (
comment.user?.type !== 'User' ||
!login ||
!eligibleLogins.has(login.toLowerCase())
) {
continue;
}
signingComments.push({
login,
createdAt: comment.created_at,
body: comment.body ?? '',
});
}
}
} catch (err) {
core.warning(`Org PR search encountered error: ${err.message}`);
}
// 2. Also harvest any repo-local cla-signatures branches on recently pushed public repos
try {
const repos = await github.rest.repos.listForOrg({
org: orgName,
type: 'public',
sort: 'pushed',
direction: 'desc',
per_page: 40,
});
for (const r of repos.data) {
if (r.archived || r.fork || r.name === '.github') continue;
try {
const res = await github.rest.repos.getContent({
owner: orgName,
repo: r.name,
path: 'cla-signers.json',
ref: 'cla-signatures',
});
if (res.data && 'content' in res.data && res.data.content) {
const parsed = JSON.parse(
Buffer.from(res.data.content, 'base64').toString('utf8'),
);
if (Array.isArray(parsed.signers)) {
importedSigners.push(...parsed.signers);
}
}
} catch (err) {
if (err.status !== 404) {
core.info(`Skipped ${r.name} cla-signatures: ${err.message}`);
}
}
}
} catch (err) {
core.warning(`Repo cla-signatures scan encountered error: ${err.message}`);
}
signingComments.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
await fs.writeFile(
'org-signing-comments.json',
`${JSON.stringify(signingComments, null, '\t')}\n`,
);
await fs.writeFile(
'org-imported-signers.json',
`${JSON.stringify(importedSigners, null, '\t')}\n`,
);
- name: π Apply new signers to org cla-signers.json
id: record
run: |
node cla-hub/scripts/check-cla.mjs \
--signers org-cla-signatures/cla-signers.json \
--record-comments-json org-signing-comments.json \
--import-signers-json org-imported-signers.json > cla-sync-output.txt
cat cla-sync-output.txt
grep -E '^(added|github)=' cla-sync-output.txt >> "$GITHUB_OUTPUT"
- name: π± Commit and push org signers
if: steps.record.outputs.added == 'true'
working-directory: org-cla-signatures
env:
CLA_LOGINS: ${{ steps.record.outputs.github }}
run: |
set -euo pipefail
git add cla-signers.json
if git diff --cached --quiet; then
exit 0
fi
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -m "Record CLA signers: @${CLA_LOGINS//,/, @}"
git push origin HEAD:refs/heads/cla-signatures