-
-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (46 loc) · 1.6 KB
/
label-sync.yml
File metadata and controls
53 lines (46 loc) · 1.6 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
name: Pull Request Label Sync
on:
pull_request_target:
types: [opened, reopened, synchronize]
pull_request:
types: [opened, reopened, synchronize]
workflow_call:
inputs:
copy_issue_labels:
type: boolean
default: true
description: "Copy labels from linked issue"
permissions:
contents: read
pull-requests: write
jobs:
copy-issue-labels:
if: inputs.copy_issue_labels == true || github.event_name != 'workflow_call'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Extract issue number from PR
id: extract-issue
env:
BODY: ${{ github.event.pull_request.body }}
TITLE: ${{ github.event.pull_request.title }}
run: |
ISSUE=$(echo "$TITLE $BODY" | \
grep -oiE '(closes|fixes|resolves|addresses)\s+#[[:digit:]]+' | \
grep -oE '#[[:digit:]]+' | head -1 | tr -d '#')
if [ -n "$ISSUE" ]; then
echo "issue_number=$ISSUE" >> "$GITHUB_OUTPUT"
fi
- name: Copy labels from issue to PR
if: steps.extract-issue.outputs.issue_number != ''
run: |
LABELS=$(gh issue view "$ISSUE_NUM" --repo "$REPO" --json labels --jq '.labels[].name')
for label in $LABELS; do
gh pr edit "$PR_NUM" --repo "$REPO" --add-label "$label" 2>/dev/null || true
done
env:
ISSUE_NUM: ${{ steps.extract-issue.outputs.issue_number }}
PR_NUM: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}