Skip to content
/ server Public

Commit e514514

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 Corporation" is assigned. If they are in neither staff nor 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. This is stage1 of the fix: it is read only and only *prints* the changes needed
1 parent accb4af commit e514514

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
REPO=MariaDB/server
24+
set -euo pipefail
25+
nfailed=0
26+
27+
# List first 200 PRs lacking classification labels as JSON
28+
gh pr list \
29+
--repo "$REPO" \
30+
--search 'is:pr -label:"External Contribution" -label:"MariaDB Foundation" -label:"MariaDB Corporation" -label="Codership"' \
31+
--limit 200 \
32+
--json number,createdAt,labels,author |
33+
jq -c '.[]' |
34+
while read -r pr; do
35+
pr_number=$(echo "$pr" | jq -r '.number')
36+
created_at=$(echo "$pr" | jq -r '.createdAt')
37+
label_count=$(echo "$pr" | jq '.labels | length')
38+
author=$(echo "$pr" | jq -r '.author.login')
39+
40+
echo "Evaluating PR #$pr_number by $author"
41+
42+
# Check if author is in the developers team
43+
if gh api \
44+
-H "Accept: application/vnd.github+json" \
45+
"/orgs/MariaDB/teams/developers/members/$author" \
46+
>/dev/null 2>&1; then
47+
echo "Author is in developers team"
48+
is_developer=1
49+
else
50+
is_developer=0
51+
echo "Author is not in developers team"
52+
fi
53+
# Check if author is in the staff team
54+
if gh api \
55+
-H "Accept: application/vnd.github+json" \
56+
"/orgs/MariaDB/teams/staff/members/$author" \
57+
>/dev/null 2>&1; then
58+
echo "Author is in staff team"
59+
is_foundation=1
60+
else
61+
is_foundation=0
62+
echo "Author is not in staff team"
63+
fi
64+
65+
if [[ "$is_foundation" -ne 0 ]]; then
66+
label="MariaDB Foundation"
67+
else
68+
if [[ "$is_developer" -ne 0 ]]; then
69+
label="MariaDB Corporation"
70+
else
71+
label="External Contribution"
72+
fi
73+
fi
74+
75+
# start soft: read-only first.
76+
echo "Should apply label [$label] to PR#[$pr_number] by [$author]"
77+
78+
# echo "Applying label $label"
79+
# if gh issue edit "$pr_number" \
80+
# --repo "$REPO" \
81+
# --add-label "$label"; then
82+
# echo "**FAILED applying label [$label] to PR#[$pr_number] by [$author]"
83+
# nfailed=$((nfailed + 1))
84+
# fi
85+
done

0 commit comments

Comments
 (0)