This repository was archived by the owner on Jun 5, 2026. It is now read-only.
forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (83 loc) · 3.07 KB
/
Copy pathauto-merge-backports.yml
File metadata and controls
96 lines (83 loc) · 3.07 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
name: Auto-Merge Test Backport PRs
on:
schedule:
- cron: "0 * * * *" # Every hour
jobs:
auto-merge:
if: github.repository == 'cockroachdb/cockroach'
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);
const query = `
query SearchPRs() {
search(query: "repo:${context.repo.owner}/${context.repo.repo} is:pr is:open label:backport label:backport-test-only", type: ISSUE, first: 100) {
nodes {
... on PullRequest {
number
createdAt
labels(first: 10) {
nodes {
name
}
}
reviews(last: 50) {
nodes {
state
author {
login
}
}
}
}
}
}
}
`;
const result = await github.graphql(query);
const prs = result.search.nodes;
if (prs.length === 0) {
console.log('No backport PRs found matching criteria');
} else {
console.log(`Found ${prs.length} backport PR(s) to evaluate`);
}
for (const pr of prs) {
const createdAt = new Date(pr.createdAt);
const isOldEnough = createdAt <= iso24HoursAgo;
if (!isOldEnough) {
console.log(`Skipping PR #${pr.number}: not old enough, only created at ${pr.createdAt}`);
continue;
}
const approved = pr.reviews.nodes.some(
r =>
r.state === 'APPROVED' &&
r.author?.login === 'blathers-crl'
);
if (!approved) {
console.log(`Skipping PR #${pr.number}: not approved`);
continue;
}
const labels = pr.labels.nodes.map(l => l.name).join(', ');
console.log(`Merging PR #${pr.number}, Created at: ${pr.createdAt}, Approved: ${approved}, Labels: ${labels}`);
// Merge the PR
try {
console.log(`Merging PR #${pr.number}`);
await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
merge_method: "merge",
});
} catch (err) {
console.warn(`Failed to merge PR #${pr.number}: ${err.message}`);
}
}