Skip to content
/ server Public

Commit 8e8535c

Browse files
author
gkodinov
committed
MDEV-38546: Automatically label new unlabeled pull requests
with foundation/corporation/external contribution The MariaDB server repository uses certain pull request labels as queue markers for incoming pull requests as follows: - External Contribution: for all external contributions - MariaDB Corporation: for employees of the MariaDB corporation - MariaDB Foundation: for the employees of the MariaDB foundation Right now, when a new pull request is filed, these tags need to be applied manually. However a large % of these manual assignments can be automated by checking if the author is in https://github.com/orgs/MariaDB/teams/staff or in https://github.com/orgs/MariaDB/teams/developers. If they are in staff "MariaDB Foundation" is assigned. if they are not in staff, but are in developers, "MariaDB Foundation" is assigned. If they are in neither staff not developers, "External Contribution" is assigned. A github workflow is created to do the assignments. It is being triggered every day at 2AM. Or it can be triggered manually.
1 parent accb4af commit 8e8535c

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Label recent pull requests
2+
3+
on:
4+
schedule:
5+
- cron: "0 2 * * *" # 02:00 UTC daily
6+
workflow_dispatch: # allow manual runs
7+
8+
permissions:
9+
contents: read
10+
pull-requests: write
11+
issues: write
12+
13+
jobs:
14+
label-prs:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Auto-label PRs
19+
env:
20+
REPO: ${{ github.repository }}
21+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
run: |
23+
set -euo pipefail
24+
25+
one_week_ago=$(date -u -d '7 days ago' +"%Y-%m-%dT%H:%M:%SZ")
26+
27+
echo "Checking PRs created after $one_week_ago"
28+
29+
# List open PRs as JSON
30+
gh pr list \
31+
--repo "$REPO" \
32+
--state open \
33+
--limit 200 \
34+
--json number,createdAt,labels,author |
35+
jq -c '.[]' |
36+
while read -r pr; do
37+
pr_number=$(echo "$pr" | jq -r '.number')
38+
created_at=$(echo "$pr" | jq -r '.createdAt')
39+
label_count=$(echo "$pr" | jq '.labels | length')
40+
author=$(echo "$pr" | jq -r '.author.login')
41+
42+
# Only PRs from the last week
43+
if [[ "$created_at" < "$one_week_ago" ]]; then
44+
continue
45+
fi
46+
47+
# Skip PRs that already have labels
48+
#if [[ "$label_count" -ne 0 ]]; then
49+
# continue
50+
#fi
51+
52+
#TODO: remove
53+
if [[ "$pr_number" -ne 4536 ]]; then
54+
continue
55+
fi
56+
57+
echo "Evaluating PR #$pr_number by $author"
58+
59+
is_developer=0
60+
# Check if author is in the developers team
61+
if gh api \
62+
-H "Accept: application/vnd.github+json" \
63+
"/orgs/MariaDB/teams/developers/members/$author" \
64+
--verbose; then
65+
echo "Author is in developers team"
66+
is_developer=1
67+
else
68+
echo "Author is not in developers team"
69+
fi
70+
is_foundation=0
71+
# Check if author is in the staff team
72+
if gh api \
73+
-H "Accept: application/vnd.github+json" \
74+
"/orgs/MariaDB/teams/staff/members/$author" \
75+
--verbose; then
76+
echo "Author is in staff team"
77+
is_foundation=1
78+
else
79+
echo "Author is not in staff team"
80+
fi
81+
82+
label="External Contribution"
83+
if [[ "$is_foundation" -ne 0 ]]; then
84+
label="MariaDB Foundation"
85+
else
86+
if [[ "$is_developer" -ne 0 ]]; then
87+
label="MariaDB Corporation"
88+
fi
89+
fi
90+
91+
echo "Applying label $label"
92+
gh issue edit "$pr_number" \
93+
--repo "$REPO" \
94+
--add-label "$label"
95+
done

0 commit comments

Comments
 (0)