Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/pr-notify-plugin-authors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Notify Plugin Authors for Pull Requests

on:
pull_request_target:
types: [opened]
paths-ignore:
- catalog.toml
- '.**'
- README.md
- README_TEMPLATE.md
workflow_dispatch:
inputs:
pull-request-number:
required: true
type: number

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/scripts/PyGithub-requirement.txt

- name: Install dependencies
run: pip install -r .github/workflows/scripts/PyGithub-requirement.txt

- name: Notify Authors
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ github.repository }}
PULL_REQUEST_NUMBER: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pull-request-number || github.event.pull_request.number }}
run: python3 .github/workflows/scripts/pr-notify-plugin-authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@

if "--- SELECT ---" in plugin:
issue.create_comment("Specify which plugin this issue is about!")
issue.edit(state='closed', state_reason='null')
issue.edit(state='closed')
70 changes: 70 additions & 0 deletions .github/workflows/scripts/pr-notify-plugin-authors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os
import sys

from github import Auth, Github

token = os.environ["GITHUB_TOKEN"]
repo_name = os.environ["REPOSITORY"]
pull_request_number = os.environ["PULL_REQUEST_NUMBER"]

auth = Auth.Token(token)
gh = Github(auth=auth)
repo = gh.get_repo(repo_name)

if pull_request_number.isdigit():
pull_request_number = int(pull_request_number)
else:
print("Pull Request number is not numeric!")
sys.exit(1)

pull_request = repo.get_pull(pull_request_number)

plugin_dirs = set()
hidden_dirs = set()
root_files = set()

for file in pull_request.get_files():
file_split = file.filename.split("/")
if len(file_split) > 1:
root_dir = file_split[0]
if root_dir.startswith('.'):
hidden_dirs.add(root_dir)
else:
plugin_dirs.add(root_dir)
else:
root_files.add(file)

if len(plugin_dirs) > 1:
print("Multiple plugin changes in one PR!")
pull_request.create_issue_comment("This pull request was automatically closed because it contains changes for two or more plugins in one PR!")
pull_request.edit(state='closed')
sys.exit(0)
elif len(plugin_dirs) == 1:
plugin_dir = plugin_dirs.pop()

manifest_file = f"{plugin_dir}/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)
else:
print("This is a non-plugin change, returning!")
sys.exit(0)


pr_author = pull_request.user.login

if pr_author == author:
print("The author and maintainer of the plugin are the same!")
sys.exit(0)
else:
pull_request.create_issue_comment(f"CC @{author}")
Loading