feat(workflow): Added notify-plugin-authors for issues (#145)
* feat(workflow): Added notify-plugin-authors for issues fix(workflow): Should be run correctly now fix(workflow): Added reopened fix(workflow): Removed cache fix(workflow): Added a lot, hope this works fix(workflow): Increment the i fix(workflow): Maybe? debug print cwd fix: Maybe now works? fix: maybe fix: For sure now fix: Some last fixes before it's done fix: Now the workflow adds a comment fix: Format A lot of commits in this one squashed together * fix(workflow): Do not use the provided plugin author name since that can be custom written and be another persons name * fix(workflow): Added propare caching so that we don't reinstall the dependencies everytime * fix(workflow): Added check for errors that have a very small chance to happen. * fix(workflow): Fixed some of the 'bugs', it should be fine now with better error handling * fix(workflow): Added correct guards for the workflow file * fix(workflow): Changed the name so that it can be used in the other workflow as well. * fix(workflow): skip quietly on unparseable plugin field, accept bare plugin name --------- Co-authored-by: Lemmy <studio@quadbyte.net>
This commit is contained in:
co-authored by
Lemmy
parent
35afaa444d
commit
dbd55675ff
@@ -0,0 +1,73 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from github import Auth, Github
|
||||||
|
|
||||||
|
token = os.environ["GITHUB_TOKEN"]
|
||||||
|
repo_name = os.environ["REPOSITORY"]
|
||||||
|
issue_number = os.environ["ISSUE_NUMBER"]
|
||||||
|
|
||||||
|
auth = Auth.Token(token)
|
||||||
|
gh = Github(auth=auth)
|
||||||
|
repo = gh.get_repo(repo_name)
|
||||||
|
|
||||||
|
if issue_number.isdigit():
|
||||||
|
issue_number = int(issue_number)
|
||||||
|
else:
|
||||||
|
print("Issue number is not numeric!")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
issue = repo.get_issue(issue_number)
|
||||||
|
body = issue.body
|
||||||
|
lines = body.splitlines()
|
||||||
|
|
||||||
|
try:
|
||||||
|
title_index = lines.index("### Plugin")
|
||||||
|
except ValueError:
|
||||||
|
print("No Plugin title found!")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(title_index + 1, len(lines)):
|
||||||
|
if lines[i]:
|
||||||
|
break
|
||||||
|
|
||||||
|
plugin = lines[i].strip()
|
||||||
|
plugin_split = plugin.split('/')
|
||||||
|
|
||||||
|
# The Plugin field is free text, so accept both the canonical "<author>/<plugin>" id and
|
||||||
|
# a bare plugin name, and skip quietly on anything else instead of failing the run.
|
||||||
|
if len(plugin_split) == 2:
|
||||||
|
plugin_name = plugin_split[1].strip()
|
||||||
|
elif len(plugin_split) == 1:
|
||||||
|
plugin_name = plugin_split[0]
|
||||||
|
else:
|
||||||
|
print(f"Unknown format of plugin name, got {plugin}")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if not plugin_name:
|
||||||
|
print("No plugin name given!")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
manifest_file = f"{plugin_name}/plugin.toml"
|
||||||
|
|
||||||
|
if os.path.exists(manifest_file):
|
||||||
|
file_commits = repo.get_commits(path=manifest_file).reversed
|
||||||
|
author = file_commits[0].author
|
||||||
|
|
||||||
|
if author is not None:
|
||||||
|
author = author.login
|
||||||
|
else:
|
||||||
|
print("Author name is null, returning!")
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print(f"Plugin manifest doesn't exist, {manifest_file}")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
if author:
|
||||||
|
issue.create_comment(f"CC @{author}")
|
||||||
|
else:
|
||||||
|
print("Could not get the author.")
|
||||||
|
sys.exit(1)
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
name: Notify Plugin Authors for Issues
|
||||||
|
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [opened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
issues: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
notify-plugin-authors:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.repository == 'noctalia-dev/community-plugins'
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
- uses: actions/setup-python@v7
|
||||||
|
with:
|
||||||
|
python-version: '3.14'
|
||||||
|
cache: 'pip'
|
||||||
|
cache-dependency-path: |
|
||||||
|
.github/workflows/notify-plugin-authors-requirements.txt
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: pip install -r .github/workflows/notify-plugin-authors-requirements.txt
|
||||||
|
|
||||||
|
- name: Notify Authors
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
REPOSITORY: ${{ github.repository }}
|
||||||
|
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
||||||
|
run: python3 .github/workflows/issues-notify-plugin-authors.py
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
PyGithub==2.9.1
|
||||||
Reference in New Issue
Block a user