From 89899aa1b9193be14a749100cc98d7f279fdbad4 Mon Sep 17 00:00:00 2001 From: Benji Visser Date: Tue, 23 Jan 2024 19:56:37 -0500 Subject: [PATCH] Revert "allow passing of commit hash on the cli" (#279) --- cmd/xeol/cli/options/xeol.go | 30 +------------- cmd/xeol/internal/types/commit.go | 16 ------- cmd/xeol/internal/types/commit_test.go | 27 ------------ cmd/xeol/internal/types/projectname.go | 16 ------- cmd/xeol/internal/types/projectname_test.go | 46 --------------------- 5 files changed, 1 insertion(+), 134 deletions(-) delete mode 100644 cmd/xeol/internal/types/commit.go delete mode 100644 cmd/xeol/internal/types/commit_test.go delete mode 100644 cmd/xeol/internal/types/projectname.go delete mode 100644 cmd/xeol/internal/types/projectname_test.go diff --git a/cmd/xeol/cli/options/xeol.go b/cmd/xeol/cli/options/xeol.go index f20423ef..3cc89889 100644 --- a/cmd/xeol/cli/options/xeol.go +++ b/cmd/xeol/cli/options/xeol.go @@ -9,7 +9,6 @@ import ( git "github.com/go-git/go-git/v5" "github.com/karrick/tparse" - "github.com/xeol-io/xeol/cmd/xeol/internal/types" "github.com/xeol-io/xeol/internal/format" ) @@ -100,11 +99,6 @@ func (o *Xeol) AddFlags(flags clio.FlagSet) { "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.StringVarP(&o.CommitHash, - "commit-hash", "", - "manually set the commit hash of the project being analyzed for xeol.io. If you are running xeol inside a git repository, this will be automatically detected.", - ) - flags.StringVarP(&o.APIKey, "api-key", "", "set the API key for xeol.io. When this is set, scans will be uploaded to xeol.io.", @@ -155,28 +149,6 @@ func (o *Xeol) parseLookaheadOption() (err error) { return nil } -func (o *Xeol) parseProjectAndCommitOption() (err error) { - if o.APIKey != "" { - if o.ProjectName == "" { - return fmt.Errorf("must specify a project name when using --api-key. This is usually inferred automatically when running inside a git repository, but you may also pass it manually with --project-name") - } - if err := types.ProjectName(o.ProjectName).IsValid(); err != nil { - return err - } - - if o.CommitHash == "" { - return fmt.Errorf("must specify a commit hash when using --api-key. This is usually inferred automatically when running inside a git repository, but you may also pass it manually with --commit-hash") - } - if err := types.CommitHash(o.CommitHash).IsValid(); err != nil { - return err - } - } - return nil -} - func (o *Xeol) PostLoad() error { - if err := o.parseLookaheadOption(); err != nil { - return err - } - return o.parseProjectAndCommitOption() + return o.parseLookaheadOption() } diff --git a/cmd/xeol/internal/types/commit.go b/cmd/xeol/internal/types/commit.go deleted file mode 100644 index d8951672..00000000 --- a/cmd/xeol/internal/types/commit.go +++ /dev/null @@ -1,16 +0,0 @@ -package types - -import ( - "fmt" - "regexp" -) - -type CommitHash string - -func (c CommitHash) IsValid() error { - re := regexp.MustCompile(`^[a-fA-F0-9]{40}$`) - if !re.MatchString(string(c)) { - return fmt.Errorf("invalid SHA1 hash format for commit hash '%s'", string(c)) - } - return nil -} diff --git a/cmd/xeol/internal/types/commit_test.go b/cmd/xeol/internal/types/commit_test.go deleted file mode 100644 index 3258599a..00000000 --- a/cmd/xeol/internal/types/commit_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package types - -import ( - "testing" -) - -func TestCommitHash_IsValid(t *testing.T) { - tests := []struct { - name string - hash CommitHash - wantErr bool - }{ - {"Valid SHA1", "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", false}, - {"Invalid SHA1 - Short", "a94a8fe5cc", true}, - {"Invalid SHA1 - Long", "a94a8fe5ccb19ba61c4c0873d391e9879", true}, - {"Invalid SHA1 - Special Characters", "a94a8fe5cc#19ba61c4c0873d391e9$", true}, - {"Invalid SHA1 - Empty", "", true}, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := tt.hash.IsValid(); (err != nil) != tt.wantErr { - t.Errorf("CommitHash.IsValid() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} diff --git a/cmd/xeol/internal/types/projectname.go b/cmd/xeol/internal/types/projectname.go deleted file mode 100644 index fa6e84cf..00000000 --- a/cmd/xeol/internal/types/projectname.go +++ /dev/null @@ -1,16 +0,0 @@ -package types - -import ( - "fmt" - "regexp" -) - -type ProjectName string - -func (p ProjectName) IsValid() error { - re := regexp.MustCompile(`^(gitlab|github|azure)//([a-zA-Z0-9\-_]+/[a-zA-Z0-9\-_]+(/[a-zA-Z0-9\-_]+)?)$`) - if ok := re.MatchString(string(p)); !ok { - return fmt.Errorf("invalid project name. Accepted formats: 'gitlab///', 'github///', 'azure////'") - } - return nil -} diff --git a/cmd/xeol/internal/types/projectname_test.go b/cmd/xeol/internal/types/projectname_test.go deleted file mode 100644 index 9a8c1d58..00000000 --- a/cmd/xeol/internal/types/projectname_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package types - -import "testing" - -func TestIsValidProjectName(t *testing.T) { - tests := []struct { - projectName string - wantErr bool - }{ - { - projectName: "gitlab//noqcks/test", - wantErr: false, - }, - { - projectName: "github//noqcks/test", - wantErr: false, - }, - { - projectName: "azure//noqcks/test", - wantErr: false, - }, - { - projectName: "azure//noqcks/test/test", - wantErr: false, - }, - { - projectName: "azure//noqcks/test/test/test", - wantErr: true, - }, - { - projectName: "azure//noqcks", - wantErr: true, - }, - { - projectName: "test//test", - wantErr: true, - }, - } - - for _, test := range tests { - err := ProjectName(test.projectName).IsValid() - if test.wantErr && err == nil { - t.Errorf("Expected error for '%s', but got nil", test.projectName) - } - } -}