-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Sync Issue Labels to PR | ||
|
||
on: | ||
pull_request: | ||
types: [ opened, synchronize, edited ] # Trigger when a PR is created, updated, or edited | ||
|
||
jobs: | ||
sync-labels: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Checkout the repository | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
# Sync labels from the linked issue to the PR | ||
- name: Sync Labels from Linked Issue | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.BOT_TOKEN }} | ||
script: | | ||
// Extract linked issue numbers from the PR description | ||
const issueNumbers = context.payload.pull_request.body | ||
?.match(/(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)?(?:\s*)?#(\d+)/gi) | ||
?.map(match => parseInt(match.match(/\d+/)[0])) || []; | ||
if (issueNumbers.length === 0) { | ||
console.log("No linked issues found in the PR description."); | ||
return; | ||
} | ||
for (const issueNumber of issueNumbers) { | ||
console.log(`Processing linked issue: #${issueNumber}`); | ||
// Fetch labels from the linked issue | ||
const issueResponse = await github.rest.issues.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
}); | ||
const issueLabels = issueResponse.data.labels.map(label => label.name); | ||
if (issueLabels.length === 0) { | ||
console.log(`No labels found on Issue #${issueNumber}`); | ||
continue; | ||
} | ||
console.log(`Labels from Issue #${issueNumber}: ${issueLabels.join(', ')}`); | ||
// Add labels to the PR | ||
await github.rest.issues.addLabels({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.payload.pull_request.number, | ||
labels: issueLabels, | ||
}); | ||
console.log(`Labels synced to PR: ${issueLabels.join(', ')}`); | ||
} |