This repository has been archived by the owner on Oct 13, 2024. It is now read-only.
[MOVIE]: The Courier (2020) #3717
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: Auto Update DB | |
on: | |
issues: | |
types: [labeled] | |
# no point in concurrency since it still cancels pending jobs | |
jobs: | |
auto_update_db: | |
if: (github.event.label.name == 'request-theme' || github.event.label.name == 'approve-theme') | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ github.token }} | |
steps: | |
- name: Check if member | |
if: (github.event.label.name == 'approve-theme') | |
# if someone, somehow, adds the approval label but isn't a member, then exit | |
run: | | |
gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
/orgs/${{ github.repository_owner }}/members/${{ github.actor }} || exit 1 | |
- name: Queue | |
# we only want to run one add job at a time, so queue them | |
if: (github.event.label.name == 'approve-theme') | |
uses: ahmadnassri/action-workflow-queue@v1 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: database | |
path: database | |
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token | |
fetch-depth: 0 # otherwise, will fail to push refs to dest repo | |
- name: Install Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Setup Python Dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install -r requirements.txt | |
- name: Parse Issue | |
uses: stefanbuck/github-issue-parser@v3 | |
id: issue-parser | |
with: | |
issue-body: ${{ github.event.issue.body }} | |
template-path: .github/ISSUE_TEMPLATE/theme.yml | |
- name: Crease JSON | |
run: | | |
echo '${{ steps.issue-parser.outputs.jsonString }}' > submission.json | |
- name: Get Issue Author ID | |
id: author | |
run: | | |
echo "issue_author_id=$(echo "${{ github.event.issue.user.id }}")" >> $GITHUB_OUTPUT | |
- name: Update | |
id: update | |
env: | |
ISSUE_AUTHOR_USER_ID: ${{ steps.author.outputs.issue_author_id }} | |
TMDB_API_KEY_V3: ${{ secrets.TMDB_API_KEY_V3 }} | |
TWITCH_CLIENT_ID: ${{ secrets.TWITCH_CLIENT_ID }} | |
TWITCH_CLIENT_SECRET: ${{ secrets.TWITCH_CLIENT_SECRET }} | |
run: | | |
python -u ./src/updater.py --issue_update | |
# if exceptions.md file exists, then set output to true | |
if [ -f exceptions.md ]; then | |
echo "exception=true" >> $GITHUB_OUTPUT | |
else | |
echo "exception=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Git Diff | |
id: diff | |
working-directory: database | |
run: | | |
echo "::group::issue_comment" | |
git add . | |
echo "" >> ../comment.md | |
echo "\`\`\`diff" >> ../comment.md | |
echo "$(git diff --cached)" >> ../comment.md | |
echo "\`\`\`" >> ../comment.md | |
cat ../comment.md | |
echo "::endgroup::" | |
echo "::group::issue_title" | |
cat ../title.md | |
echo "issue_title=$(cat ../title.md)" >> $GITHUB_OUTPUT | |
echo "::endgroup::" | |
- name: Update Issue Title | |
uses: actions/github-script@v6 | |
env: | |
ISSUE_TITLE: ${{ steps.diff.outputs.issue_title }} | |
with: | |
github-token: ${{ secrets.GH_BOT_TOKEN }} | |
script: | | |
github.rest.issues.update({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
title: process.env.ISSUE_TITLE | |
}) | |
- name: Update Labels for Exceptions | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GH_BOT_TOKEN }} | |
script: | | |
// get labels | |
const labels = await github.rest.issues.listLabelsOnIssue({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}) | |
// get exception output | |
const exception = "${{ steps.update.outputs.exception }}" | |
// check if labels list contains "exception" | |
const label_exception = labels.data.some(label => label.name === 'exception') | |
// add exception label if there was an exception and not already labeled | |
if (!label_exception && exception === 'true') { | |
github.rest.issues.addLabels({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
labels: ['exception'] | |
}) | |
} | |
// remove exception label if there is no longer an exception | |
if (label_exception && exception === 'false') { | |
github.rest.issues.removeLabel({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
name: ['exception'] | |
}) | |
} | |
// check if labels list contains "approve-theme" | |
approve_label = "approve-theme" | |
let label_add = labels.data.some(label => label.name === approve_label) | |
if (label_add && exception === 'true') { | |
github.rest.issues.removeLabel({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
name: [approve_label] | |
}) | |
} | |
// remove label "approve-queue" | |
queue_label = "approve-queue" | |
let label_remove = labels.data.some(label => label.name === queue_label) | |
if (label_remove) { | |
github.rest.issues.removeLabel({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
name: [queue_label] | |
}) | |
} | |
- name: Issue comment | |
uses: mshick/add-pr-comment@v2 | |
with: | |
repo-token: ${{ secrets.GH_BOT_TOKEN }} | |
message-path: comment.md | |
- name: GitHub Commit & Push | |
if: >- | |
(github.event.label.name == 'approve-theme') && | |
steps.update.outputs.exception == 'false' | |
uses: actions-js/[email protected] | |
with: | |
author_email: ${{ secrets.GH_BOT_EMAIL }} | |
author_name: ${{ secrets.GH_BOT_NAME }} | |
branch: database # commit to database | |
directory: database # use the database directory | |
github_token: ${{ secrets.GH_BOT_TOKEN }} | |
message: 'resolves #${{ github.event.issue.number }}' | |
- name: Close Issue | |
if: >- | |
(github.event.label.name == 'approve-theme') && | |
steps.update.outputs.exception == 'false' | |
env: | |
GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }} | |
run: | | |
comment="This theme has been added/updated and will be available on the next daily scheduled update." | |
close_reason="completed" | |
lock_reason="resolved" | |
gh issue close ${{ github.event.issue.number }} --comment "${comment}" --reason "${close_reason}" | |
gh issue lock ${{ github.event.issue.number }} --reason "${lock_reason}" | |
- name: Label next issue | |
if: >- | |
(github.event.label.name == 'approve-theme') && | |
steps.update.outputs.exception == 'false' | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GH_BOT_TOKEN }} | |
script: | | |
// get list of open issues | |
const issues = await github.rest.issues.listForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'open', | |
labels: 'approve-queue' | |
}) | |
// add approve-theme label to first issue found | |
if (issues.data.length > 0) { | |
github.rest.issues.addLabels({ | |
issue_number: issues.data[0].number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
labels: ['approve-theme'] | |
}) | |
} |