mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 06:54:13 +08:00
Add label trigger functionality to Claude Code Action (#177)
- introduced a new input parameter `label_trigger` in `action.yml` to allow triggering actions based on specific labels applied to issues. - Enhanced the context preparation and event handling in the code to support the new labled event.
This commit is contained in:
committed by
GitHub
parent
c831be8f54
commit
b0d9b8c4cd
@@ -81,6 +81,7 @@ export function prepareContext(
|
||||
const eventAction = context.eventAction;
|
||||
const triggerPhrase = context.inputs.triggerPhrase || "@claude";
|
||||
const assigneeTrigger = context.inputs.assigneeTrigger;
|
||||
const labelTrigger = context.inputs.labelTrigger;
|
||||
const customInstructions = context.inputs.customInstructions;
|
||||
const allowedTools = context.inputs.allowedTools;
|
||||
const disallowedTools = context.inputs.disallowedTools;
|
||||
@@ -256,6 +257,19 @@ export function prepareContext(
|
||||
claudeBranch,
|
||||
...(assigneeTrigger && { assigneeTrigger }),
|
||||
};
|
||||
} else if (eventAction === "labeled") {
|
||||
if (!labelTrigger) {
|
||||
throw new Error("LABEL_TRIGGER is required for issue labeled event");
|
||||
}
|
||||
eventData = {
|
||||
eventName: "issues",
|
||||
eventAction: "labeled",
|
||||
isPR: false,
|
||||
issueNumber,
|
||||
baseBranch,
|
||||
claudeBranch,
|
||||
labelTrigger,
|
||||
};
|
||||
} else if (eventAction === "opened") {
|
||||
eventData = {
|
||||
eventName: "issues",
|
||||
@@ -328,6 +342,11 @@ export function getEventTypeAndContext(envVars: PreparedContext): {
|
||||
eventType: "ISSUE_CREATED",
|
||||
triggerContext: `new issue with '${envVars.triggerPhrase}' in body`,
|
||||
};
|
||||
} else if (eventData.eventAction === "labeled") {
|
||||
return {
|
||||
eventType: "ISSUE_LABELED",
|
||||
triggerContext: `issue labeled with '${eventData.labelTrigger}'`,
|
||||
};
|
||||
}
|
||||
return {
|
||||
eventType: "ISSUE_ASSIGNED",
|
||||
@@ -467,6 +486,7 @@ Follow these steps:
|
||||
- Analyze the pre-fetched data provided above.
|
||||
- For ISSUE_CREATED: Read the issue body to find the request after the trigger phrase.
|
||||
- For ISSUE_ASSIGNED: Read the entire issue body to understand the task.
|
||||
- For ISSUE_LABELED: Read the entire issue body to understand the task.
|
||||
${eventData.eventName === "issue_comment" || eventData.eventName === "pull_request_review_comment" || eventData.eventName === "pull_request_review" ? ` - For comment/review events: Your instructions are in the <trigger_comment> tag above.` : ""}
|
||||
${context.directPrompt ? ` - DIRECT INSTRUCTION: A direct instruction was provided and is shown in the <direct_prompt> tag above. This is not from any GitHub comment but a direct instruction to execute.` : ""}
|
||||
- IMPORTANT: Only the comment/issue containing '${context.triggerPhrase}' has your instructions.
|
||||
|
||||
@@ -68,6 +68,16 @@ type IssueAssignedEvent = {
|
||||
assigneeTrigger?: string;
|
||||
};
|
||||
|
||||
type IssueLabeledEvent = {
|
||||
eventName: "issues";
|
||||
eventAction: "labeled";
|
||||
isPR: false;
|
||||
issueNumber: string;
|
||||
baseBranch: string;
|
||||
claudeBranch: string;
|
||||
labelTrigger: string;
|
||||
};
|
||||
|
||||
type PullRequestEvent = {
|
||||
eventName: "pull_request";
|
||||
eventAction?: string; // opened, synchronize, etc.
|
||||
@@ -85,6 +95,7 @@ export type EventData =
|
||||
| IssueCommentEvent
|
||||
| IssueOpenedEvent
|
||||
| IssueAssignedEvent
|
||||
| IssueLabeledEvent
|
||||
| PullRequestEvent;
|
||||
|
||||
// Combined type with separate eventData field
|
||||
|
||||
@@ -29,6 +29,7 @@ export type ParsedGitHubContext = {
|
||||
inputs: {
|
||||
triggerPhrase: string;
|
||||
assigneeTrigger: string;
|
||||
labelTrigger: string;
|
||||
allowedTools: string[];
|
||||
disallowedTools: string[];
|
||||
customInstructions: string;
|
||||
@@ -53,6 +54,7 @@ export function parseGitHubContext(): ParsedGitHubContext {
|
||||
inputs: {
|
||||
triggerPhrase: process.env.TRIGGER_PHRASE ?? "@claude",
|
||||
assigneeTrigger: process.env.ASSIGNEE_TRIGGER ?? "",
|
||||
labelTrigger: process.env.LABEL_TRIGGER ?? "",
|
||||
allowedTools: parseMultilineInput(process.env.ALLOWED_TOOLS ?? ""),
|
||||
disallowedTools: parseMultilineInput(process.env.DISALLOWED_TOOLS ?? ""),
|
||||
customInstructions: process.env.CUSTOM_INSTRUCTIONS ?? "",
|
||||
|
||||
@@ -13,7 +13,7 @@ import type { ParsedGitHubContext } from "../context";
|
||||
|
||||
export function checkContainsTrigger(context: ParsedGitHubContext): boolean {
|
||||
const {
|
||||
inputs: { assigneeTrigger, triggerPhrase, directPrompt },
|
||||
inputs: { assigneeTrigger, labelTrigger, triggerPhrase, directPrompt },
|
||||
} = context;
|
||||
|
||||
// If direct prompt is provided, always trigger
|
||||
@@ -34,6 +34,16 @@ export function checkContainsTrigger(context: ParsedGitHubContext): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for label trigger
|
||||
if (isIssuesEvent(context) && context.eventAction === "labeled") {
|
||||
const labelName = (context.payload as any).label?.name || "";
|
||||
|
||||
if (labelTrigger && labelName === labelTrigger) {
|
||||
console.log(`Issue labeled with trigger label '${labelTrigger}'`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for issue body and title trigger on issue creation
|
||||
if (isIssuesEvent(context) && context.eventAction === "opened") {
|
||||
const issueBody = context.payload.issue.body || "";
|
||||
|
||||
Reference in New Issue
Block a user