Skip to content

Commit e42cd47

Browse files
authored
added labels for pr
1 parent 8fc4a0b commit e42cd47

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

.github/workflows/pr-format-check.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,47 @@ jobs:
5555
if (!hasValidSummary) {
5656
core.setFailed(`❌ PR must contain a meaningful summary section with actual text content (minimum 10 characters).
5757
Please add a clear description under the '### Summary' heading in your PR description.`);
58-
}
58+
}
59+
- name: Add size label based on PR diff
60+
uses: actions/github-script@v7
61+
with:
62+
script: |
63+
const pr = context.payload.pull_request;
64+
const additions = pr.additions;
65+
const deletions = pr.deletions;
66+
const totalChanges = additions + deletions;
67+
68+
// Threshold constants
69+
const SMALL_PR_THRESHOLD = 50;
70+
const MEDIUM_PR_THRESHOLD = 200;
71+
72+
let labelToAdd = '';
73+
if (totalChanges < SMALL_PR_THRESHOLD) {
74+
labelToAdd = 'pr-size: small';
75+
} else if (totalChanges < MEDIUM_PR_THRESHOLD) {
76+
labelToAdd = 'pr-size: medium';
77+
} else {
78+
labelToAdd = 'pr-size: large';
79+
}
80+
81+
// Remove existing size labels if any
82+
const existingLabels = pr.labels.map(l => l.name);
83+
const sizeLabels = ['pr-size: small', 'pr-size: medium', 'pr-size: large'];
84+
for (const label of existingLabels) {
85+
if (sizeLabels.includes(label)) {
86+
await github.rest.issues.removeLabel({
87+
...context.repo,
88+
issue_number: pr.number,
89+
name: label,
90+
});
91+
}
92+
}
93+
94+
// Add new size label
95+
await github.rest.issues.addLabels({
96+
...context.repo,
97+
issue_number: pr.number,
98+
labels: [labelToAdd],
99+
});
100+
101+
console.log(`Added label: ${labelToAdd} (Total changes: ${totalChanges})`);

0 commit comments

Comments
 (0)