@@ -4,21 +4,21 @@ import {
44 isTriggeredByUserInteraction ,
55 isPushEvent ,
66 isJiraWorkflowDispatchEvent ,
7- isResolveConflictsWorkflowDispatchEvent , isPullRequestEvent , isPullRequestReviewEvent , isIssueCommentEvent ,
7+ isResolveConflictsWorkflowDispatchEvent , isPullRequestEvent , isPullRequestReviewEvent , isIssueCommentEvent , isWorkflowRunFailureEvent ,
88} from "../context" ;
99import { checkHumanActor } from "../validation/actor" ;
1010import { postJunieWorkingStatusComment } from "../operations/comments/feedback" ;
1111import { initializeJunieWorkspace } from "../operations/branch" ;
1212import { PrepareJunieOptions } from "./types/junie" ;
13- import { detectJunieTriggerPhrase } from "../validation/trigger" ;
13+ import { detectJunieTriggerPhrase , isReviewOrCommentHasFixCITrigger } from "../validation/trigger" ;
1414import { configureGitCredentials } from "../operations/auth" ;
1515import { prepareMcpConfig } from "../../mcp/prepare-mcp-config" ;
1616import { verifyRepositoryAccess } from "../validation/permissions" ;
1717import { Octokits } from "../api/client" ;
1818import { prepareJunieTask } from "./junie-tasks" ;
1919import { prepareJunieCLIToken } from "./junie-token" ;
2020import { OUTPUT_VARS } from "../../constants/environment" ;
21- import { RESOLVE_CONFLICTS_ACTION } from "../../constants/github" ;
21+ import { RESOLVE_CONFLICTS_ACTION , FIX_CI_ACTION } from "../../constants/github" ;
2222import { getJiraClient } from "../jira/client" ;
2323
2424/**
@@ -62,10 +62,27 @@ export async function initializeJunieExecution({
6262
6363 // Get PR-specific info for MCP servers
6464 const prNumber = context . isPR ? context . entityNumber : undefined ;
65- const commitSha = branchInfo . headSha ;
65+
66+ // For workflow_run events, use the workflow run's head_sha (the commit that was tested)
67+ // This is critical for the checks server to find the correct check runs
68+ let commitSha = branchInfo . headSha ;
69+ if ( isWorkflowRunFailureEvent ( context ) ) {
70+ const workflowRunSha = ( context . payload as any ) . workflow_run ?. head_sha ;
71+ if ( workflowRunSha ) {
72+ console . log ( `Using workflow_run head_sha for checks: ${ workflowRunSha } ` ) ;
73+ commitSha = workflowRunSha ;
74+ }
75+ }
76+
77+ // Detect if this is a fix-ci action (needed for auto-enabling checks server)
78+ const isFixCIInPrompt = context . inputs . prompt ?. includes ( FIX_CI_ACTION ) ;
79+ const isFixCIInComment = isReviewOrCommentHasFixCITrigger ( context ) ;
80+ const isFixCIFromWorkflowFailure = isWorkflowRunFailureEvent ( context ) ;
81+ const isFixCI = isFixCIInPrompt || isFixCIInComment || isFixCIFromWorkflowFailure ;
6682
6783 // Prepare MCP configuration with automatic server activation
6884 // - Inline comment server: enabled for PRs (requires commitSha)
85+ // - Checks server: enabled for fix-ci action or when explicitly requested
6986 const mcpConfig = await prepareMcpConfig ( {
7087 junieWorkingDir : context . inputs . junieWorkingDir ,
7188 allowedMcpServers : mcpServers ,
@@ -74,7 +91,8 @@ export async function initializeJunieExecution({
7491 repo : context . payload . repository . name ,
7592 branchInfo : branchInfo ,
7693 prNumber : prNumber ,
77- commitSha : commitSha
94+ commitSha : commitSha ,
95+ isFixCI : isFixCI
7896 } )
7997
8098 await prepareJunieTask ( context , branchInfo , octokit , mcpConfig . enabledServers )
@@ -104,6 +122,10 @@ async function shouldHandle(context: JunieExecutionContext, octokit: Octokits):
104122 return true ;
105123 }
106124
125+ if ( isWorkflowRunFailureEvent ( context ) ) {
126+ return true ;
127+ }
128+
107129 return isTriggeredByUserInteraction ( context ) && detectJunieTriggerPhrase ( context ) && checkHumanActor ( octokit . rest , context ) ;
108130}
109131
0 commit comments