Skip to content

Commit 90e809e

Browse files
chore: add script to resync caretaker app open PRs (#18732)
1 parent d60c9af commit 90e809e

File tree

3 files changed

+181
-88
lines changed

3 files changed

+181
-88
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"cherry-pick-patch": "ts-node --project tools/cherry-pick-patch/ tools/cherry-pick-patch/cherry-pick-patch.ts",
4141
"ownerslint": "ts-node --project scripts/ scripts/ownerslint.ts",
4242
"tslint": "tslint -c tslint.json --project ./tsconfig.json",
43-
"stylelint": "stylelint \"src/**/*.+(css|scss)\" --config .stylelintrc.json --syntax scss"
43+
"stylelint": "stylelint \"src/**/*.+(css|scss)\" --config .stylelintrc.json --syntax scss",
44+
"resync-caretaker-app": "ts-node --project scripts scripts/caretaking/resync-caretaker-app-prs.ts"
4445
},
4546
"version": "9.1.0",
4647
"dependencies": {
@@ -77,7 +78,7 @@
7778
"@bazel/protractor": "^1.4.0",
7879
"@bazel/typescript": "^1.4.0",
7980
"@firebase/app-types": "^0.3.2",
80-
"@octokit/rest": "^16.28.7",
81+
"@octokit/rest": "^17.0.0",
8182
"@schematics/angular": "^9.0.4",
8283
"@types/browser-sync": "^2.26.1",
8384
"@types/fs-extra": "^4.0.3",
@@ -89,6 +90,7 @@
8990
"@types/merge2": "^0.3.30",
9091
"@types/minimist": "^1.2.0",
9192
"@types/node": "^12.11.1",
93+
"@types/node-fetch": "^2.5.5",
9294
"@types/parse5": "^5.0.0",
9395
"@types/run-sequence": "^0.0.29",
9496
"@types/semver": "^6.2.0",
@@ -128,6 +130,7 @@
128130
"minimatch": "^3.0.4",
129131
"minimist": "^1.2.0",
130132
"moment": "^2.18.1",
133+
"node-fetch": "^2.6.0",
131134
"parse5": "^5.0.0",
132135
"protractor": "^5.4.2",
133136
"requirejs": "^2.3.6",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {Octokit} from '@octokit/rest';
2+
import * as fetch from 'node-fetch';
3+
4+
const github = new Octokit({auth: process.env.TOKEN});
5+
6+
async function resync() {
7+
const pulls: any[] = [];
8+
let page = 1;
9+
let hasNext = true;
10+
while (hasNext) {
11+
const response = await github.pulls.list({
12+
owner: 'angular',
13+
repo: 'components',
14+
per_page: 100,
15+
page
16+
});
17+
pulls.push(...response.data);
18+
hasNext = !!response.data.length;
19+
page++;
20+
}
21+
22+
let syncedCount = 0;
23+
for (let pull of pulls) {
24+
await fetch.default(
25+
`https://test-jperrott.firebaseio.com/pulls/${pull.base.repo.full_name}/${pull.number}/github.json`,
26+
{
27+
method: 'patch',
28+
body: JSON.stringify({
29+
'branch': pull.base.ref,
30+
'title': pull.title,
31+
'pull_number': pull.number,
32+
'state': pull.state,
33+
'commit_sha': pull.head.sha,
34+
'author': pull.user,
35+
'labels': pull.labels
36+
})
37+
});
38+
syncedCount++;
39+
console.log(`updated pr ${pull.number} (${syncedCount} of ${pulls.length})`);
40+
}
41+
}
42+
43+
resync();

0 commit comments

Comments
 (0)