Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CLI Client Handling Non-Interactive Terminal and Error Message for Non-Canonical Repo #247

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/cli-client/internals/cli/cli_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func addHelp(p *flags.Parser) {
func blockForConfirm(s string) error {
// check if is a tty
fi, err := os.Stdin.Stat()
if err != nil || fi.Mode()&os.ModeNamedPipe == 0 {
if err != nil && fi.Mode()&os.ModeNamedPipe == 1 {
zhijie-yang marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("non-interactive terminal detected, run with -y option")
} else if err != nil {
return err
Expand Down
12 changes: 8 additions & 4 deletions tools/cli-client/internals/trigger/build_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ func InferBuildMetadata() BuildMetadata {
repo, err := git.PlainOpenWithOptions(".",
&git.PlainOpenOptions{DetectDotGit: true, EnableDotGitCommonDir: false})
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to open repository: %v", err)
fmt.Fprintf(os.Stderr, "Unable to open repository: %v\n", err)
os.Exit(1)
}

// find the source URL
remotes, err := repo.Remotes()
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to obtain remotes: %v", err)
fmt.Fprintf(os.Stderr, "Unable to obtain remotes: %v\n", err)
os.Exit(1)
}
if len(remotes) < 1 || len(remotes[0].Config().URLs) < 1 {
fmt.Fprintf(os.Stderr, "No valid remote exists for this repo")
fmt.Fprintf(os.Stderr, "No valid remote exists for this repo\n")
os.Exit(1)
}
remoteURL := remotes[0].Config().URLs[0]
Expand All @@ -49,12 +49,16 @@ func InferBuildMetadata() BuildMetadata {
// use regex to match the repo location
regex := regexp.MustCompile("github.com[:/](canonical/.*).git")
zhijie-yang marked this conversation as resolved.
Show resolved Hide resolved
matches := regex.FindStringSubmatch(remoteURL)
if len(matches) < 2 {
fmt.Fprintf(os.Stderr, "oci-factory must be called in a git local repository under organization [canonical]\n")
os.Exit(1)
}
source := matches[1]
zhijie-yang marked this conversation as resolved.
Show resolved Hide resolved
logger.Debugf("Source: %s", source)

headSha256, err := repo.ResolveRevision("HEAD")
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to resolve HEAD: %v", err)
fmt.Fprintf(os.Stderr, "Unable to resolve HEAD: %v\n", err)
os.Exit(1)
}
logger.Debugf("HEAD SHA-256: %s", headSha256)
Expand Down
Loading