Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

[MOVIE]: Teen Wolf: The Movie (2023) #17912

[MOVIE]: Teen Wolf: The Movie (2023)

[MOVIE]: Teen Wolf: The Movie (2023) #17912

---
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@v5
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
env:
JSON_STRING: ${{ steps.issue-parser.outputs.jsonString }}
run: |
echo ${JSON_STRING} > 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
# if duplicate.md file exists, then set output to true
if [ -f duplicate.md ]; then
echo "duplicate=true" >> $GITHUB_OUTPUT
else
echo "duplicate=false" >> $GITHUB_OUTPUT
fi
# if auto_close.md file exists, then set output to true
if [ -f auto_close.md ]; then
echo "auto_close=true" >> $GITHUB_OUTPUT
else
echo "auto_close=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
git diff --cached >> ../comment.md
echo "\`\`\`" >> ../comment.md
echo "" >> ../comment.md
echo "" >> ../comment.md
cat ../bot_commands.md >> ../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@v7
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
id: labels
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
result-encoding: string
script: |
// get labels
const labels = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
})
// get update outputs
const exception = "${{ steps.update.outputs.exception }}"
const duplicate = "${{ steps.update.outputs.duplicate }}"
// create an array of current labels
let current_labels = labels.data.map(label => label.name)
// check if labels list contains "exception"
const label_exception = current_labels.includes('exception')
// add exception label if there was an exception and not already labeled
if (!label_exception && exception === 'true') {
current_labels.push('exception')
} else if (label_exception && exception === 'false') {
// remove exception label if there is no longer an exception
const index = current_labels.indexOf('exception')
current_labels.splice(index, 1)
}
// check if labels list contains "duplicate"
const label_duplicate = current_labels.includes('duplicate')
// add duplicate label if there was a duplicate and not already labeled
if (!label_duplicate && duplicate === 'true') {
current_labels.push('duplicate')
} else if (label_duplicate && duplicate === 'false') {
// remove duplicate label if there is no longer a duplicate
const index = current_labels.indexOf('duplicate')
current_labels.splice(index, 1)
}
// check if labels list contains "approve-theme"
const approve_label = "approve-theme"
let label_add = current_labels.includes(approve_label)
if (label_add && exception === 'true') {
// remove approve-theme label if there is an exception
const index = current_labels.indexOf(approve_label)
current_labels.splice(index, 1)
}
// remove label "approve-queue"
const queue_label = "approve-queue"
// this is always removed
let label_remove = current_labels.includes(queue_label)
if (label_remove) {
const index = current_labels.indexOf(queue_label)
current_labels.splice(index, 1)
}
// set labels
await github.rest.issues.setLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: current_labels
})
// determine to continue or not
if (label_add) {
return 'true'
}
- name: Issue comment
uses: mshick/add-pr-comment@v2
with:
repo-token: ${{ secrets.GH_BOT_TOKEN }}
message-path: comment.md
- name: Auto Close
if: >-
(github.event.label.name == 'request-theme') &&
steps.update.outputs.auto_close == 'true'
env:
GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
run: |
comment=$(cat auto_close.md)
close_reason="not planned"
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: GitHub Commit & Push
if: >-
(github.event.label.name == 'approve-theme') &&
steps.update.outputs.exception == 'false' &&
steps.labels.outputs.result == 'true'
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' &&
steps.labels.outputs.result == 'true'
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@v7
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']
})
}