Skip to content

Commit 5cb4ece

Browse files
committed
Renaming and cleanup
1 parent 67e45f1 commit 5cb4ece

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

pkg/cmd/run/view/view.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type browser interface {
3232
Browse(string) error
3333
}
3434

35-
type logs map[string]*job
35+
type runLog map[string]*job
3636

3737
type job struct {
3838
name string
@@ -222,7 +222,7 @@ func runView(opts *ViewOptions) error {
222222
return fmt.Errorf("job %d is still in progress; logs will be available when it is complete", selectedJob.ID)
223223
}
224224

225-
r, err := jobLog(httpClient, repo, selectedJob.ID)
225+
r, err := getJobLog(httpClient, repo, selectedJob.ID)
226226
if err != nil {
227227
return err
228228
}
@@ -250,18 +250,18 @@ func runView(opts *ViewOptions) error {
250250
return fmt.Errorf("run %d is still in progress; logs will be available when it is complete", run.ID)
251251
}
252252

253-
runLogZip, err := runLog(httpClient, repo, run.ID)
253+
runLogZip, err := getRunLog(httpClient, repo, run.ID)
254254
if err != nil {
255255
return fmt.Errorf("failed to get run log: %w", err)
256256
}
257257
opts.IO.StopProgressIndicator()
258258

259-
logs, err := readLogsFromZip(runLogZip)
259+
runLog, err := readRunLog(runLogZip)
260260
if err != nil {
261261
return err
262262
}
263263

264-
err = displayLogs(opts.IO, logs)
264+
err = displayRunLog(opts.IO, runLog)
265265
return err
266266
}
267267

@@ -388,13 +388,13 @@ func getLog(httpClient *http.Client, logURL string) (io.ReadCloser, error) {
388388
return resp.Body, nil
389389
}
390390

391-
func runLog(httpClient *http.Client, repo ghrepo.Interface, runID int) (io.ReadCloser, error) {
391+
func getRunLog(httpClient *http.Client, repo ghrepo.Interface, runID int) (io.ReadCloser, error) {
392392
logURL := fmt.Sprintf("%srepos/%s/actions/runs/%d/logs",
393393
ghinstance.RESTPrefix(repo.RepoHost()), ghrepo.FullName(repo), runID)
394394
return getLog(httpClient, logURL)
395395
}
396396

397-
func jobLog(httpClient *http.Client, repo ghrepo.Interface, jobID int) (io.ReadCloser, error) {
397+
func getJobLog(httpClient *http.Client, repo ghrepo.Interface, jobID int) (io.ReadCloser, error) {
398398
logURL := fmt.Sprintf("%srepos/%s/actions/jobs/%d/logs",
399399
ghinstance.RESTPrefix(repo.RepoHost()), ghrepo.FullName(repo), jobID)
400400
return getLog(httpClient, logURL)
@@ -435,17 +435,17 @@ func promptForJob(cs *iostreams.ColorScheme, jobs []shared.Job) (*shared.Job, er
435435
// └── jobname2/
436436
// ├── 1_stepname.txt
437437
// └── 2_somestepname.txt
438-
func readLogsFromZip(lz io.ReadCloser) (logs, error) {
439-
ls := make(logs)
440-
defer lz.Close()
441-
z, err := ioutil.ReadAll(lz)
438+
func readRunLog(rlz io.ReadCloser) (runLog, error) {
439+
rl := make(runLog)
440+
defer rlz.Close()
441+
z, err := ioutil.ReadAll(rlz)
442442
if err != nil {
443-
return ls, err
443+
return rl, err
444444
}
445445

446446
zipReader, err := zip.NewReader(bytes.NewReader(z), int64(len(z)))
447447
if err != nil {
448-
return ls, err
448+
return rl, err
449449
}
450450

451451
for _, zipFile := range zipReader.File {
@@ -456,19 +456,19 @@ func readLogsFromZip(lz io.ReadCloser) (logs, error) {
456456
if dir != "" && ext == ".txt" {
457457
split := strings.Split(file, "_")
458458
if len(split) != 2 {
459-
return ls, errors.New("invalid step log filename")
459+
return rl, errors.New("invalid step log filename")
460460
}
461461

462462
jobName := strings.TrimSuffix(dir, "/")
463463
stepName := strings.TrimSuffix(split[1], ".txt")
464464
stepOrder, err := strconv.Atoi(split[0])
465465
if err != nil {
466-
return ls, errors.New("invalid step log filename")
466+
return rl, errors.New("invalid step log filename")
467467
}
468468

469469
stepLogs, err := readZipFile(zipFile)
470470
if err != nil {
471-
return ls, err
471+
return rl, err
472472
}
473473

474474
st := step{
@@ -477,15 +477,15 @@ func readLogsFromZip(lz io.ReadCloser) (logs, error) {
477477
logs: string(stepLogs),
478478
}
479479

480-
if j, ok := ls[jobName]; !ok {
481-
ls[jobName] = &job{name: jobName, steps: []step{st}}
480+
if j, ok := rl[jobName]; !ok {
481+
rl[jobName] = &job{name: jobName, steps: []step{st}}
482482
} else {
483483
j.steps = append(j.steps, st)
484484
}
485485
}
486486
}
487487

488-
return ls, nil
488+
return rl, nil
489489
}
490490

491491
func readZipFile(zf *zip.File) ([]byte, error) {
@@ -497,21 +497,21 @@ func readZipFile(zf *zip.File) ([]byte, error) {
497497
return ioutil.ReadAll(f)
498498
}
499499

500-
func displayLogs(io *iostreams.IOStreams, ls logs) error {
500+
func displayRunLog(io *iostreams.IOStreams, rl runLog) error {
501501
err := io.StartPager()
502502
if err != nil {
503503
return err
504504
}
505505
defer io.StopPager()
506506

507507
var jobNames []string
508-
for name := range ls {
508+
for name := range rl {
509509
jobNames = append(jobNames, name)
510510
}
511511
sort.Strings(jobNames)
512512

513513
for _, name := range jobNames {
514-
job := ls[name]
514+
job := rl[name]
515515
steps := job.steps
516516
sort.Slice(steps, func(i, j int) bool {
517517
return steps[i].order < steps[j].order

pkg/cmd/run/view/view_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func TestViewRun(t *testing.T) {
401401
as.StubOne(2)
402402
as.StubOne(0)
403403
},
404-
wantOut: runLogOutput(),
404+
wantOut: expectedRunLogOutput,
405405
},
406406
{
407407
name: "noninteractive with run log",
@@ -418,7 +418,7 @@ func TestViewRun(t *testing.T) {
418418
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/3/logs"),
419419
httpmock.FileResponse("./fixtures/run_log.zip"))
420420
},
421-
wantOut: runLogOutput(),
421+
wantOut: expectedRunLogOutput,
422422
},
423423
{
424424
name: "run log but run is not done",
@@ -630,8 +630,7 @@ func TestViewRun(t *testing.T) {
630630
}
631631
}
632632

633-
func runLogOutput() string {
634-
return heredoc.Doc(`
633+
var expectedRunLogOutput = heredoc.Doc(`
635634
job1 step1 log line 1
636635
job1 step1 log line 2
637636
job1 step1 log line 3
@@ -645,4 +644,3 @@ job2 step2 log line 1
645644
job2 step2 log line 2
646645
job2 step2 log line 3
647646
`)
648-
}

0 commit comments

Comments
 (0)