Skip to content

Commit

Permalink
[improvement] better handling of project name (#67)
Browse files Browse the repository at this point in the history
Signed-off-by: Benji Visser <benji@093b.org>
  • Loading branch information
noqcks authored Jun 29, 2023
1 parent 7ae04a8 commit 14f8eb7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func validateRootArgs(cmd *cobra.Command, args []string) error {
return fmt.Errorf("an image/directory argument is required")
}

if appConfig.APIKey != "" && appConfig.ProjectName == "" {
return fmt.Errorf("err: couldn't automatically detect a project name. Please set the project name using --project-name flag when using --api-key flag with xeol.io")
}

return cobra.MaximumNArgs(1)(cmd, args)
}

Expand Down Expand Up @@ -114,7 +118,7 @@ func setRootFlags(flags *pflag.FlagSet) {

flags.StringP(
"project-name", "", "",
"set the name of the project being analyzed for xeol.io.",
"manually set the name of the project being analyzed for xeol.io. If you are running xeol inside a git repository, this will be automatically detected.",
)

flags.StringP(
Expand Down
14 changes: 13 additions & 1 deletion internal/config/project_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,24 @@ func NewProject(repo *git.Repository) *Project {
}

func (p *Project) GetRemoteURL() string {
// try to get the origin remote
origin, err := p.Repo.Remote("origin")
if err == nil {
return origin.Config().URLs[0]
}

// if origin is not found, get the list of remotes
remotes, err := p.Repo.Remotes()
if err != nil {
return ""
}

return origin.Config().URLs[0]
if len(remotes) == 0 {
return ""
}

// return the URL of the first remote found
return remotes[0].Config().URLs[0]
}

func (p *Project) GetDefaultProjectName() string {
Expand Down
15 changes: 15 additions & 0 deletions test/integration/match_by_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ func addFedora29Matches(t *testing.T, theResult *match.Matches) {
Eol: "2019-11-26",
},
})
theResult.Add(match.Match{
Package: pkg.Package{
Name: "python",
ID: "2ba17cf1680ce4f2",
Version: "3.7.2",
Type: syftPkg.BinaryPkg,
Language: "",
PURL: "pkg:generic/python@3.7.2",
},
Cycle: eol.Cycle{
ProductName: "Python",
ReleaseCycle: "3.7",
Eol: "2023-06-27",
},
})
}

func TestMatchByImage(t *testing.T) {
Expand Down

0 comments on commit 14f8eb7

Please sign in to comment.