feat: enhance PR label backfilling with size validation and warning tracking

This commit is contained in:
ciat-777
2026-03-15 13:39:19 +08:00
parent 84fffaa6fc
commit 8cd81ff48d
+24 -4
View File
@@ -85,6 +85,7 @@ jobs:
let inspected = 0; let inspected = 0;
let updated = 0; let updated = 0;
let skipped = 0; let skipped = 0;
let warned = 0;
for (const pull of pulls) { for (const pull of pulls) {
if (inspected >= limit) { if (inspected >= limit) {
@@ -93,6 +94,12 @@ jobs:
inspected += 1; inspected += 1;
const { data: fullPull } = await github.rest.pulls.get({
owner,
repo,
pull_number: pull.number,
});
const files = await github.paginate(github.rest.pulls.listFiles, { const files = await github.paginate(github.rest.pulls.listFiles, {
owner, owner,
repo, repo,
@@ -101,17 +108,28 @@ jobs:
}); });
const desiredAreaLabels = computeAreaLabels(files); const desiredAreaLabels = computeAreaLabels(files);
const desiredSizeLabel = computeSizeLabel(pull.additions + pull.deletions); const totalChanges = fullPull.additions + fullPull.deletions;
const hasValidSizeData = Number.isFinite(totalChanges) && totalChanges >= 0;
const currentLabels = pull.labels.map((label) => label.name); const currentLabels = pull.labels.map((label) => label.name);
const missingAreaLabels = desiredAreaLabels.filter((label) => !currentLabels.includes(label)); const missingAreaLabels = desiredAreaLabels.filter((label) => !currentLabels.includes(label));
const currentSizeLabels = currentLabels.filter((label) => sizeLabels.includes(label)); const currentSizeLabels = currentLabels.filter((label) => sizeLabels.includes(label));
const sizeMatches = currentSizeLabels.length === 1 && currentSizeLabels[0] === desiredSizeLabel; const desiredSizeLabel = hasValidSizeData ? computeSizeLabel(totalChanges) : null;
const sizeMatches =
hasValidSizeData &&
currentSizeLabels.length === 1 &&
currentSizeLabels[0] === desiredSizeLabel;
if (missingAreaLabels.length === 0 && sizeMatches) { if (!hasValidSizeData) {
warned += 1;
core.warning(`Skipping size label for PR #${pull.number}: invalid additions/deletions values.`);
}
if (missingAreaLabels.length === 0 && (hasValidSizeData ? sizeMatches : currentSizeLabels.length === 0)) {
skipped += 1; skipped += 1;
continue; continue;
} }
if (hasValidSizeData) {
for (const label of currentSizeLabels) { for (const label of currentSizeLabels) {
if (label === desiredSizeLabel) { if (label === desiredSizeLabel) {
continue; continue;
@@ -130,9 +148,10 @@ jobs:
} }
} }
} }
}
const labelsToAdd = [...missingAreaLabels]; const labelsToAdd = [...missingAreaLabels];
if (!sizeMatches) { if (hasValidSizeData && !sizeMatches) {
labelsToAdd.push(desiredSizeLabel); labelsToAdd.push(desiredSizeLabel);
} }
@@ -153,4 +172,5 @@ jobs:
.addRaw(`Inspected PRs: ${inspected}\n`) .addRaw(`Inspected PRs: ${inspected}\n`)
.addRaw(`Updated PRs: ${updated}\n`) .addRaw(`Updated PRs: ${updated}\n`)
.addRaw(`Skipped PRs: ${skipped}\n`) .addRaw(`Skipped PRs: ${skipped}\n`)
.addRaw(`Warnings: ${warned}\n`)
.write(); .write();