API Managment #137
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: Story Issue Checkbox | |
on: | |
issues: | |
types: [ edited ] | |
permissions: | |
issues: write | |
jobs: | |
update-checkbox: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkboxes | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const checkboxes = ["<!-- check-ba -->BA Review", "<!-- check-dev -->DEV Review", "<!-- check-po -->PO Review"]; | |
const issueBody= context.payload.issue.body | |
const oldIssueBody = context.payload.changes.body.from | |
const username = context.actor; | |
for(const checkbox of checkboxes){ | |
if(issueBody.includes(`- [x] ${checkbox}`) && oldIssueBody.includes(`- [ ] ${checkbox}`)){ | |
const updatedBody = issueBody.replace(`- [x] ${checkbox}`, `- [x] ${checkbox} (@${username})`); | |
github.rest.issues.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body: updatedBody | |
}); | |
} else if(issueBody.includes(`- [ ] ${checkbox}`) && oldIssueBody.includes(`- [x] ${checkbox}`)){ | |
const regex = new RegExp(`- \\[ \\] ${checkbox} \\(@[^)]+\\)`, 'g'); | |
const updatedBody = issueBody.replace(regex, `- [ ] ${checkbox}`); | |
github.rest.issues.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body: updatedBody | |
}); | |
} | |
} |