Remove issue from epic #8
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
--- | |
name: Remove issue from epic | |
on: # yamllint disable-line rule:truthy | |
issues: | |
types: | |
- unlabeled | |
concurrency: | |
group: remove-issue-from-epic | |
cancel-in-progress: false | |
permissions: read-all | |
jobs: | |
remove-issue-from-epic: | |
name: Remove Issue from epic | |
runs-on: ubuntu-latest | |
permissions: | |
issues: write | |
steps: | |
- name: Remove issue from epic | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const payload = context.payload; | |
const issueNumber = payload.issue.number; | |
const issueTitle = payload.issue.title; | |
const labelName = payload.label.name; | |
// Check if the removed label is an Epic label (based on your naming convention) | |
if (!labelName.includes('(Epic #')) { | |
console.log('The removed label is not an Epic label. Exiting...'); | |
return; | |
} | |
// Extract the Epic's issue number from the label name | |
const epicNumber = labelName.match(/\(Epic #(\d+)\)/)[1]; | |
if (!epicNumber) { | |
console.log('Could not determine the Epic issue number. Exiting...'); | |
return; | |
} | |
// Fetch the description of the Epic | |
const epic = await github.rest.issues.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: epicNumber | |
}); | |
const epicBody = epic.data.body; | |
// Construct the link that might exist in the Epic description | |
const issueLink = `- [ ] #${issueNumber}`; | |
// Check if the link exists. If it does, remove it | |
if (epicBody.includes(issueLink)) { | |
const updatedDescription = epicBody.replace(issueLink, '').trim(); | |
// Update the Epic description | |
await github.rest.issues.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: epicNumber, | |
body: updatedDescription | |
}); | |
} else { | |
console.log('The issue link was not found in the Epic description. Exiting...'); | |
} |