-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
auto-rebase.ts
48 lines (36 loc) · 1.19 KB
/
auto-rebase.ts
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
import { getTitleOfLatestCommit } from "./util/git";
import { octokit } from "./util/octokit";
// We only auto-rebase if the latest commit message is one of
//
// - test(*)
// - chore:
const owner = 'swc-project';
const repo = 'swc';
(async () => {
const latestCommitMessage = await getTitleOfLatestCommit();
console.log(`Latest commit message: ${latestCommitMessage}`);
if (!latestCommitMessage.startsWith("test(") && !latestCommitMessage.startsWith("chore:")) {
console.log(`Auto rebase script cannot work because the latest commit may require a version bump`);
return;
}
const allPrs = await octokit.rest.pulls.list({
owner,
repo,
state: 'open',
sort: 'long-running',
direction: 'desc',
});
const autoMergePrs = allPrs.data.filter(pr => !!pr.auto_merge);
if (autoMergePrs.length === 0) {
console.log(`No PRs with auto-merge enabled`);
return;
}
const pr = autoMergePrs[0];
await octokit.rest.pulls.updateBranch({
owner,
repo,
pull_number: pr.number,
expected_head_sha: pr.head.sha
});
console.log(`Updated PR ${pr.number} to merge upstream`);
})()