MCPcopy Create free account
hub / github.com/github/gh-aw / triggerWorkflowRun

Function triggerWorkflowRun

pkg/cli/trial_helpers.go:191–235  ·  view source on GitHub ↗
(repoSlug, workflowName string, triggerContext string, verbose bool)

Source from the content-addressed store, hash-verified

189}
190
191func triggerWorkflowRun(repoSlug, workflowName string, triggerContext string, verbose bool) (string, error) {
192 trialLog.Printf("Triggering workflow run: workflow=%s, repo=%s, hasTriggerContext=%v", workflowName, repoSlug, triggerContext != "")
193 if verbose {
194 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Triggering workflow run for: "+workflowName))
195 }
196
197 // Trigger workflow using gh CLI
198 lockFileName := workflowName + ".lock.yml"
199
200 // Build the command args
201 args := []string{"workflow", "run", lockFileName, "--repo", repoSlug}
202
203 // If trigger context is provided, extract issue number and add it as input
204 if triggerContext != "" {
205 issueNumber := parseIssueSpec(triggerContext)
206 if issueNumber != "" {
207 args = append(args, "--field", "issue_number="+issueNumber)
208 if verbose {
209 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Using issue number %s from trigger context", issueNumber)))
210 }
211 } else if verbose {
212 fmt.Fprintln(os.Stderr, console.FormatWarningMessage("Could not extract issue number from trigger context, running without inputs"))
213 }
214 }
215
216 output, err := workflow.RunGHCombined("Triggering workflow...", args...)
217
218 if err != nil {
219 return "", fmt.Errorf("failed to trigger workflow run: %w (output: %s)", err, string(output))
220 }
221
222 // Get the most recent run ID for this workflow using shared retry logic
223 runInfo, err := getLatestWorkflowRunWithRetry(lockFileName, repoSlug, verbose)
224 if err != nil {
225 return "", fmt.Errorf("failed to get workflow run ID: %w", err)
226 }
227
228 runID := strconv.FormatInt(runInfo.DatabaseID, 10)
229
230 if verbose {
231 fmt.Fprintln(os.Stderr, console.FormatSuccessMessage(fmt.Sprintf("Workflow run started with ID: %s (status: %s)", runID, runInfo.Status)))
232 }
233
234 return runID, nil
235}
236
237// parseIssueSpec extracts the issue number from various formats
238// Supports:

Callers 1

executeTrialRunFunction · 0.85

Calls 8

FormatInfoMessageFunction · 0.92
FormatWarningMessageFunction · 0.92
RunGHCombinedFunction · 0.92
FormatSuccessMessageFunction · 0.92
parseIssueSpecFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected