-
Notifications
You must be signed in to change notification settings - Fork 16
60 lines (54 loc) · 2.3 KB
/
auto-update-base.yaml
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
name: Auto-Update PR Base
on:
push:
branches:
- main
jobs:
auto-update-base:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
try {
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: "open",
});
for (const pull of pulls) {
const hasAutoUpdateLabel = pull.labels.some(label => label.name === "auto-update-base");
if (hasAutoUpdateLabel) {
try {
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull.number,
});
if (pr.data.mergeable_state === 'dirty') {
console.log(`[INFO] PR #${pull.number}: "${pull.title}" - Skipping update due to merge conflict.`);
continue;
}
if (pr.data.mergeable_state !== 'behind') {
console.log(`[INFO] PR #${pull.number}: "${pull.title}" - Base branch is up-to-date.`);
continue;
}
console.log(`[UPDATE] PR #${pull.number}: "${pull.title}" - Updating base branch...`);
try {
await github.rest.pulls.updateBranch({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull.number,
});
console.log(`[SUCCESS] PR #${pull.number}: "${pull.title}" - Base branch updated.`);
} catch (updateError) {
console.error(`[ERROR] PR #${pull.number}: Failed to update base branch - ${updateError.message}`);
}
} catch (diffError) {
console.error(`[ERROR] PR #${pull.number}: Failed to compare commits - ${diffError.message}`);
}
}
}
} catch (error) {
console.error(`[ERROR] Failed to list pull requests - ${error.message}`);
}