fix(run list): do not fail on org workflows
This commit is contained in:
parent
b78734068d
commit
5817f6fce9
3 changed files with 64 additions and 0 deletions
|
|
@ -366,6 +366,44 @@ func TestListRun(t *testing.T) {
|
|||
completed stale cool commit CI trunk push 10 4m34s 2021-02-23T04:51:00Z
|
||||
`),
|
||||
},
|
||||
{
|
||||
name: "organization required workflow in run list (workflow GET returns 404)",
|
||||
opts: &ListOptions{
|
||||
Limit: defaultLimit,
|
||||
now: shared.TestRunStartTime.Add(time.Minute*4 + time.Second*34),
|
||||
},
|
||||
isTTY: true,
|
||||
stubs: func(reg *httpmock.Registry) {
|
||||
reg.Register(
|
||||
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs"),
|
||||
httpmock.JSONResponse(shared.RunsPayload{
|
||||
WorkflowRuns: shared.TestRunsWithOrgRequiredWorkflows,
|
||||
}))
|
||||
reg.Register(
|
||||
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows"),
|
||||
httpmock.JSONResponse(workflowShared.WorkflowsPayload{
|
||||
Workflows: []workflowShared.Workflow{
|
||||
shared.TestWorkflow,
|
||||
},
|
||||
}))
|
||||
reg.Register(
|
||||
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/456"),
|
||||
httpmock.StatusStringResponse(404, "not found"),
|
||||
)
|
||||
},
|
||||
wantOut: heredoc.Doc(`
|
||||
STATUS TITLE WORKFLOW BRANCH EVENT ID ELAPSED AGE
|
||||
X cool commit trunk push 1 4m34s about 4 minutes ago
|
||||
* cool commit trunk push 2 4m34s about 4 minutes ago
|
||||
✓ cool commit trunk push 3 4m34s about 4 minutes ago
|
||||
X cool commit trunk push 4 4m34s about 4 minutes ago
|
||||
X cool commit CI trunk push 5 4m34s about 4 minutes ago
|
||||
- cool commit CI trunk push 6 4m34s about 4 minutes ago
|
||||
- cool commit CI trunk push 7 4m34s about 4 minutes ago
|
||||
* cool commit CI trunk push 8 4m34s about 4 minutes ago
|
||||
* cool commit CI trunk push 9 4m34s about 4 minutes ago
|
||||
`),
|
||||
},
|
||||
{
|
||||
name: "pagination",
|
||||
opts: &ListOptions{
|
||||
|
|
|
|||
|
|
@ -446,6 +446,16 @@ func preloadWorkflowNames(client *api.Client, repo ghrepo.Interface, runs []Run)
|
|||
if _, ok := workflowMap[run.WorkflowID]; !ok {
|
||||
// Look up workflow by ID because it may have been deleted
|
||||
workflow, err := workflowShared.GetWorkflow(client, repo, run.WorkflowID)
|
||||
// If the error is an httpError and it is a 404, this is likely a
|
||||
// organization-level "required workflow" ruleset. The user does not
|
||||
// have permissions to view the details of the workflow, so we cannot
|
||||
// look it up directly without receiving a 404, but it is nonetheless
|
||||
// in the workflow run list. To handle this, we set the workflow name
|
||||
// to an empty string.
|
||||
if httpErr, ok := err.(api.HTTPError); ok && httpErr.StatusCode == 404 {
|
||||
workflowMap[run.WorkflowID] = ""
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ func TestRunWithCommit(id int64, s Status, c Conclusion, commit string) Run {
|
|||
return TestRunWithWorkflowAndCommit(123, id, s, c, commit)
|
||||
}
|
||||
|
||||
func TestRunWithOrgRequiredWorkflow(id int64, s Status, c Conclusion, commit string) Run {
|
||||
return TestRunWithWorkflowAndCommit(456, id, s, c, commit)
|
||||
}
|
||||
|
||||
func TestRunWithWorkflowAndCommit(workflowId, runId int64, s Status, c Conclusion, commit string) Run {
|
||||
return Run{
|
||||
WorkflowID: workflowId,
|
||||
|
|
@ -57,6 +61,18 @@ var TestRuns []Run = []Run{
|
|||
TestRun(10, Completed, Stale),
|
||||
}
|
||||
|
||||
var TestRunsWithOrgRequiredWorkflows []Run = []Run{
|
||||
TestRunWithOrgRequiredWorkflow(1, Completed, TimedOut, "cool commit"),
|
||||
TestRunWithOrgRequiredWorkflow(2, InProgress, "", "cool commit"),
|
||||
TestRunWithOrgRequiredWorkflow(3, Completed, Success, "cool commit"),
|
||||
TestRunWithOrgRequiredWorkflow(4, Completed, Cancelled, "cool commit"),
|
||||
TestRun(5, Completed, Failure),
|
||||
TestRun(6, Completed, Neutral),
|
||||
TestRun(7, Completed, Skipped),
|
||||
TestRun(8, Requested, ""),
|
||||
TestRun(9, Queued, ""),
|
||||
}
|
||||
|
||||
var WorkflowRuns []Run = []Run{
|
||||
TestRun(2, InProgress, ""),
|
||||
SuccessfulRun,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue