-
Notifications
You must be signed in to change notification settings - Fork 2.1k
53 lines (52 loc) · 1.7 KB
/
bot-auto-cherry-pick.yml
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
name: 'Github Rebot for Cherry Pick when PR is merged'
on:
pull_request_target:
types:
- closed
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: Comment cherry-pick command
uses: actions/github-script@v5
with:
script: |
const pr = context.payload.pull_request;
if (!pr.merged) {
console.log("PR is not merged. Skipping...");
return;
}
if (!pr.milestone || !pr.milestone.title) {
console.log("Milestone is not set. Skipping...");
return;
}
const milestone = pr.milestone.title;
const ref = `heads/release-${milestone}`;
let branchExists;
try {
await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: ref
});
branchExists = true;
} catch (error) {
if (error.status === 404) {
console.log(`Branch ${ref} does not exist. Skipping...`);
branchExists = false;
} else {
throw error; // Rethrow if it's another error
}
}
if (!branchExists) {
return;
}
const cherryPickCmd = `/cherry-pick release-${milestone}`;
console.log(`Adding comment: ${cherryPickCmd}`);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: cherryPickCmd
});
github-token: ${{ secrets.GH_PAT }}