MCPcopy
hub / github.com/github/github-mcp-server / runWorkflow

Function runWorkflow

pkg/github/actions.go:1018–1057  ·  view source on GitHub ↗
(ctx context.Context, client *github.Client, owner, repo, workflowID, ref string, inputs map[string]any)

Source from the content-addressed store, hash-verified

1016}
1017
1018func runWorkflow(ctx context.Context, client *github.Client, owner, repo, workflowID, ref string, inputs map[string]any) (*mcp.CallToolResult, any, error) {
1019 event := github.CreateWorkflowDispatchEventRequest{
1020 Ref: ref,
1021 Inputs: inputs,
1022 }
1023
1024 var resp *github.Response
1025 var err error
1026 var workflowType string
1027
1028 if workflowIDInt, parseErr := strconv.ParseInt(workflowID, 10, 64); parseErr == nil {
1029 _, resp, err = client.Actions.CreateWorkflowDispatchEventByID(ctx, owner, repo, workflowIDInt, event)
1030 workflowType = "workflow_id"
1031 } else {
1032 _, resp, err = client.Actions.CreateWorkflowDispatchEventByFileName(ctx, owner, repo, workflowID, event)
1033 workflowType = "workflow_file"
1034 }
1035
1036 if err != nil {
1037 return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to run workflow", resp, err), nil, nil
1038 }
1039 defer func() { _ = resp.Body.Close() }()
1040
1041 result := map[string]any{
1042 "message": "Workflow run has been queued",
1043 "workflow_type": workflowType,
1044 "workflow_id": workflowID,
1045 "ref": ref,
1046 "inputs": inputs,
1047 "status": resp.Status,
1048 "status_code": resp.StatusCode,
1049 }
1050
1051 r, err := json.Marshal(result)
1052 if err != nil {
1053 return nil, nil, fmt.Errorf("failed to marshal response: %w", err)
1054 }
1055
1056 return utils.NewToolResultText(string(r)), nil, nil
1057}
1058
1059func rerunWorkflowRun(ctx context.Context, client *github.Client, owner, repo string, runID int64) (*mcp.CallToolResult, any, error) {
1060 resp, err := client.Actions.RerunWorkflowByID(ctx, owner, repo, runID)

Callers 1

ActionsRunTriggerFunction · 0.85

Calls 2

NewToolResultTextFunction · 0.92
CloseMethod · 0.80

Tested by

no test coverage detected