-
Notifications
You must be signed in to change notification settings - Fork 455
95 lines (89 loc) · 3.42 KB
/
Copy pathbackport.yml
File metadata and controls
95 lines (89 loc) · 3.42 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
name: Backport merged pull request
on:
pull_request_target:
types: [closed, labeled]
permissions:
contents: write # so it can comment
pull-requests: write # so it can create pull requests
jobs:
backport:
name: Backport pull request
runs-on: ubuntu-latest
# Don't run on closed unmerged pull requests
if: >
github.event.pull_request.merged
&& (
github.event.action == 'closed'
|| (
github.event.action == 'labeled'
&& contains(github.event.label.name, 'backport')
)
)
steps:
- uses: actions/checkout@v4
with:
# Token for git actions, e.g. git push see https://github.com/korthout/backport-action/issues/379
token: ${{ secrets.BACKPORT_ACTION_PAT }}
- name: Get issues
id: get-issues
uses: mondeja/pr-linked-issues-action@v2
env:
GITHUB_TOKEN: ${{ secrets.BACKPORT_ACTION_PAT }}
- name: Create backport pull requests
id: create_backport_pr
uses: korthout/backport-action@v4
with:
# Token for git actions, see https://github.com/korthout/backport-action/issues/379
github_token: ${{ secrets.BACKPORT_ACTION_PAT }}
auto_merge_method: squash
auto_merge_enabled: true
copy_assignees: true
copy_milestone: true
copy_requested_reviewers: true
add_labels: Backport
pull_description: |-
# Description
Backport of #${pull_number} to `${target_branch}`.
Fixes #${{ steps.get-issues.outputs.issues }}
experimental: >
{
"conflict_resolution": "draft_commit_conflicts"
}
- name: Link all backport PRs to original issue
if: ${{ steps.get-issues.outputs.issues != '' && steps.create_backport_pr.outputs.created_pull_numbers != '' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.BACKPORT_ACTION_PAT }}
script: |
const issueNumbers = "${{ steps.get-issues.outputs.issues }}".split(',').map(s => s.trim()).filter(Boolean);
const prNumbers = "${{ steps.create_backport_pr.outputs.created_pull_numbers }}".split(' ').map(s => s.trim()).filter(Boolean);
for (const prNumber of prNumbers) {
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: Number(prNumber)
});
for (const issueNumber of issueNumbers) {
const { data: issue } = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: Number(issueNumber)
});
console.log(`Linking PR #${prNumber} to issue #${issueNumber}`);
await github.graphql(`
mutation AddLinkedIssue($pullRequestId: ID!, $issueId: ID!) {
addLinkedIssue(input: {
pullRequestId: $pullRequestId,
issueId: $issueId
}) {
pullRequest {
number
}
}
}
`, {
pullRequestId: pr.node_id,
issueId: issue.node_id
});
}
}