Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
refactor(commands/ci): pass context.Context as first argument
Browse files Browse the repository at this point in the history
From: https://golang.org/pkg/context/

Do not store Contexts inside a struct type; instead, pass a
Context explicitly to each function that needs it. The Context
should be the first parameter, typically named ctx

https://deepsource.io/gh/profclems/glab/run/0801fe82-1e9c-42fd-acc7-affe7f2e2fbb/go/RVV-A0002/
  • Loading branch information
maxice8 committed Dec 28, 2020
1 parent 16efd43 commit 6732be6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion commands/ci/ciutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func DisplayMultiplePipelines(p []*gitlab.PipelineInfo, projectID string) string
return "No Pipelines available on " + projectID
}

func RunTrace(apiClient *gitlab.Client, ctx context.Context, w io.Writer, pid interface{}, sha, name string) error {
func RunTrace(ctx context.Context, apiClient *gitlab.Client, w io.Writer, pid interface{}, sha, name string) error {
fmt.Fprintln(w, "Getting job trace...")
for range time.NewTicker(time.Second * 3).C {
if ctx.Err() == context.Canceled {
Expand Down
2 changes: 1 addition & 1 deletion commands/ci/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TraceRun(opts *TraceOpts) error {
}
fmt.Fprintln(opts.IO.StdOut)

err = ciutils.RunTrace(apiClient, context.Background(), opts.IO.StdOut, repo.FullName(), job.Pipeline.Sha, job.Name)
err = ciutils.RunTrace(context.Background(), apiClient, opts.IO.StdOut, repo.FullName(), job.Pipeline.Sha, job.Name)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions commands/ci/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func inputCapture(a *tview.Application, root *tview.Pages, navi navigator, input
a.Suspend(func() {
ctx, cancel := context.WithCancel(context.Background())
go func() {
err := ciutils.RunTrace(apiClient, ctx, cOut, projectID, CommitSHA, curJob.Name)
err := ciutils.RunTrace(ctx, apiClient, cOut, projectID, CommitSHA, curJob.Name)
if err != nil {
a.Stop()
log.Fatal(err)
Expand Down Expand Up @@ -402,7 +402,7 @@ func jobsView(app *tview.Application, jobsCh chan []*gitlab.Job, inputCh chan st
tv.SetBorderPadding(0, 0, 1, 1).SetBorder(true)

go func() {
err := ciutils.RunTrace(apiClient, context.Background(), vtclean.NewWriter(tview.ANSIWriter(tv), true), projectID, CommitSHA, curJob.Name)
err := ciutils.RunTrace(context.Background(), apiClient, vtclean.NewWriter(tview.ANSIWriter(tv), true), projectID, CommitSHA, curJob.Name)
if err != nil {
app.Stop()
log.Fatal(err)
Expand Down

0 comments on commit 6732be6

Please sign in to comment.