Skip to content

Commit 2108651

Browse files
author
LocalIdentity
committed
Update PR backport action
The action now has a manual override so you can trigger it on forgotten PRs It now tries a 3way merge and falls back to using reject if that fails Shows the PR# and title in the run name Grabs the original commit author when making the PR
1 parent a0b95f3 commit 2108651

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

.github/workflows/backport.yml

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,54 @@
11
name: Port changes to PoB1
22

33
on:
4-
pull_request_target:
5-
types: [closed]
6-
7-
env:
8-
LABEL_STRING: ${{ join(github.event.pull_request.labels.*.name, ',') }}
4+
pull_request_target:
5+
types: [closed]
6+
workflow_dispatch:
7+
inputs:
8+
pr_number:
9+
description: PoB2 PR number to port
10+
required: true
11+
type: number
912

1013
jobs:
11-
backport:
12-
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'pob1')
13-
runs-on: ubuntu-latest
14-
steps:
15-
- name: Notify PathOfBuilding repo
16-
uses: peter-evans/repository-dispatch@v3
17-
with:
18-
token: ${{ secrets.WIRES77_PAT }}
19-
repository: ${{ github.repository_owner }}/PathOfBuilding
20-
event-type: port-changes
21-
client-payload: '{"patch_url": "${{ github.event.pull_request.patch_url }}", "msg": "Apply changes from ${{ github.event.pull_request.html_url }}", "id": ${{ github.event.pull_request.number }}, "title": "${{ github.event.pull_request.title }}", "labels": "${{ env.LABEL_STRING }}", "name": "${{ github.event.pull_request.user.name }}", "user": "${{ github.event.pull_request.user.login }}"}'
14+
backport:
15+
if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'pob1'))
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Determine PR number
19+
run: |
20+
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
21+
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> "$GITHUB_ENV"
22+
else
23+
echo "PR_NUMBER=${{ github.event.inputs.pr_number }}" >> "$GITHUB_ENV"
24+
fi
25+
26+
- name: Fetch PR details
27+
id: payload
28+
uses: actions/github-script@v7
29+
with:
30+
result-encoding: string
31+
script: |
32+
const pr = await github.rest.pulls.get({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
pull_number: process.env.PR_NUMBER
36+
});
37+
const labels = pr.data.labels.map(l => l.name).join(',');
38+
return JSON.stringify({
39+
patch_url: pr.data.patch_url,
40+
msg: `Apply changes from ${pr.data.html_url}`,
41+
id: pr.data.number,
42+
title: pr.data.title,
43+
labels,
44+
name: pr.data.user.name || pr.data.user.login,
45+
user: pr.data.user.login,
46+
});
2247
48+
- name: Notify PathOfBuilding repo
49+
uses: peter-evans/repository-dispatch@v3
50+
with:
51+
token: ${{ secrets.WIRES77_PAT }}
52+
repository: ${{ github.repository_owner }}/PathOfBuilding
53+
event-type: port-changes
54+
client-payload: ${{ steps.payload.outputs.result }}

.github/workflows/backport_receive.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Update code with code from PoB1
2-
run-name: ${{ github.event.client_payload.title }}
2+
run-name: "PR #${{ github.event.client_payload.id }} — ${{ github.event.client_payload.title }}"
33

44
on:
55
repository_dispatch:

0 commit comments

Comments
 (0)