[ADD_BACKLOG] Test #40
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: Issue Templates automated Tasks | |
on: | |
issues: | |
types: [opened, edited] | |
jobs: | |
check_issue: | |
runs-on: ubuntu-latest | |
outputs: | |
issue_type: ${{ steps.detect_issue_type.outputs.issue_type }} | |
template_file: ${{ steps.set_template_file.outputs.template_file }} | |
steps: | |
- name: ποΈ Checkout | |
uses: actions/checkout@v4 | |
- id: detect_issue_type | |
name: π Scan issue type | |
env: | |
ISSUE_TYPE: ${{ | |
contains(github.event.issue.labels.*.name, 'ADD_GAME') && 'ADD_GAME' || | |
contains(github.event.issue.labels.*.name, 'UPDATE_GAME') && 'UPDATE_GAME' || | |
contains(github.event.issue.labels.*.name, 'DELETE_GAME') && 'DELETE_GAME' || | |
contains(github.event.issue.labels.*.name, 'ADD_BACKLOG') && 'ADD_BACKLOG' || | |
contains(github.event.issue.labels.*.name, 'DELETE_BACKLOG') && 'DELETE_BACKLOG' || | |
'UNKNOWN' }} | |
run: echo "issue_type=${{ env.ISSUE_TYPE }}" >> $GITHUB_OUTPUT | |
- id: set_template_file | |
name: π Select the correct template for this issue | |
run: | | |
case "${{ steps.detect_issue_type.outputs.issue_type }}" in | |
ADD_GAME) | |
echo "template_file=01-add-game.yml" >> $GITHUB_OUTPUT | |
;; | |
UPDATE_GAME) | |
echo "template_file=02-update-game.yml" >> $GITHUB_OUTPUT | |
;; | |
DELETE_GAME) | |
echo "template_file=03-delete-game.yml" >> $GITHUB_OUTPUT | |
;; | |
ADD_BACKLOG) | |
echo "template_file=04-add-backlog.yml" >> $GITHUB_OUTPUT | |
;; | |
DELETE_BACKLOG) | |
echo "template_file=05-delete-backlog.yml" >> $GITHUB_OUTPUT | |
;; | |
esac | |
process_issue: | |
runs-on: ubuntu-latest | |
needs: check_issue | |
if: ${{ needs.check_issue.outputs.issue_type != 'UNKNOWN' }} | |
outputs: | |
issue_json: ${{ steps.processed.outputs.json }} | |
issue_type: ${{ needs.check_issue.outputs.issue_type }} | |
env: | |
ISSUE_TYPE: ${{ needs.check_issue.outputs.issue_type }} | |
TEMPLATE_FILE: ${{ needs.check_issue.outputs.template_file }} | |
steps: | |
- name: ποΈ Checkout | |
uses: actions/checkout@v4 | |
# To generate an array of all fields id and labels - example : | |
# [ { "id": "name", "label": "The Name of the Thing" }, { "id": "nickname", "label": "The Nickname of the Thing" }, // ... other fields ] | |
# Warning, yq follows JSONL specs ( https://jsonlines.org/ ) so we don't have exactly an array here | |
- uses: mikefarah/[email protected] | |
name: π° Parse YML file to extract id and labels | |
with: | |
cmd: | | |
yq -o=json -I=0 '.body[] | select(.type != "markdown") | {"id": .id, "label": .attributes.label}' .github/ISSUE_TEMPLATE/${{ env.TEMPLATE_FILE }} > template-keys.jsonl | |
- id: parse-issue | |
name: π IssueOps Form Parser | |
uses: issue-ops/[email protected] | |
with: | |
issue-form-template: ${{ env.TEMPLATE_FILE }} | |
body: ${{ github.event.issue.body }} | |
- name: πΎ Save result into a json file | |
run: | | |
echo '${{ steps.parse-issue.outputs.json }}' | jq '.' > original_answers.json | |
# https://til.codeinthehole.com/posts/about-jqs-slurp-option/ | |
- name: π Prepare template keys file | |
run: | | |
jq -s '[.[] | {key: (.label | ascii_downcase | gsub("[^a-z0-9]"; "_") | sub("^_+|_+$"; "") | gsub("_+"; "_")), value: .id}]' template-keys.jsonl > transformed_keys.json | |
jq 'reduce .[] as $item ({}; . + {($item.key): $item.value})' transformed_keys.json > keys_map.json | |
- name: π Show keys mappings | |
run: | | |
echo "$(cat keys_map.json)" | |
- name: π Replace Form keys by our keys | |
run: | | |
jq -s ' | |
# Load both JSON files as an array, with the first being the data and the second being the mapping | |
.[0] as $data | | |
.[1] as $mapping | | |
# Apply the mapping to rename keys | |
$data | with_entries(.key |= ($mapping[.] // .)) | |
' original_answers.json keys_map.json > output.json | |
- name: π Show result | |
run: | | |
echo "$(cat output.json)" | |
- name: π₯ Sent result to github outputs | |
id: processed | |
run: | | |
json_content=$(cat output.json | jq -c) | |
echo "json=$json_content" >> $GITHUB_OUTPUT | |
magic_time: | |
needs: process_issue | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
issues: write | |
env: | |
OPERATION: ${{ needs.process_issue.outputs.issue_type }} | |
REQUEST: ${{ needs.process_issue.outputs.issue_json }} | |
steps: | |
- name: ποΈ Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Node.js β¨ | |
uses: actions/[email protected] | |
with: | |
node-version: "lts/*" | |
- name: π» Install npm packages | |
run: npm install better-sqlite3 --no-save | |
- name: πΏ Do actions in database | |
run: | | |
node automatedTasks.mjs "$OPERATION" "$REQUEST" | |
- name: π€ Update JSON files after this change | |
run: npm run generate-api-json-files | |
- name: π Create Pull Request | |
id: cpr | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
title: "π€ ${{ github.event.issue.title }}" | |
body: | | |
### Automated ${{ env.OPERATION }} Change Details | |
The following changes were made to the JSON files based on the issue template : | |
```json | |
${{ toJson(fromJson(env.REQUEST)) }} | |
``` | |
Please review the changes. Closes #${{ github.event.issue.number }} | |
- name: π¬ Create comment with PR Link | |
if: ${{ steps.cpr.outputs.pull-request-number }} | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
π A pull request has been created to address this issue: | |
**PR Title**: π€ ${{ github.event.issue.title }} | |
**Link**: ${{ steps.cpr.outputs.pull-request-url }} | |
Please review the changes and provide your feedback. | |
reactions: rocket |