(ctx context.Context, client *github.Client, owner, repo, workflowID, ref string, inputs map[string]any)
| 1016 | } |
| 1017 | |
| 1018 | func 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 | |
| 1059 | func 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) |
no test coverage detected