Skip to content

Commit 73cb3ec

Browse files
authored
Merge pull request cli#11312 from cli/babakks/avoid-fetching-logs-for-skipped-jobs
Avoid fetching logs for skipped jobs
2 parents 47f24b9 + f67bd9a commit 73cb3ec

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

pkg/cmd/run/shared/shared.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ func IsFailureState(c Conclusion) bool {
319319
}
320320
}
321321

322+
func IsSkipped(c Conclusion) bool {
323+
return c == Skipped
324+
}
325+
322326
type RunsPayload struct {
323327
TotalCount int `json:"total_count"`
324328
WorkflowRuns []Run `json:"workflow_runs"`

pkg/cmd/run/shared/test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ var LegacySuccessfulJobWithoutStepLogs Job = Job{
158158
},
159159
}
160160

161+
var SkippedJob Job = Job{
162+
ID: 13,
163+
Status: Completed,
164+
Conclusion: Skipped,
165+
Name: "cool job",
166+
StartedAt: TestRunStartTime,
167+
CompletedAt: TestRunStartTime,
168+
URL: "https://github.com/jobs/13",
169+
RunID: 3,
170+
Steps: []Step{},
171+
}
172+
161173
var FailedJob Job = Job{
162174
ID: 20,
163175
Status: Completed,

pkg/cmd/run/view/logs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ func populateLogSegments(httpClient *http.Client, repo ghrepo.Interface, jobs []
9191

9292
apiLogFetcherCount := 0
9393
for _, job := range jobs {
94+
if shared.IsSkipped(job.Conclusion) {
95+
continue
96+
}
97+
9498
if onlyFailed && !shared.IsFailureState(job.Conclusion) {
9599
continue
96100
}

pkg/cmd/run/view/view_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,29 @@ func TestViewRun(t *testing.T) {
22542254
wantErr: true,
22552255
errMsg: "job 20 is still in progress; logs will be available when it is complete",
22562256
},
2257+
{
2258+
name: "job log but job is skipped",
2259+
tty: false,
2260+
opts: &ViewOptions{
2261+
JobID: "13",
2262+
Log: true,
2263+
},
2264+
httpStubs: func(reg *httpmock.Registry) {
2265+
reg.Register(
2266+
httpmock.REST("GET", "repos/OWNER/REPO/actions/jobs/13"),
2267+
httpmock.JSONResponse(shared.SkippedJob))
2268+
reg.Register(
2269+
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/3"),
2270+
httpmock.JSONResponse(shared.SuccessfulRun))
2271+
reg.Register(
2272+
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/3/logs"),
2273+
httpmock.BinaryResponse(emptyZipArchive))
2274+
reg.Register(
2275+
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"),
2276+
httpmock.JSONResponse(shared.TestWorkflow))
2277+
},
2278+
wantOut: "",
2279+
},
22572280
{
22582281
name: "noninteractive with job",
22592282
opts: &ViewOptions{

0 commit comments

Comments
 (0)