Skip to content

Commit 008e30b

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 008e30b

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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: Label recent pull requests
19+
uses: actions/github-script@v7
20+
with:
21+
github-token: ${{ secrets.GITHUB_TOKEN }}
22+
script: |
23+
const foundationOrg = "MariaDB/teams/staff";
24+
const developersOrg = "MariaDB/teams/developers";
25+
26+
const now = new Date();
27+
const since = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
28+
29+
const owner = context.repo.owner;
30+
const repo = context.repo.repo;
31+
32+
// Get open PRs
33+
const prs = await github.paginate(
34+
github.rest.pulls.list,
35+
{
36+
owner,
37+
repo,
38+
state: "open",
39+
per_page: 100
40+
}
41+
);
42+
43+
for (const pr of prs) {
44+
const createdAt = new Date(pr.created_at);
45+
46+
// Only PRs from last 7 days with no labels
47+
if (createdAt < since || pr.labels.length > 0) {
48+
continue;
49+
}
50+
51+
const author = pr.user.login;
52+
core.info(`Processing PR #${pr.number} by ${author}`);
53+
54+
let isFoundation = false;
55+
let isDeveloper = false;
56+
57+
// Check foundationorg membership
58+
try {
59+
await github.rest.orgs.checkMembershipForUser({
60+
org: foundationOrg,
61+
username: author
62+
});
63+
isFoundation = true;
64+
} catch (e) {
65+
// not a member
66+
}
67+
68+
// Check developersorg membership
69+
try {
70+
await github.rest.orgs.checkMembershipForUser({
71+
org: developersOrg,
72+
username: author
73+
});
74+
isDeveloper = true;
75+
} catch (e) {
76+
// not a member
77+
}
78+
79+
let label;
80+
if (isFoundation) {
81+
label = "foundation";
82+
} else if (isDeveloper) {
83+
label = "plc";
84+
} else {
85+
label = "external";
86+
}
87+
88+
core.info(`Assigning label '${label}' to PR #${pr.number}`);
89+
90+
await github.rest.issues.addLabels({
91+
owner,
92+
repo,
93+
issue_number: pr.number,
94+
labels: [label]
95+
});
96+
}

0 commit comments

Comments
 (0)