-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea0fc31
commit f6c230c
Showing
7 changed files
with
118 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package providers | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCheckAzCliInstalled(t *testing.T) { | ||
EnsureAzCliInstalled() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package providers | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type SubLabel struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
// EnsureGhCliInstalled ensures that the Github CLI is installed and the user is logged in | ||
func EnsureGhCli() { | ||
EnsureGhCliInstalled() | ||
EnsureGhCliLoggedIn() | ||
} | ||
|
||
func EnsureGhCliInstalled() { | ||
log.Debug("Checking that github cli is installed...") | ||
ghCmd := exec.Command("gh") | ||
_, err := ghCmd.CombinedOutput() | ||
if err != nil { | ||
log.Fatal("Error: The github cli is required to complete this process. Find installation instructions at this link: https://github.com/cli/cli#installation") | ||
} | ||
|
||
log.Debug("Github cli found!") | ||
} | ||
|
||
func EnsureGhCliLoggedIn() { | ||
EnsureGhCliInstalled() | ||
if !IsLoggedInToGh() { | ||
if err := LogInToGh(); err != nil { | ||
log.Fatal("Error: unable to log in to github") | ||
} | ||
} | ||
} | ||
|
||
func IsLoggedInToGh() bool { | ||
log.Debug("Checking that user is logged in to github...") | ||
ghCmd := exec.Command("gh", "auth", "status") | ||
out, err := ghCmd.CombinedOutput() | ||
if err != nil { | ||
fmt.Printf(string(out)) | ||
return false | ||
} | ||
|
||
log.Debug("User is logged in!") | ||
return true | ||
|
||
} | ||
|
||
func LogInToGh() error { | ||
log.Debug("Logging user in to github...") | ||
ghCmd := exec.Command("gh", "auth", "login") | ||
ghCmd.Stdin = os.Stdin | ||
ghCmd.Stdout = os.Stdout | ||
ghCmd.Stderr = os.Stderr | ||
err := ghCmd.Run() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func isValidGhRepo(repo string) error { | ||
listReposCmd := exec.Command("gh", "repo", "view", repo) | ||
_, err := listReposCmd.CombinedOutput() | ||
if err != nil { | ||
log.Fatal("Github repo not found") | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package providers | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestHasGhCli(t *testing.T) { | ||
EnsureGhCliInstalled() | ||
} |
This file was deleted.
Oops, something went wrong.