GetWorkflowRun fetches workflow run details using gh CLI
(runID string)
| 12 | |
| 13 | // GetWorkflowRun fetches workflow run details using gh CLI |
| 14 | func GetWorkflowRun(runID string) (*WorkflowRun, error) { |
| 15 | ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
| 16 | defer cancel() |
| 17 | |
| 18 | cmd := exec.CommandContext(ctx, "gh", "run", "view", runID, "--json", |
| 19 | "conclusion,name,headBranch,headSha,url,displayTitle,event,createdAt,jobs") |
| 20 | |
| 21 | output, err := cmd.Output() |
| 22 | if err != nil { |
| 23 | if exitErr, ok := err.(*exec.ExitError); ok { |
| 24 | return nil, fmt.Errorf("failed to get workflow run: %w (stderr: %s)", err, string(exitErr.Stderr)) |
| 25 | } |
| 26 | return nil, fmt.Errorf("failed to get workflow run: %w", err) |
| 27 | } |
| 28 | |
| 29 | var run WorkflowRun |
| 30 | if err := json.Unmarshal(output, &run); err != nil { |
| 31 | return nil, fmt.Errorf("failed to parse workflow run: %w", err) |
| 32 | } |
| 33 | |
| 34 | return &run, nil |
| 35 | } |
| 36 | |
| 37 | // GetCommitAuthor fetches commit author using gh CLI |
| 38 | func GetCommitAuthor(sha string) (string, error) { |
no test coverage detected