Skip to content

Commit da7d0a8

Browse files
authored
Merge pull request #33 from chrisgavin/safeexec-windows
Lookup path to `gh` safely on Windows.
2 parents 47c818b + 1b21375 commit da7d0a8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

cmd/root.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/chrisgavin/gh-dispatch/internal/workflow"
2121
"github.com/cli/go-gh"
2222
"github.com/cli/go-gh/pkg/repository"
23+
"github.com/cli/safeexec"
2324
"github.com/go-git/go-git/v5"
2425
"github.com/pkg/errors"
2526
log "github.com/sirupsen/logrus"
@@ -259,7 +260,12 @@ var rootCmd = &cobra.Command{
259260
return err
260261
}
261262

262-
command := exec.CommandContext(cmd.Context(), "gh", "run", "watch", "--repo", fmt.Sprintf("%s/%s/%s", currentRepository.Host(), currentRepository.Owner(), currentRepository.Name()), strconv.FormatInt(workflowRun.ID, 10))
263+
ghPath, err := safeexec.LookPath("gh")
264+
if err != nil {
265+
return errors.Wrap(err, "Unable to find gh.")
266+
}
267+
268+
command := exec.CommandContext(cmd.Context(), ghPath, "run", "watch", "--repo", fmt.Sprintf("%s/%s/%s", currentRepository.Host(), currentRepository.Owner(), currentRepository.Name()), strconv.FormatInt(workflowRun.ID, 10))
263269
command.Stdout = os.Stdout
264270
command.Stderr = os.Stderr
265271
err = command.Run()

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.17
55
require (
66
github.com/AlecAivazis/survey/v2 v2.3.4
77
github.com/cli/go-gh v0.0.3
8+
github.com/cli/safeexec v1.0.0
89
github.com/go-git/go-git/v5 v5.4.2
910
github.com/pkg/errors v0.9.1
1011
github.com/sirupsen/logrus v1.8.1
@@ -17,7 +18,6 @@ require (
1718
github.com/Microsoft/go-winio v0.4.16 // indirect
1819
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
1920
github.com/acomagu/bufpipe v1.0.3 // indirect
20-
github.com/cli/safeexec v1.0.0 // indirect
2121
github.com/cli/shurcooL-graphql v0.0.1 // indirect
2222
github.com/davecgh/go-spew v1.1.1 // indirect
2323
github.com/emirpasic/gods v1.12.0 // indirect

0 commit comments

Comments
 (0)