Skip to content

Commit 3e8fe4c

Browse files
zakiskchmouel
authored andcommitted
fix(ci): use exec.CommandContext to satisfy noctx linter
Replaced all direct calls to exec.Command with the context-aware exec.CommandContext across CLI utilities and helper packages. Signed-off-by: Zaki Shaikh <[email protected]>
1 parent 3639f67 commit 3e8fe4c

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

pkg/cli/browser/browser.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package browser
22

33
import (
4+
"context"
45
"os/exec"
56
"runtime"
67
)
78

89
// OpenWebBrowser opens the specified URL in the default browser of the user.
9-
func OpenWebBrowser(url string) error {
10+
func OpenWebBrowser(ctx context.Context, url string) error {
1011
var cmd string
1112

1213
args := []string{}
@@ -21,5 +22,5 @@ func OpenWebBrowser(url string) error {
2122
}
2223

2324
args = append(args, url)
24-
return exec.Command(cmd, args...).Start()
25+
return exec.CommandContext(ctx, cmd, args...).Start()
2526
}

pkg/cmd/tknpac/bootstrap/install.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ func getLatestRelease(ctx context.Context, k8release string) (string, string, er
4848
}
4949

5050
// kubectlApply get kubectl binary and apply a yaml file.
51-
func kubectlApply(uri string) error {
51+
func kubectlApply(ctx context.Context, uri string) error {
5252
path, err := exec.LookPath("kubectl")
5353
if err != nil {
5454
return err
5555
}
56-
cmd := exec.Command(path, "apply", "-f", uri)
56+
cmd := exec.CommandContext(ctx, path, "apply", "-f", uri)
5757
out, err := cmd.CombinedOutput()
5858
if err != nil {
5959
return fmt.Errorf("%w\n%s", err, out)
@@ -112,7 +112,7 @@ func getDashboardURL(ctx context.Context, opts *bootstrapOpts, run *params.Run)
112112
}
113113

114114
// installGosmeeForwarder Install a gosmee forwarded to hook.pipelinesascode.com.
115-
func installGosmeeForwarder(opts *bootstrapOpts) error {
115+
func installGosmeeForwarder(ctx context.Context, opts *bootstrapOpts) error {
116116
gosmeInstall, err := askYN(true, fmt.Sprintf(gosmeeInstallHelpText, opts.forwarderURL), "Do you want me to install the gosmee forwarder?", opts.ioStreams.Out)
117117
if err != nil {
118118
return err
@@ -132,7 +132,7 @@ func installGosmeeForwarder(opts *bootstrapOpts) error {
132132
if _, err = f.WriteString(tmpl); err != nil {
133133
return err
134134
}
135-
if err := kubectlApply(f.Name()); err != nil {
135+
if err := kubectlApply(ctx, f.Name()); err != nil {
136136
return err
137137
}
138138
fmt.Fprintf(opts.ioStreams.Out, "💡 Your gosmee forward URL has been generated: %s\n", opts.RouteName)
@@ -175,14 +175,14 @@ func installPac(ctx context.Context, run *params.Run, opts *bootstrapOpts) error
175175
}
176176
}
177177

178-
if err := kubectlApply(latestReleaseYaml); err != nil {
178+
if err := kubectlApply(ctx, latestReleaseYaml); err != nil {
179179
return err
180180
}
181181

182182
fmt.Fprintf(opts.ioStreams.Out, "✓ Pipelines-as-Code %s has been installed\n", latestVersion)
183183

184184
if (!isOpenShift && opts.RouteName == "") || opts.forceInstallGosmee {
185-
if err := installGosmeeForwarder(opts); err != nil {
185+
if err := installGosmeeForwarder(ctx, opts); err != nil {
186186
return err
187187
}
188188
}

pkg/cmd/tknpac/bootstrap/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func startWebServer(ctx context.Context, opts *bootstrapOpts, run *params.Run, j
4545
url := fmt.Sprintf("http://localhost:%d", opts.webserverPort)
4646
fmt.Fprintf(opts.ioStreams.Out, "🌍 Starting a web browser on %s, click on the button to create your GitHub APP\n", url)
4747
//nolint:errcheck
48-
go browser.OpenWebBrowser(url)
48+
go browser.OpenWebBrowser(ctx, url)
4949
if err := s.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
5050
log.Fatal(err)
5151
}

pkg/cmd/tknpac/completion/completion.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package completion
22

33
import (
4+
"context"
45
"os/exec"
56
"strings"
67

@@ -10,7 +11,7 @@ import (
1011
// GetObjectsWithKubectl return completions with kubectl, we are doing this with
1112
// kubectl since we have caching and without it completion is way too slow.
1213
func GetObjectsWithKubectl(obj string) []string {
13-
out, err := exec.Command("kubectl", "get", obj, "-o=jsonpath={range .items[*]}{.metadata.name} {end}").Output()
14+
out, err := exec.CommandContext(context.Background(), "kubectl", "get", obj, "-o=jsonpath={range .items[*]}{.metadata.name} {end}").Output()
1415
if err != nil {
1516
return nil
1617
}

pkg/cmd/tknpac/logs/logs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,12 @@ func log(ctx context.Context, lo *logOption) error {
238238
replyName := strings.Fields(replyString)[0]
239239

240240
if lo.webBrowser {
241-
return showLogsWithWebConsole(lo, replyName)
241+
return showLogsWithWebConsole(ctx, lo, replyName)
242242
}
243243
return showlogswithtkn(lo.tknPath, replyName, lo.cs.Info.Kube.Namespace)
244244
}
245245

246-
func showLogsWithWebConsole(lo *logOption, pr string) error {
246+
func showLogsWithWebConsole(ctx context.Context, lo *logOption, pr string) error {
247247
if os.Getenv("PAC_TEKTON_DASHBOARD_URL") != "" {
248248
lo.cs.Clients.SetConsoleUI(&consoleui.TektonDashboard{BaseURL: os.Getenv("PAC_TEKTON_DASHBOARD_URL")})
249249
}
@@ -254,7 +254,7 @@ func showLogsWithWebConsole(lo *logOption, pr string) error {
254254
Namespace: lo.cs.Info.Kube.Namespace,
255255
},
256256
}
257-
return browser.OpenWebBrowser(lo.cs.Clients.ConsoleUI().DetailURL(prObj))
257+
return browser.OpenWebBrowser(ctx, lo.cs.Clients.ConsoleUI().DetailURL(prObj))
258258
}
259259

260260
func showlogswithtkn(tknPath, pr, ns string) error {

pkg/git/git.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package git
22

33
import (
44
"bytes"
5+
"context"
56
"fmt"
67
"os"
78
"os/exec"
@@ -24,7 +25,7 @@ func RunGit(dir string, args ...string) (string, error) {
2425
// insert in args "-c", "gitcommit.gpgsign=false" at the beginning gpg sign when set in user
2526
args = append([]string{"-c", "commit.gpgsign=false"}, args...)
2627

27-
c := exec.Command(gitPath, args...)
28+
c := exec.CommandContext(context.Background(), gitPath, args...)
2829
c.Env = []string{
2930
"PATH=" + os.Getenv("PATH"),
3031
"HOME=" + os.Getenv("HOME"),

0 commit comments

Comments
 (0)