mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 21:01:43 +03:00
CI: gate auto-response with trigger label
This commit is contained in:
@@ -60,22 +60,47 @@ jobs:
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const triggerLabel = "trigger-response";
|
||||||
|
const target = context.payload.issue ?? context.payload.pull_request;
|
||||||
|
if (!target) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const labelSet = new Set(
|
||||||
|
(target.labels ?? [])
|
||||||
|
.map((label) => (typeof label === "string" ? label : label?.name))
|
||||||
|
.filter((name) => typeof name === "string"),
|
||||||
|
);
|
||||||
|
|
||||||
|
const hasTriggerLabel = labelSet.has(triggerLabel);
|
||||||
|
if (hasTriggerLabel) {
|
||||||
|
labelSet.delete(triggerLabel);
|
||||||
|
try {
|
||||||
|
await github.rest.issues.removeLabel({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: target.number,
|
||||||
|
name: triggerLabel,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
if (error?.status !== 404) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasTriggerLabel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const issue = context.payload.issue;
|
const issue = context.payload.issue;
|
||||||
if (issue) {
|
if (issue) {
|
||||||
const title = issue.title ?? "";
|
const title = issue.title ?? "";
|
||||||
const body = issue.body ?? "";
|
const body = issue.body ?? "";
|
||||||
const haystack = `${title}\n${body}`.toLowerCase();
|
const haystack = `${title}\n${body}`.toLowerCase();
|
||||||
const hasMoltbookLabel = (issue.labels ?? []).some((label) =>
|
const hasMoltbookLabel = labelSet.has("r: moltbook");
|
||||||
typeof label === "string" ? label === "r: moltbook" : label?.name === "r: moltbook",
|
const hasTestflightLabel = labelSet.has("r: testflight");
|
||||||
);
|
const hasSecurityLabel = labelSet.has("security");
|
||||||
const hasTestflightLabel = (issue.labels ?? []).some((label) =>
|
|
||||||
typeof label === "string"
|
|
||||||
? label === "r: testflight"
|
|
||||||
: label?.name === "r: testflight",
|
|
||||||
);
|
|
||||||
const hasSecurityLabel = (issue.labels ?? []).some((label) =>
|
|
||||||
typeof label === "string" ? label === "security" : label?.name === "security",
|
|
||||||
);
|
|
||||||
if (title.toLowerCase().includes("security") && !hasSecurityLabel) {
|
if (title.toLowerCase().includes("security") && !hasSecurityLabel) {
|
||||||
await github.rest.issues.addLabels({
|
await github.rest.issues.addLabels({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
@@ -83,7 +108,7 @@ jobs:
|
|||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
labels: ["security"],
|
labels: ["security"],
|
||||||
});
|
});
|
||||||
return;
|
labelSet.add("security");
|
||||||
}
|
}
|
||||||
if (title.toLowerCase().includes("testflight") && !hasTestflightLabel) {
|
if (title.toLowerCase().includes("testflight") && !hasTestflightLabel) {
|
||||||
await github.rest.issues.addLabels({
|
await github.rest.issues.addLabels({
|
||||||
@@ -92,7 +117,7 @@ jobs:
|
|||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
labels: ["r: testflight"],
|
labels: ["r: testflight"],
|
||||||
});
|
});
|
||||||
return;
|
labelSet.add("r: testflight");
|
||||||
}
|
}
|
||||||
if (haystack.includes("moltbook") && !hasMoltbookLabel) {
|
if (haystack.includes("moltbook") && !hasMoltbookLabel) {
|
||||||
await github.rest.issues.addLabels({
|
await github.rest.issues.addLabels({
|
||||||
@@ -101,13 +126,13 @@ jobs:
|
|||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
labels: ["r: moltbook"],
|
labels: ["r: moltbook"],
|
||||||
});
|
});
|
||||||
return;
|
labelSet.add("r: moltbook");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pullRequest = context.payload.pull_request;
|
const pullRequest = context.payload.pull_request;
|
||||||
if (pullRequest) {
|
if (pullRequest) {
|
||||||
const labelCount = pullRequest.labels?.length ?? 0;
|
const labelCount = labelSet.size;
|
||||||
if (labelCount > 20) {
|
if (labelCount > 20) {
|
||||||
await github.rest.issues.createComment({
|
await github.rest.issues.createComment({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
@@ -125,20 +150,12 @@ jobs:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const labelName = context.payload.label?.name;
|
const rule = rules.find((item) => labelSet.has(item.label));
|
||||||
if (!labelName) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const rule = rules.find((item) => item.label === labelName);
|
|
||||||
if (!rule) {
|
if (!rule) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const issueNumber = context.payload.issue?.number ?? context.payload.pull_request?.number;
|
const issueNumber = target.number;
|
||||||
if (!issueNumber) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await github.rest.issues.createComment({
|
await github.rest.issues.createComment({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
|
|||||||
Reference in New Issue
Block a user