(exec workflowRunDiagnosticExecutor, runListArgs []string)
| 92 | type workflowRunDiagnosticExecutor func(name string, args ...string) (stdout string, stderr string, err error) |
| 93 | |
| 94 | func collectWorkflowRunDiagnostics(exec workflowRunDiagnosticExecutor, runListArgs []string) string { |
| 95 | var diagnostics strings.Builder |
| 96 | fmt.Fprintf(&diagnostics, "run filters: %s\n", strings.Join(runListArgs, " ")) |
| 97 | run := func(label string, name string, args ...string) string { |
| 98 | stdout, stderr, err := exec(name, args...) |
| 99 | fmt.Fprintf(&diagnostics, "%s:\n", label) |
| 100 | if output := strings.TrimSpace(stdout); output != "" { |
| 101 | fmt.Fprintln(&diagnostics, output) |
| 102 | } |
| 103 | if output := strings.TrimSpace(stderr); output != "" { |
| 104 | fmt.Fprintf(&diagnostics, "stderr:\n%s\n", output) |
| 105 | } |
| 106 | if err != nil { |
| 107 | fmt.Fprintf(&diagnostics, "error: %v\n", err) |
| 108 | } |
| 109 | return strings.TrimSpace(stdout) |
| 110 | } |
| 111 | |
| 112 | run("repository", "git", "remote", "get-url", "origin") |
| 113 | commit := run("local commit", "git", "rev-parse", "HEAD") |
| 114 | branch := commandFlagValue(runListArgs, "--branch", "-b") |
| 115 | event := commandFlagValue(runListArgs, "--event", "-e") |
| 116 | |
| 117 | if branch != "" { |
| 118 | run("remote branch", "git", "ls-remote", "origin", "refs/heads/"+branch) |
| 119 | } |
| 120 | run("workflow files", "git", "ls-tree", "-r", "--name-only", "HEAD", ".github/workflows") |
| 121 | run("recent workflow runs", "gh", "run", "list", "--limit", "20", "--json", "databaseId,workflowName,event,headBranch,headSha,status,createdAt") |
| 122 | |
| 123 | if commit != "" { |
| 124 | run( |
| 125 | "commit check suites", |
| 126 | "gh", "api", "repos/{owner}/{repo}/commits/"+commit+"/check-suites", |
| 127 | "--jq", `.check_suites[] | {id, status, conclusion, app: .app.slug, head_sha}`, |
| 128 | ) |
| 129 | } |
| 130 | |
| 131 | apiArgs := []string{ |
| 132 | "api", "repos/{owner}/{repo}/actions/runs", |
| 133 | "--method", "GET", |
| 134 | "-f", "per_page=1", |
| 135 | "--include", |
| 136 | "--silent", |
| 137 | } |
| 138 | if branch != "" { |
| 139 | apiArgs = append(apiArgs, "-f", "branch="+branch) |
| 140 | } |
| 141 | if event != "" { |
| 142 | apiArgs = append(apiArgs, "-f", "event="+event) |
| 143 | } |
| 144 | if commit != "" { |
| 145 | apiArgs = append(apiArgs, "-f", "head_sha="+commit) |
| 146 | } |
| 147 | run("Actions API response headers", "gh", apiArgs...) |
| 148 | |
| 149 | return strings.TrimSpace(diagnostics.String()) |
| 150 | } |
| 151 |
no test coverage detected