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

[PLUGIN]: m00nwtchr/PlexEbooks.bundle #1078

[PLUGIN]: m00nwtchr/PlexEbooks.bundle

[PLUGIN]: m00nwtchr/PlexEbooks.bundle #1078

---
name: Auto Update DB
on:
issues:
types: [labeled]
# no point in concurrency since it still cancels pending jobs
# concurrency:
# # only if label starts with "request" then add issue number to end of group
# group: >-
# ${{ github.workflow }}-${{ github.event.label.name }}
# ${{ startsWith(github.event.label.name, 'request-') | github.event.issue.number }}
# cancel-in-progress: false # false to act as queue
jobs:
auto_update_db:
if: >-
(github.event.label.name == 'add-plugin' || github.event.label.name == 'request-plugin')
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Check if member
if: startsWith(github.event.label.name, 'add-')
# if someone, somehow, adds a label that starts with "add-" 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: startsWith(github.event.label.name, 'add-')
uses: ahmadnassri/action-workflow-queue@v1
- name: Checkout
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
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/plugin.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:
PAT_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
ISSUE_AUTHOR_USER_ID: ${{ steps.author.outputs.issue_author_id }}
run: |
python -u ./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 "add-plugin"
const label_add_plugin = labels.data.some(label => label.name === 'add-plugin')
// remove add-plugin label if there was an exception
if (label_add_plugin && exception === 'true') {
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ['add-plugin']
})
}
- 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: >-
startsWith(github.event.label.name, 'add-') &&
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: >-
startsWith(github.event.label.name, 'add-') &&
steps.update.outputs.exception == 'false'
env:
GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
run: |
comment="This plugin 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}"