forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (63 loc) · 2.51 KB
/
auto-merge-backports.yml
File metadata and controls
74 lines (63 loc) · 2.51 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
name: Auto-Merge Test Backport PRs
on:
schedule:
- cron: "0 * * * *" # Every hour
workflow_dispatch:
jobs:
auto-merge:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Merge qualifying PRs
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Get timestamp for 24 hours ago in ISO format
const now = new Date();
const iso24HoursAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString();
const query = `repo:${context.repo.owner}/${context.repo.repo} is:pr is:open label:backport label:blathers-backport label:backport-test-only created:<${iso24HoursAgo}`;
const searchResults = await github.paginate(github.rest.search.issuesAndPullRequests, {
q: query,
per_page: 100,
});
for (const prItem of searchResults) {
const prNumber = prItem.number;
// Fetch full PR details
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
// Check for approvals
const reviews = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
const approved = reviews.some(
r =>
r.state === 'APPROVED' &&
r.user?.login === 'blathers-crl[bot]'
);
if (!approved) {
console.log(`Skipping PR #${prNumber}: not approved`);
continue;
}
const labels = prItem.labels.map(l => l.name).join(', ');
console.log(`Merging PR #${prNumber}, Created at: ${pr.created_at}, Approved: ${approved}, Labels: ${labels}`);
// Merge the PR
// try {
// console.log(`Merging PR #${prNumber}`);
// await github.rest.pulls.merge({
// owner: context.repo.owner,
// repo: context.repo.repo,
// pull_number: prNumber,
// merge_method: "merge",
// });
// } catch (err) {
// console.warn(`Failed to merge PR #${prNumber}: ${err.message}`);
// }
}