forked from noctalia-dev/legacy-v4-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (89 loc) · 3.65 KB
/
Copy pathnotify-plugin-authors.yml
File metadata and controls
104 lines (89 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Auto-assign Plugin Reviewers
on:
pull_request_target:
types: [opened]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
assign-reviewers:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get changed files and assign reviewers
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
REPO: ${{ github.repository }}
run: |
# Get the list of changed files in this PR
changed_files=$(gh pr view $PR_NUMBER --json files --jq '.files[].path')
# Extract unique top-level directories from changed files
declare -A plugin_dirs
while IFS= read -r file; do
# Extract the first directory component (plugin name)
if [[ "$file" =~ ^([^/]+)/ ]]; then
plugin_dir="${BASH_REMATCH[1]}"
# Skip non-plugin directories
case "$plugin_dir" in
.git|.github|Bin) continue ;;
esac
plugin_dirs["$plugin_dir"]=1
fi
done <<< "$changed_files"
# For each modified plugin, find the original author
declare -A authors
for plugin in "${!plugin_dirs[@]}"; do
echo "Processing plugin: $plugin"
# Get the first commit author for this plugin
commit_sha=$(git log --diff-filter=A --format='%H' --reverse -- "$plugin/" 2>/dev/null | head -n 1)
if [[ -z "$commit_sha" ]]; then
commit_sha=$(git log --format='%H' --reverse -- "$plugin/" 2>/dev/null | head -n 1)
fi
if [[ -z "$commit_sha" ]]; then
echo "No commits found for $plugin"
continue
fi
# Get GitHub username via API
api_url="https://api.github.com/repos/$REPO/commits/$commit_sha"
response=$(gh api "$api_url" 2>/dev/null || echo "")
if [[ -z "$response" ]]; then
echo "Could not fetch commit info from GitHub API"
continue
fi
author=$(echo "$response" | jq -r '.author.login // empty')
if [[ -n "$author" ]]; then
if [[ "$author" == "$PR_AUTHOR" ]]; then
echo "Skipping notification for @$author (PR author)"
else
echo "Found author for $plugin: @$author"
authors["$author"]=1
fi
fi
done
# If we found any authors, notify them
if [[ ${#authors[@]} -eq 0 ]]; then
echo "No plugin authors found"
exit 0
fi
# Build the list of authors
author_list=(${!authors[@]})
author_mentions=$(printf '@%s ' "${author_list[@]}")
# Post appropriate comment based on number of plugins
comment_body=""
if [[ ${#plugin_dirs[@]} -eq 1 ]]; then
comment_body="${author_mentions}- this PR modifies your plugin. Please review when you have a chance."
else
comment_body="${author_mentions}- this PR modifies your plugins. Please review when you have a chance."
fi
# Post comment using gh CLI
gh pr comment "$PR_NUMBER" --body "$comment_body"