mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:50:43 +00:00
chore: add positive proof labels (#78117)
This commit is contained in:
@@ -4,6 +4,8 @@ import {
|
||||
MOCK_ONLY_PROOF_LABEL,
|
||||
NEEDS_REAL_BEHAVIOR_PROOF_LABEL,
|
||||
PROOF_OVERRIDE_LABEL,
|
||||
PROOF_SUFFICIENT_LABEL,
|
||||
PROOF_SUPPLIED_LABEL,
|
||||
evaluateRealBehaviorProof,
|
||||
labelsForRealBehaviorProof,
|
||||
} from "./real-behavior-proof-policy.mjs";
|
||||
@@ -150,6 +152,14 @@ export const managedLabelSpecs = {
|
||||
color: "C5DEF5",
|
||||
description: "Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI.",
|
||||
},
|
||||
[PROOF_SUPPLIED_LABEL]: {
|
||||
color: "C2E0C6",
|
||||
description: "External PR includes structured after-fix real behavior proof.",
|
||||
},
|
||||
[PROOF_SUFFICIENT_LABEL]: {
|
||||
color: "0E8A16",
|
||||
description: "ClawSweeper judged the real behavior proof convincing.",
|
||||
},
|
||||
[PROOF_OVERRIDE_LABEL]: {
|
||||
color: "C2E0C6",
|
||||
description: "Maintainer override for the external PR real behavior proof gate.",
|
||||
@@ -218,7 +228,11 @@ const maintainerAuthorLabel = "maintainer";
|
||||
const privilegedAuthorAssociations = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
||||
const privilegedRepositoryRoles = new Set(["admin", "maintain", "write"]);
|
||||
const candidateLabelValues = Object.values(candidateLabels);
|
||||
const proofCandidateLabelValues = [NEEDS_REAL_BEHAVIOR_PROOF_LABEL, MOCK_ONLY_PROOF_LABEL];
|
||||
const structuralProofLabelValues = [
|
||||
NEEDS_REAL_BEHAVIOR_PROOF_LABEL,
|
||||
MOCK_ONLY_PROOF_LABEL,
|
||||
PROOF_SUPPLIED_LABEL,
|
||||
];
|
||||
const noisyPrMessage =
|
||||
"Closing this PR because it looks dirty (too many unrelated or unexpected changes). This usually happens when a branch picks up unrelated commits or a merge went sideways. Please recreate the PR from a clean branch.";
|
||||
|
||||
@@ -759,8 +773,21 @@ async function addMissingLabels(github, context, core, issueNumber, labels, labe
|
||||
core.info(`Added candidate labels to #${issueNumber}: ${missingLabels.join(", ")}`);
|
||||
}
|
||||
|
||||
function shouldRemoveProofSufficientLabel(context, proofEvaluation) {
|
||||
if (proofEvaluation.status !== "passed") {
|
||||
return true;
|
||||
}
|
||||
return ["edited", "synchronize"].includes(context.payload.action);
|
||||
}
|
||||
|
||||
async function applyPullRequestCandidateLabels(github, context, core, pullRequest, labelSet) {
|
||||
const files = await listPullRequestFiles(github, context, pullRequest);
|
||||
const proofEvaluation = evaluateRealBehaviorProof({
|
||||
pullRequest: {
|
||||
...pullRequest,
|
||||
labels: [...labelSet].map((name) => ({ name })),
|
||||
},
|
||||
});
|
||||
const classifiedLabels = classifyPullRequestCandidateLabels(
|
||||
{
|
||||
...pullRequest,
|
||||
@@ -768,9 +795,15 @@ async function applyPullRequestCandidateLabels(github, context, core, pullReques
|
||||
},
|
||||
files,
|
||||
);
|
||||
const staleProofLabels = proofCandidateLabelValues.filter(
|
||||
const staleProofLabels = structuralProofLabelValues.filter(
|
||||
(label) => labelSet.has(label) && !classifiedLabels.includes(label),
|
||||
);
|
||||
if (
|
||||
labelSet.has(PROOF_SUFFICIENT_LABEL) &&
|
||||
shouldRemoveProofSufficientLabel(context, proofEvaluation)
|
||||
) {
|
||||
staleProofLabels.push(PROOF_SUFFICIENT_LABEL);
|
||||
}
|
||||
await removeLabels(github, context, pullRequest.number, staleProofLabels, labelSet);
|
||||
await addMissingLabels(github, context, core, pullRequest.number, classifiedLabels, labelSet);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
export const PROOF_OVERRIDE_LABEL = "proof: override";
|
||||
export const PROOF_SUPPLIED_LABEL = "proof: supplied";
|
||||
export const PROOF_SUFFICIENT_LABEL = "proof: sufficient";
|
||||
export const NEEDS_REAL_BEHAVIOR_PROOF_LABEL = "triage: needs-real-behavior-proof";
|
||||
export const MOCK_ONLY_PROOF_LABEL = "triage: mock-only-proof";
|
||||
|
||||
@@ -75,6 +77,10 @@ function escapeRegex(text) {
|
||||
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
function normalizeLineEndings(text = "") {
|
||||
return text.replace(/\r\n?/g, "\n");
|
||||
}
|
||||
|
||||
function labelNames(labels) {
|
||||
return new Set(
|
||||
(labels ?? [])
|
||||
@@ -106,13 +112,14 @@ export function hasProofOverride(labels) {
|
||||
}
|
||||
|
||||
export function extractRealBehaviorProofSection(body = "") {
|
||||
const normalizedBody = normalizeLineEndings(body);
|
||||
const headingRegex = /^#{2,6}\s+real behavior proof\b[^\n]*$/gim;
|
||||
const match = headingRegex.exec(body);
|
||||
const match = headingRegex.exec(normalizedBody);
|
||||
if (!match) {
|
||||
return "";
|
||||
}
|
||||
const sectionStart = match.index + match[0].length;
|
||||
const rest = body.slice(sectionStart);
|
||||
const rest = normalizedBody.slice(sectionStart);
|
||||
const nextHeading = rest.match(/\n#{1,6}\s+\S/);
|
||||
return (nextHeading ? rest.slice(0, nextHeading.index) : rest).trim();
|
||||
}
|
||||
@@ -129,7 +136,7 @@ function isAnyProofFieldLine(line) {
|
||||
}
|
||||
|
||||
function extractFieldValue(section, field) {
|
||||
const lines = section.split("\n");
|
||||
const lines = normalizeLineEndings(section).split("\n");
|
||||
for (let index = 0; index < lines.length; index += 1) {
|
||||
const matchingName = field.names.find((name) => fieldLineRegex(name).test(lines[index]));
|
||||
if (!matchingName) {
|
||||
@@ -151,7 +158,7 @@ function extractFieldValue(section, field) {
|
||||
}
|
||||
|
||||
function stripProofFieldLabels(section) {
|
||||
return section
|
||||
return normalizeLineEndings(section)
|
||||
.split("\n")
|
||||
.map((line) => {
|
||||
if (!isAnyProofFieldLine(line)) {
|
||||
@@ -274,6 +281,9 @@ export function evaluateRealBehaviorProof({ pullRequest, labels } = {}) {
|
||||
}
|
||||
|
||||
export function labelsForRealBehaviorProof(evaluation) {
|
||||
if (evaluation.status === "passed") {
|
||||
return [PROOF_SUPPLIED_LABEL];
|
||||
}
|
||||
if (evaluation.status === "mock_only") {
|
||||
return [MOCK_ONLY_PROOF_LABEL];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user