Skip to content
/ server Public

Commit e60b645

Browse files
author
gkodinov
committed
MDEV-38546: Copy the label from the last pull request by
the same contributor to the new pull request When triggered by a new or re-opened pull request, copy the labels from the last pull request by the same author. This helps to automatically clasify the incoming pull requests. It will: * look for prior pull requests by the same author * copy one of the following labels from the most recent pull request: - External Contribution: for all external contributions - MariaDB Corporation: for employees of the MariaDB corporation - MariaDB Foundation: for the employees of the MariaDB foundation - Codership: Galera codership code * apply the label to the new pull request Tested manually with a test repo.
1 parent accb4af commit e60b645

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Copy selected labels from previous PR by same author
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: read
10+
11+
jobs:
12+
copy-labels:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Copy selected labels from last PR by same author
17+
uses: actions/github-script@v7
18+
with:
19+
script: |
20+
const { owner, repo } = context.repo;
21+
const currentPr = context.payload.pull_request;
22+
const author = currentPr.user.login;
23+
const currentPrNumber = currentPr.number;
24+
25+
const allowedLabels = new Set([
26+
'External Contribution',
27+
'MariaDB Corporation',
28+
'MariaDB Foundation',
29+
'Codership']);
30+
31+
// List recent PRs
32+
const prs = await github.rest.pulls.list({
33+
owner,
34+
repo,
35+
state: 'all',
36+
sort: 'created',
37+
direction: 'desc',
38+
per_page: 20,
39+
});
40+
41+
// Find the most recent previous PR by the same author
42+
const previousPr = prs.data.find(
43+
pr => pr.user.login === author && pr.number !== currentPrNumber
44+
);
45+
46+
if (!previousPr) {
47+
console.log('No previous PR found for this author.');
48+
return;
49+
}
50+
51+
const labelsToCopy = (previousPr.labels || [])
52+
.map(label => label.name)
53+
.filter(name => allowedLabels.has(name));
54+
55+
if (labelsToCopy.length === 0) {
56+
console.log('No matching labels to copy.');
57+
return;
58+
}
59+
60+
console.log(`Applying labels from PR #${previousPr.number}:`, labelsToCopy);
61+
62+
await github.rest.issues.addLabels({
63+
owner,
64+
repo,
65+
issue_number: currentPrNumber,
66+
labels: labelsToCopy,
67+
});

0 commit comments

Comments
 (0)