Skip to content

Fact suggestion

Fact suggestion #134

Workflow file for this run

# Overview of what we need to do:
# 1 - When a issue is labeled as 'suggestion', trigger the workflow.
# 2 - Retrieve the github username of the author of the issue
# 3 - Retrieve the issue's facts
# 4 - Parse the facts and put in a nice json format
# 5 - Read facts database
# 6 - Add the new fact(s) to facts database
# 7 - Overwrite facts database
# 8 - Add, commit, push
# 9 - :)
# Each of these steps introduce a new challenge.
# 1 needs a bit of search to know the syntax.
# 2~3 can be solved with env vars, I think.
# 4~7 are pretty much just plain programming,
# but... node or python? I wouldn't like to deal with npm for now.
# 8... authorizing things is tricky...
name: Add new fact
on:
issues:
types:
- labeled
jobs:
add-new-fact:
if: github.event.label.name == 'accepted'
runs-on: ubuntu-latest
env:
ISSUE_USER: ${{ github.event.issue.user.login }}
ISSUE_BODY: ${{ github.event.issue.body }}
steps:
# Downloads the repository, so I can update the facts database
- uses: actions/checkout@v2
# Shows issue info - Useful for debugging
- name: Shows issue
run: |
echo $ISSUE_USER
echo $ISSUE_BODY
# Function that will modify files
- name: Run main function
run: python facts/add_fact.py >> $GITHUB_ENV # Useful for setting env vars. Kinda dirty.
# Add and commit stuff
- name: Auto commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "add new facts. thanks, @${{env.ISSUE_USER}}!"
# Add reactions to issue
- name: Add reaction to original issue
uses: aidan-mundy/react-to-issue@v1.0.2
with:
issue-number: ${{ github.event.issue.number }}
# +1, -1, laugh, confused, heart, hooray, rocket, eyes
reactions: heart, hooray
# Comment and close original issue
- name: Close original issue
uses: peter-evans/close-issue@v1.0.3
with:
comment: |
Thanks for the contribution!
The facts added were ${{env.ADDED_FACTS}}.
You will be able to see them soon from [here.](https://touristfacts.dikson.xyz/?fact=${{env.FIRST_FACT}})