From 532be61d6bcfca854670250f663cd8d400f8c31b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 14:35:50 +0000 Subject: [PATCH 01/16] Bump github.com/in-toto/attestation from 1.1.0 to 1.1.1 Bumps [github.com/in-toto/attestation](https://github.com/in-toto/attestation) from 1.1.0 to 1.1.1. - [Release notes](https://github.com/in-toto/attestation/releases) - [Commits](https://github.com/in-toto/attestation/compare/v1.1.0...v1.1.1) --- updated-dependencies: - dependency-name: github.com/in-toto/attestation dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ca5549587..ba20dc0bd 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-version v1.3.0 github.com/henvic/httpretty v0.1.4 - github.com/in-toto/attestation v1.1.0 + github.com/in-toto/attestation v1.1.1 github.com/joho/godotenv v1.5.1 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/mattn/go-colorable v0.1.14 diff --git a/go.sum b/go.sum index 5a7147b19..9dbbcdcd7 100644 --- a/go.sum +++ b/go.sum @@ -265,8 +265,8 @@ github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68= github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef h1:A9HsByNhogrvm9cWb28sjiS3i7tcKCkflWFEkHfuAgM= github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs= -github.com/in-toto/attestation v1.1.0 h1:oRWzfmZPDSctChD0VaQV7MJrywKOzyNrtpENQFq//2Q= -github.com/in-toto/attestation v1.1.0/go.mod h1:DB59ytd3z7cIHgXxwpSX2SABrU6WJUKg/grpdgHVgVs= +github.com/in-toto/attestation v1.1.1 h1:QD3d+oATQ0dFsWoNh5oT0udQ3tUrOsZZ0Fc3tSgWbzI= +github.com/in-toto/attestation v1.1.1/go.mod h1:Dcq1zVwA2V7Qin8I7rgOi+i837wEf/mOZwRm047Sjys= github.com/in-toto/in-toto-golang v0.9.0 h1:tHny7ac4KgtsfrG6ybU8gVOZux2H8jN05AXJ9EBM1XU= github.com/in-toto/in-toto-golang v0.9.0/go.mod h1:xsBVrVsHNsB61++S6Dy2vWosKhuA3lUTQd+eF9HdeMo= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= From e8475d9fb8a3cd2193bbbecce3706a547dcdbd51 Mon Sep 17 00:00:00 2001 From: Michael Hoffman Date: Sat, 11 Jan 2025 20:00:44 -0500 Subject: [PATCH 02/16] Initial, working implementation --- pkg/cmd/repo/autolink/autolink.go | 2 + pkg/cmd/repo/autolink/list/list.go | 9 +- pkg/cmd/repo/autolink/shared/autolink.go | 7 ++ pkg/cmd/repo/autolink/view/http.go | 47 ++++++++++ pkg/cmd/repo/autolink/view/view.go | 107 +++++++++++++++++++++++ 5 files changed, 164 insertions(+), 8 deletions(-) create mode 100644 pkg/cmd/repo/autolink/view/http.go create mode 100644 pkg/cmd/repo/autolink/view/view.go diff --git a/pkg/cmd/repo/autolink/autolink.go b/pkg/cmd/repo/autolink/autolink.go index 1fd218354..09b766b85 100644 --- a/pkg/cmd/repo/autolink/autolink.go +++ b/pkg/cmd/repo/autolink/autolink.go @@ -4,6 +4,7 @@ import ( "github.com/MakeNowJust/heredoc" cmdCreate "github.com/cli/cli/v2/pkg/cmd/repo/autolink/create" cmdList "github.com/cli/cli/v2/pkg/cmd/repo/autolink/list" + cmdView "github.com/cli/cli/v2/pkg/cmd/repo/autolink/view" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/spf13/cobra" ) @@ -24,6 +25,7 @@ func NewCmdAutolink(f *cmdutil.Factory) *cobra.Command { cmd.AddCommand(cmdList.NewCmdList(f, nil)) cmd.AddCommand(cmdCreate.NewCmdCreate(f, nil)) + cmd.AddCommand(cmdView.NewCmdView(f, nil)) return cmd } diff --git a/pkg/cmd/repo/autolink/list/list.go b/pkg/cmd/repo/autolink/list/list.go index a68c03f3c..74267e7a4 100644 --- a/pkg/cmd/repo/autolink/list/list.go +++ b/pkg/cmd/repo/autolink/list/list.go @@ -15,13 +15,6 @@ import ( "github.com/spf13/cobra" ) -var autolinkFields = []string{ - "id", - "isAlphanumeric", - "keyPrefix", - "urlTemplate", -} - type listOptions struct { BaseRepo func() (ghrepo.Interface, error) Browser browser.Browser @@ -70,7 +63,7 @@ func NewCmdList(f *cmdutil.Factory, runF func(*listOptions) error) *cobra.Comman } cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "List autolink references in the web browser") - cmdutil.AddJSONFlags(cmd, &opts.Exporter, autolinkFields) + cmdutil.AddJSONFlags(cmd, &opts.Exporter, domain.AutolinkFields) return cmd } diff --git a/pkg/cmd/repo/autolink/shared/autolink.go b/pkg/cmd/repo/autolink/shared/autolink.go index d79537c31..28e975e7c 100644 --- a/pkg/cmd/repo/autolink/shared/autolink.go +++ b/pkg/cmd/repo/autolink/shared/autolink.go @@ -9,6 +9,13 @@ type Autolink struct { URLTemplate string `json:"url_template"` } +var AutolinkFields = []string{ + "id", + "isAlphanumeric", + "keyPrefix", + "urlTemplate", +} + func (a *Autolink) ExportData(fields []string) map[string]interface{} { return cmdutil.StructExportData(a, fields) } diff --git a/pkg/cmd/repo/autolink/view/http.go b/pkg/cmd/repo/autolink/view/http.go new file mode 100644 index 000000000..d3fdfc86a --- /dev/null +++ b/pkg/cmd/repo/autolink/view/http.go @@ -0,0 +1,47 @@ +package view + +import ( + "encoding/json" + "fmt" + "net/http" + + "github.com/cli/cli/v2/api" + "github.com/cli/cli/v2/internal/ghinstance" + "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/pkg/cmd/repo/autolink/domain" +) + +type AutolinkViewer struct { + HTTPClient *http.Client +} + +func (a *AutolinkViewer) View(repo ghrepo.Interface, id string) (*domain.Autolink, error) { + path := fmt.Sprintf("repos/%s/%s/autolinks/%s", repo.RepoOwner(), repo.RepoName(), id) + url := ghinstance.RESTPrefix(repo.RepoHost()) + path + req, err := http.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := a.HTTPClient.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + if resp.StatusCode == http.StatusNotFound { + return nil, fmt.Errorf("HTTP 404: Either no autolink with this ID exists for this repository or you are missing admin rights to the repository. (https://api.github.com/%s)", path) + } else if resp.StatusCode > 299 { + return nil, api.HandleHTTPError(resp) + } + + var autolink domain.Autolink + err = json.NewDecoder(resp.Body).Decode(&autolink) + + if err != nil { + fmt.Println(err.Error()) + return nil, err + } + + return &autolink, nil +} diff --git a/pkg/cmd/repo/autolink/view/view.go b/pkg/cmd/repo/autolink/view/view.go new file mode 100644 index 000000000..2d0cfd6c6 --- /dev/null +++ b/pkg/cmd/repo/autolink/view/view.go @@ -0,0 +1,107 @@ +package view + +import ( + "fmt" + + "github.com/MakeNowJust/heredoc" + "github.com/cli/cli/v2/internal/browser" + "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/pkg/cmd/repo/autolink/domain" + "github.com/cli/cli/v2/pkg/cmdutil" + "github.com/cli/cli/v2/pkg/iostreams" + "github.com/spf13/cobra" +) + +type viewOptions struct { + BaseRepo func() (ghrepo.Interface, error) + Browser browser.Browser + AutolinkClient AutolinkViewClient + IO *iostreams.IOStreams + Exporter cmdutil.Exporter + + ID string +} + +type AutolinkViewClient interface { + View(repo ghrepo.Interface, id string) (*domain.Autolink, error) +} + +func NewCmdView(f *cmdutil.Factory, runF func(*viewOptions) error) *cobra.Command { + opts := &viewOptions{ + Browser: f.Browser, + IO: f.IOStreams, + } + + cmd := &cobra.Command{ + Use: "view ", + Short: "View an autolink reference", + Long: heredoc.Docf(` + View an autolink reference for a repository. + + Information about autolinks is only available to repository administrators. + `), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + opts.BaseRepo = f.BaseRepo + httpClient, err := f.HttpClient() + + if err != nil { + return err + } + + opts.ID = args[0] + + if err != nil { + return err + } + + opts.AutolinkClient = &AutolinkViewer{HTTPClient: httpClient} + + if runF != nil { + return runF(opts) + } + + return viewRun(opts) + }, + } + + cmdutil.AddJSONFlags(cmd, &opts.Exporter, domain.AutolinkFields) + + return cmd +} + +func viewRun(opts *viewOptions) error { + repo, err := opts.BaseRepo() + if err != nil { + return err + } + cs := opts.IO.ColorScheme() + + autolink, err := opts.AutolinkClient.View(repo, opts.ID) + + if err != nil { + return fmt.Errorf("%s %w", cs.Red("error viewing autolink:"), err) + } + + if opts.Exporter != nil { + return opts.Exporter.Write(opts.IO, autolink) + } + + msg := heredoc.Docf(` + Autolink in %s + + ID: %d + Key Prefix: %s + URL Template: %s + Alphanumeric: %t + `, + ghrepo.FullName(repo), + autolink.ID, + autolink.KeyPrefix, + autolink.URLTemplate, + autolink.IsAlphanumeric, + ) + fmt.Fprint(opts.IO.Out, msg) + + return nil +} From f941608091c29411cafcfb5173d6f29ab5fab6d4 Mon Sep 17 00:00:00 2001 From: Michael Hoffman Date: Mon, 13 Jan 2025 09:01:12 -0500 Subject: [PATCH 03/16] Partial testing for view --- pkg/cmd/repo/autolink/view/view_test.go | 193 ++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 pkg/cmd/repo/autolink/view/view_test.go diff --git a/pkg/cmd/repo/autolink/view/view_test.go b/pkg/cmd/repo/autolink/view/view_test.go new file mode 100644 index 000000000..4ace02ea5 --- /dev/null +++ b/pkg/cmd/repo/autolink/view/view_test.go @@ -0,0 +1,193 @@ +package view + +import ( + "bytes" + "net/http" + "testing" + + "github.com/MakeNowJust/heredoc" + "github.com/cli/cli/v2/internal/browser" + "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/pkg/cmd/repo/autolink/domain" + "github.com/cli/cli/v2/pkg/cmdutil" + "github.com/cli/cli/v2/pkg/iostreams" + "github.com/cli/cli/v2/pkg/jsonfieldstest" + "github.com/google/shlex" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestJSONFields(t *testing.T) { + jsonfieldstest.ExpectCommandToSupportJSONFields(t, NewCmdView, []string{ + "id", + "isAlphanumeric", + "keyPrefix", + "urlTemplate", + }) +} + +func TestNewCmdView(t *testing.T) { + tests := []struct { + name string + input string + output viewOptions + wantErr bool + wantExporter bool + errMsg string + }{ + { + name: "no argument", + input: "", + wantErr: true, + errMsg: "accepts 1 arg(s), received 0", + }, + { + name: "id provided", + input: "123", + output: viewOptions{ID: "123"}, + }, + { + name: "json flag", + input: "123 --json id", + output: viewOptions{}, + wantExporter: true, + }, + { + name: "invalid json flag", + input: "123 --json invalid", + output: viewOptions{}, + wantErr: true, + errMsg: "Unknown JSON field: \"invalid\"\nAvailable fields:\n id\n isAlphanumeric\n keyPrefix\n urlTemplate", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ios, _, _, _ := iostreams.Test() + f := &cmdutil.Factory{ + IOStreams: ios, + } + f.HttpClient = func() (*http.Client, error) { + return &http.Client{}, nil + } + + argv, err := shlex.Split(tt.input) + require.NoError(t, err) + + var gotOpts *viewOptions + cmd := NewCmdView(f, func(opts *viewOptions) error { + gotOpts = opts + return nil + }) + + cmd.SetArgs(argv) + cmd.SetIn(&bytes.Buffer{}) + cmd.SetOut(&bytes.Buffer{}) + cmd.SetErr(&bytes.Buffer{}) + + _, err = cmd.ExecuteC() + if tt.wantErr { + require.EqualError(t, err, tt.errMsg) + } else { + require.NoError(t, err) + assert.Equal(t, tt.wantExporter, gotOpts.Exporter != nil) + } + }) + } +} + +type stubAutoLinkViewer struct { + autolink *domain.Autolink + err error +} + +func (g stubAutoLinkViewer) View(repo ghrepo.Interface, id string) (*domain.Autolink, error) { + return g.autolink, g.err +} + +type testAutolinkClientViewError struct{} + +func (e testAutolinkClientViewError) Error() string { + return "autolink client view error" +} + +func TestViewRun(t *testing.T) { + tests := []struct { + name string + opts *viewOptions + stubViewer stubAutoLinkViewer + expectedErr error + wantStdout string + wantStderr string + }{ + { + name: "view", + opts: &viewOptions{ + ID: "1", + }, + stubViewer: stubAutoLinkViewer{ + autolink: &domain.Autolink{ + ID: 1, + KeyPrefix: "TICKET-", + URLTemplate: "https://example.com/TICKET?query=", + IsAlphanumeric: true, + }, + }, + wantStdout: heredoc.Doc(` + Autolink in OWNER/REPO + + ID: 1 + Key Prefix: TICKET- + URL Template: https://example.com/TICKET?query= + Alphanumeric: true + `), + }, + { + name: "view json", + opts: &viewOptions{ + Exporter: func() cmdutil.Exporter { + exporter := cmdutil.NewJSONExporter() + exporter.SetFields([]string{"id"}) + return exporter + }(), + }, + stubViewer: stubAutoLinkViewer{ + autolink: &domain.Autolink{ + ID: 1, + KeyPrefix: "TICKET-", + URLTemplate: "https://example.com/TICKET?query=", + IsAlphanumeric: true, + }, + }, + wantStdout: "{\"id\":1}\n", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ios, _, stdout, stderr := iostreams.Test() + + opts := tt.opts + opts.IO = ios + opts.Browser = &browser.Stub{} + + opts.IO = ios + opts.BaseRepo = func() (ghrepo.Interface, error) { return ghrepo.New("OWNER", "REPO"), nil } + + opts.AutolinkClient = &tt.stubViewer + err := viewRun(opts) + + if tt.expectedErr != nil { + require.Error(t, err) + require.ErrorIs(t, err, tt.expectedErr) + } else { + require.NoError(t, err) + assert.Equal(t, tt.wantStdout, stdout.String()) + } + + if tt.wantStderr != "" { + assert.Equal(t, tt.wantStderr, stderr.String()) + } + }) + } +} From 11ce0c661c494fd3ef356a6de4f898934802b48e Mon Sep 17 00:00:00 2001 From: Michael Hoffman Date: Mon, 13 Jan 2025 09:10:12 -0500 Subject: [PATCH 04/16] Updates following renaming domain to shared --- pkg/cmd/repo/autolink/list/list.go | 2 +- pkg/cmd/repo/autolink/view/http.go | 6 +++--- pkg/cmd/repo/autolink/view/view.go | 6 +++--- pkg/cmd/repo/autolink/view/view_test.go | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/cmd/repo/autolink/list/list.go b/pkg/cmd/repo/autolink/list/list.go index 74267e7a4..123c5321e 100644 --- a/pkg/cmd/repo/autolink/list/list.go +++ b/pkg/cmd/repo/autolink/list/list.go @@ -63,7 +63,7 @@ func NewCmdList(f *cmdutil.Factory, runF func(*listOptions) error) *cobra.Comman } cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "List autolink references in the web browser") - cmdutil.AddJSONFlags(cmd, &opts.Exporter, domain.AutolinkFields) + cmdutil.AddJSONFlags(cmd, &opts.Exporter, shared.AutolinkFields) return cmd } diff --git a/pkg/cmd/repo/autolink/view/http.go b/pkg/cmd/repo/autolink/view/http.go index d3fdfc86a..ddba23f6d 100644 --- a/pkg/cmd/repo/autolink/view/http.go +++ b/pkg/cmd/repo/autolink/view/http.go @@ -8,14 +8,14 @@ import ( "github.com/cli/cli/v2/api" "github.com/cli/cli/v2/internal/ghinstance" "github.com/cli/cli/v2/internal/ghrepo" - "github.com/cli/cli/v2/pkg/cmd/repo/autolink/domain" + "github.com/cli/cli/v2/pkg/cmd/repo/autolink/shared" ) type AutolinkViewer struct { HTTPClient *http.Client } -func (a *AutolinkViewer) View(repo ghrepo.Interface, id string) (*domain.Autolink, error) { +func (a *AutolinkViewer) View(repo ghrepo.Interface, id string) (*shared.Autolink, error) { path := fmt.Sprintf("repos/%s/%s/autolinks/%s", repo.RepoOwner(), repo.RepoName(), id) url := ghinstance.RESTPrefix(repo.RepoHost()) + path req, err := http.NewRequest(http.MethodGet, url, nil) @@ -35,7 +35,7 @@ func (a *AutolinkViewer) View(repo ghrepo.Interface, id string) (*domain.Autolin return nil, api.HandleHTTPError(resp) } - var autolink domain.Autolink + var autolink shared.Autolink err = json.NewDecoder(resp.Body).Decode(&autolink) if err != nil { diff --git a/pkg/cmd/repo/autolink/view/view.go b/pkg/cmd/repo/autolink/view/view.go index 2d0cfd6c6..38a2590a2 100644 --- a/pkg/cmd/repo/autolink/view/view.go +++ b/pkg/cmd/repo/autolink/view/view.go @@ -6,7 +6,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/ghrepo" - "github.com/cli/cli/v2/pkg/cmd/repo/autolink/domain" + "github.com/cli/cli/v2/pkg/cmd/repo/autolink/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/spf13/cobra" @@ -23,7 +23,7 @@ type viewOptions struct { } type AutolinkViewClient interface { - View(repo ghrepo.Interface, id string) (*domain.Autolink, error) + View(repo ghrepo.Interface, id string) (*shared.Autolink, error) } func NewCmdView(f *cmdutil.Factory, runF func(*viewOptions) error) *cobra.Command { @@ -65,7 +65,7 @@ func NewCmdView(f *cmdutil.Factory, runF func(*viewOptions) error) *cobra.Comman }, } - cmdutil.AddJSONFlags(cmd, &opts.Exporter, domain.AutolinkFields) + cmdutil.AddJSONFlags(cmd, &opts.Exporter, shared.AutolinkFields) return cmd } diff --git a/pkg/cmd/repo/autolink/view/view_test.go b/pkg/cmd/repo/autolink/view/view_test.go index 4ace02ea5..849a2828a 100644 --- a/pkg/cmd/repo/autolink/view/view_test.go +++ b/pkg/cmd/repo/autolink/view/view_test.go @@ -8,7 +8,7 @@ import ( "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/ghrepo" - "github.com/cli/cli/v2/pkg/cmd/repo/autolink/domain" + "github.com/cli/cli/v2/pkg/cmd/repo/autolink/shared" "github.com/cli/cli/v2/pkg/cmdutil" "github.com/cli/cli/v2/pkg/iostreams" "github.com/cli/cli/v2/pkg/jsonfieldstest" @@ -97,11 +97,11 @@ func TestNewCmdView(t *testing.T) { } type stubAutoLinkViewer struct { - autolink *domain.Autolink + autolink *shared.Autolink err error } -func (g stubAutoLinkViewer) View(repo ghrepo.Interface, id string) (*domain.Autolink, error) { +func (g stubAutoLinkViewer) View(repo ghrepo.Interface, id string) (*shared.Autolink, error) { return g.autolink, g.err } @@ -126,7 +126,7 @@ func TestViewRun(t *testing.T) { ID: "1", }, stubViewer: stubAutoLinkViewer{ - autolink: &domain.Autolink{ + autolink: &shared.Autolink{ ID: 1, KeyPrefix: "TICKET-", URLTemplate: "https://example.com/TICKET?query=", @@ -152,7 +152,7 @@ func TestViewRun(t *testing.T) { }(), }, stubViewer: stubAutoLinkViewer{ - autolink: &domain.Autolink{ + autolink: &shared.Autolink{ ID: 1, KeyPrefix: "TICKET-", URLTemplate: "https://example.com/TICKET?query=", From 58d84a4088a8cff75414dc4ce6129d3dcb6224bb Mon Sep 17 00:00:00 2001 From: Michael Hoffman Date: Tue, 28 Jan 2025 12:03:03 -0500 Subject: [PATCH 05/16] Shorten description --- pkg/cmd/repo/autolink/view/view.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/cmd/repo/autolink/view/view.go b/pkg/cmd/repo/autolink/view/view.go index 38a2590a2..064fc22ca 100644 --- a/pkg/cmd/repo/autolink/view/view.go +++ b/pkg/cmd/repo/autolink/view/view.go @@ -35,12 +35,8 @@ func NewCmdView(f *cmdutil.Factory, runF func(*viewOptions) error) *cobra.Comman cmd := &cobra.Command{ Use: "view ", Short: "View an autolink reference", - Long: heredoc.Docf(` - View an autolink reference for a repository. - - Information about autolinks is only available to repository administrators. - `), - Args: cobra.ExactArgs(1), + Long: "View an autolink reference for a repository.", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.BaseRepo = f.BaseRepo httpClient, err := f.HttpClient() From 32ee4db48444c8ee0229a0e90056cf50f6128ca5 Mon Sep 17 00:00:00 2001 From: Michael Hoffman Date: Tue, 28 Jan 2025 13:33:50 -0500 Subject: [PATCH 06/16] Autolink view HTTP tests --- pkg/cmd/repo/autolink/list/http_test.go | 2 +- pkg/cmd/repo/autolink/view/http.go | 1 - pkg/cmd/repo/autolink/view/http_test.go | 86 +++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 pkg/cmd/repo/autolink/view/http_test.go diff --git a/pkg/cmd/repo/autolink/list/http_test.go b/pkg/cmd/repo/autolink/list/http_test.go index 0fa918f61..65289c419 100644 --- a/pkg/cmd/repo/autolink/list/http_test.go +++ b/pkg/cmd/repo/autolink/list/http_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestAutoLinkLister_List(t *testing.T) { +func TestAutolinkLister_List(t *testing.T) { tests := []struct { name string repo ghrepo.Interface diff --git a/pkg/cmd/repo/autolink/view/http.go b/pkg/cmd/repo/autolink/view/http.go index ddba23f6d..8dd6dc12d 100644 --- a/pkg/cmd/repo/autolink/view/http.go +++ b/pkg/cmd/repo/autolink/view/http.go @@ -39,7 +39,6 @@ func (a *AutolinkViewer) View(repo ghrepo.Interface, id string) (*shared.Autolin err = json.NewDecoder(resp.Body).Decode(&autolink) if err != nil { - fmt.Println(err.Error()) return nil, err } diff --git a/pkg/cmd/repo/autolink/view/http_test.go b/pkg/cmd/repo/autolink/view/http_test.go new file mode 100644 index 000000000..5475c1f8a --- /dev/null +++ b/pkg/cmd/repo/autolink/view/http_test.go @@ -0,0 +1,86 @@ +package view + +import ( + "fmt" + "net/http" + "testing" + + "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/pkg/cmd/repo/autolink/shared" + "github.com/cli/cli/v2/pkg/httpmock" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestAutolinkViewer_View(t *testing.T) { + repo := ghrepo.New("OWNER", "REPO") + testAutolink := shared.Autolink{ + ID: 123, + KeyPrefix: "TICKET-", + URLTemplate: "https://example.com/TICKET?query=", + IsAlphanumeric: true, + } + + tests := []struct { + name string + id string + stubStatus int + stubRespJSON string + + expectedAutolink *shared.Autolink + expectErr bool + expectedErrMsg string + }{ + { + name: "200 successful view", + id: "123", + stubStatus: 200, + stubRespJSON: `{ + "id": 123, + "key_prefix": "TICKET-", + "url_template": "https://example.com/TICKET?query=", + "is_alphanumeric": true + }`, + expectedAutolink: &testAutolink, + }, + { + name: "404 repo or autolink not found", + id: "123", + stubStatus: 404, + stubRespJSON: `{ + "message": "Not Found", + "documentation_url": "https://docs.github.com/rest/repos/autolinks#get-an-autolink-reference-of-a-repository", + "status": "404" + }`, + expectErr: true, + expectedErrMsg: "HTTP 404: Either no autolink with this ID exists for this repository or you are missing admin rights to the repository. (https://api.github.com/repos/OWNER/REPO/autolinks/123)", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + reg := &httpmock.Registry{} + reg.Register( + httpmock.REST( + http.MethodGet, + fmt.Sprintf("repos/%s/%s/autolinks/%s", repo.RepoOwner(), repo.RepoName(), tt.id), + ), + httpmock.StatusStringResponse(tt.stubStatus, tt.stubRespJSON), + ) + defer reg.Verify(t) + + autolinkCreator := &AutolinkViewer{ + HTTPClient: &http.Client{Transport: reg}, + } + + autolink, err := autolinkCreator.View(repo, tt.id) + + if tt.expectErr { + require.EqualError(t, err, tt.expectedErrMsg) + } else { + require.NoError(t, err) + assert.Equal(t, tt.expectedAutolink, autolink) + } + }) + } +} From 8f55dbcf61dcda17653a2cb7755a2cf0097a8ac9 Mon Sep 17 00:00:00 2001 From: Michael Hoffman Date: Tue, 28 Jan 2025 14:07:48 -0500 Subject: [PATCH 07/16] Error case test for viewRun --- pkg/cmd/repo/autolink/view/view_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/cmd/repo/autolink/view/view_test.go b/pkg/cmd/repo/autolink/view/view_test.go index 849a2828a..3951d0cca 100644 --- a/pkg/cmd/repo/autolink/view/view_test.go +++ b/pkg/cmd/repo/autolink/view/view_test.go @@ -161,6 +161,16 @@ func TestViewRun(t *testing.T) { }, wantStdout: "{\"id\":1}\n", }, + { + name: "client error", + opts: &viewOptions{}, + stubViewer: stubAutoLinkViewer{ + autolink: nil, + err: testAutolinkClientViewError{}, + }, + expectedErr: testAutolinkClientViewError{}, + wantStderr: "", + }, } for _, tt := range tests { From 8b7d6d1b3f6a36f00b46af2bd53b83783a735be0 Mon Sep 17 00:00:00 2001 From: Michael Hoffman Date: Wed, 29 Jan 2025 09:34:29 -0500 Subject: [PATCH 08/16] Remove unused test field --- pkg/cmd/repo/autolink/view/view_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pkg/cmd/repo/autolink/view/view_test.go b/pkg/cmd/repo/autolink/view/view_test.go index 3951d0cca..f66901f59 100644 --- a/pkg/cmd/repo/autolink/view/view_test.go +++ b/pkg/cmd/repo/autolink/view/view_test.go @@ -118,7 +118,6 @@ func TestViewRun(t *testing.T) { stubViewer stubAutoLinkViewer expectedErr error wantStdout string - wantStderr string }{ { name: "view", @@ -169,7 +168,6 @@ func TestViewRun(t *testing.T) { err: testAutolinkClientViewError{}, }, expectedErr: testAutolinkClientViewError{}, - wantStderr: "", }, } @@ -194,10 +192,6 @@ func TestViewRun(t *testing.T) { require.NoError(t, err) assert.Equal(t, tt.wantStdout, stdout.String()) } - - if tt.wantStderr != "" { - assert.Equal(t, tt.wantStderr, stderr.String()) - } }) } } From 21a5267be4405bf059a359a434d31ecb3a3d66a0 Mon Sep 17 00:00:00 2001 From: Michael Hoffman Date: Wed, 29 Jan 2025 09:35:05 -0500 Subject: [PATCH 09/16] Remove unused test field --- pkg/cmd/repo/autolink/view/view_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/repo/autolink/view/view_test.go b/pkg/cmd/repo/autolink/view/view_test.go index f66901f59..bc0a1bf7f 100644 --- a/pkg/cmd/repo/autolink/view/view_test.go +++ b/pkg/cmd/repo/autolink/view/view_test.go @@ -173,7 +173,7 @@ func TestViewRun(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - ios, _, stdout, stderr := iostreams.Test() + ios, _, stdout, _ := iostreams.Test() opts := tt.opts opts.IO = ios @@ -187,7 +187,7 @@ func TestViewRun(t *testing.T) { if tt.expectedErr != nil { require.Error(t, err) - require.ErrorIs(t, err, tt.expectedErr) + assert.ErrorIs(t, err, tt.expectedErr) } else { require.NoError(t, err) assert.Equal(t, tt.wantStdout, stdout.String()) From af538b277d8be77f6cf8e9de0c74469a26f82a1d Mon Sep 17 00:00:00 2001 From: Andy Feller Date: Wed, 29 Jan 2025 10:10:42 -0500 Subject: [PATCH 10/16] Expand test case - add autolink view case for numeric - simplifying local variable usage --- pkg/cmd/repo/autolink/view/http_test.go | 32 ++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/pkg/cmd/repo/autolink/view/http_test.go b/pkg/cmd/repo/autolink/view/http_test.go index 5475c1f8a..2402fb2d7 100644 --- a/pkg/cmd/repo/autolink/view/http_test.go +++ b/pkg/cmd/repo/autolink/view/http_test.go @@ -14,12 +14,6 @@ import ( func TestAutolinkViewer_View(t *testing.T) { repo := ghrepo.New("OWNER", "REPO") - testAutolink := shared.Autolink{ - ID: 123, - KeyPrefix: "TICKET-", - URLTemplate: "https://example.com/TICKET?query=", - IsAlphanumeric: true, - } tests := []struct { name string @@ -32,7 +26,7 @@ func TestAutolinkViewer_View(t *testing.T) { expectedErrMsg string }{ { - name: "200 successful view", + name: "200 successful alphanumeric view", id: "123", stubStatus: 200, stubRespJSON: `{ @@ -41,7 +35,29 @@ func TestAutolinkViewer_View(t *testing.T) { "url_template": "https://example.com/TICKET?query=", "is_alphanumeric": true }`, - expectedAutolink: &testAutolink, + expectedAutolink: &shared.Autolink{ + ID: 123, + KeyPrefix: "TICKET-", + URLTemplate: "https://example.com/TICKET?query=", + IsAlphanumeric: true, + }, + }, + { + name: "200 successful numeric view", + id: "124", + stubStatus: 200, + stubRespJSON: `{ + "id": 124, + "key_prefix": "TICKET-", + "url_template": "https://example.com/TICKET?query=", + "is_alphanumeric": false + }`, + expectedAutolink: &shared.Autolink{ + ID: 124, + KeyPrefix: "TICKET-", + URLTemplate: "https://example.com/TICKET?query=", + IsAlphanumeric: false, + }, }, { name: "404 repo or autolink not found", From fe21e10ae8b42315575fe03f24ec967f4c65fab3 Mon Sep 17 00:00:00 2001 From: Andy Feller Date: Wed, 29 Jan 2025 10:16:02 -0500 Subject: [PATCH 11/16] Keeping autolink IDs the same in all test cases --- pkg/cmd/repo/autolink/view/http_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/repo/autolink/view/http_test.go b/pkg/cmd/repo/autolink/view/http_test.go index 2402fb2d7..5bfe9369f 100644 --- a/pkg/cmd/repo/autolink/view/http_test.go +++ b/pkg/cmd/repo/autolink/view/http_test.go @@ -44,16 +44,16 @@ func TestAutolinkViewer_View(t *testing.T) { }, { name: "200 successful numeric view", - id: "124", + id: "123", stubStatus: 200, stubRespJSON: `{ - "id": 124, + "id": 123, "key_prefix": "TICKET-", "url_template": "https://example.com/TICKET?query=", "is_alphanumeric": false }`, expectedAutolink: &shared.Autolink{ - ID: 124, + ID: 123, KeyPrefix: "TICKET-", URLTemplate: "https://example.com/TICKET?query=", IsAlphanumeric: false, From e4d720ba228d8c4221049ca30e14b05a4dc30c17 Mon Sep 17 00:00:00 2001 From: Michael Hoffman Date: Wed, 29 Jan 2025 11:12:28 -0500 Subject: [PATCH 12/16] Remove redundant error check --- pkg/cmd/repo/autolink/view/view.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pkg/cmd/repo/autolink/view/view.go b/pkg/cmd/repo/autolink/view/view.go index 064fc22ca..f892c0724 100644 --- a/pkg/cmd/repo/autolink/view/view.go +++ b/pkg/cmd/repo/autolink/view/view.go @@ -38,19 +38,13 @@ func NewCmdView(f *cmdutil.Factory, runF func(*viewOptions) error) *cobra.Comman Long: "View an autolink reference for a repository.", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - opts.BaseRepo = f.BaseRepo httpClient, err := f.HttpClient() - if err != nil { return err } + opts.BaseRepo = f.BaseRepo opts.ID = args[0] - - if err != nil { - return err - } - opts.AutolinkClient = &AutolinkViewer{HTTPClient: httpClient} if runF != nil { From b23cf6e8d768d9a929950c8c33eff780af79272b Mon Sep 17 00:00:00 2001 From: Michael Hoffman Date: Wed, 29 Jan 2025 16:24:47 -0500 Subject: [PATCH 13/16] Update formatting for autolink output --- pkg/cmd/repo/autolink/create/create.go | 4 ++-- pkg/cmd/repo/autolink/list/list.go | 4 +++- pkg/cmd/repo/autolink/view/view.go | 29 +++++++++++++------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/pkg/cmd/repo/autolink/create/create.go b/pkg/cmd/repo/autolink/create/create.go index ac3035c79..aad71a941 100644 --- a/pkg/cmd/repo/autolink/create/create.go +++ b/pkg/cmd/repo/autolink/create/create.go @@ -109,9 +109,9 @@ func createRun(opts *createOptions) error { cs := opts.IO.ColorScheme() fmt.Fprintf(opts.IO.Out, - "%s Created repository autolink %d on %s\n", + "%s Created repository autolink %s on %s\n", cs.SuccessIconWithColor(cs.Green), - autolink.ID, + cs.Cyanf("%d", autolink.ID), ghrepo.FullName(repo)) return nil diff --git a/pkg/cmd/repo/autolink/list/list.go b/pkg/cmd/repo/autolink/list/list.go index 123c5321e..402479c44 100644 --- a/pkg/cmd/repo/autolink/list/list.go +++ b/pkg/cmd/repo/autolink/list/list.go @@ -104,8 +104,10 @@ func listRun(opts *listOptions) error { tp := tableprinter.New(opts.IO, tableprinter.WithHeader("ID", "KEY PREFIX", "URL TEMPLATE", "ALPHANUMERIC")) + cs := opts.IO.ColorScheme() + for _, autolink := range autolinks { - tp.AddField(fmt.Sprintf("%d", autolink.ID)) + tp.AddField(cs.Cyanf("%d", autolink.ID)) tp.AddField(autolink.KeyPrefix) tp.AddField(autolink.URLTemplate) tp.AddField(strconv.FormatBool(autolink.IsAlphanumeric)) diff --git a/pkg/cmd/repo/autolink/view/view.go b/pkg/cmd/repo/autolink/view/view.go index f892c0724..0b212aece 100644 --- a/pkg/cmd/repo/autolink/view/view.go +++ b/pkg/cmd/repo/autolink/view/view.go @@ -3,7 +3,6 @@ package view import ( "fmt" - "github.com/MakeNowJust/heredoc" "github.com/cli/cli/v2/internal/browser" "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/cmd/repo/autolink/shared" @@ -65,6 +64,8 @@ func viewRun(opts *viewOptions) error { if err != nil { return err } + + out := opts.IO.Out cs := opts.IO.ColorScheme() autolink, err := opts.AutolinkClient.View(repo, opts.ID) @@ -77,21 +78,19 @@ func viewRun(opts *viewOptions) error { return opts.Exporter.Write(opts.IO, autolink) } - msg := heredoc.Docf(` - Autolink in %s + fmt.Fprintf(out, "Autolink in %s\n\n", ghrepo.FullName(repo)) - ID: %d - Key Prefix: %s - URL Template: %s - Alphanumeric: %t - `, - ghrepo.FullName(repo), - autolink.ID, - autolink.KeyPrefix, - autolink.URLTemplate, - autolink.IsAlphanumeric, - ) - fmt.Fprint(opts.IO.Out, msg) + fmt.Fprint(out, cs.Bold("ID: ")) + fmt.Fprintln(out, cs.Cyanf("%d", autolink.ID)) + + fmt.Fprint(out, cs.Bold("Key Prefix: ")) + fmt.Fprintln(out, autolink.KeyPrefix) + + fmt.Fprint(out, cs.Bold("URL Template: ")) + fmt.Fprintln(out, autolink.URLTemplate) + + fmt.Fprint(out, cs.Bold("Alphanumeric: ")) + fmt.Fprintln(out, autolink.IsAlphanumeric) return nil } From ddb8855198ea7a5bc9547e205dbfda8b7b5f1b80 Mon Sep 17 00:00:00 2001 From: Meredith Lancaster Date: Thu, 30 Jan 2025 09:12:48 -0700 Subject: [PATCH 14/16] flip bundle fetching logic Signed-off-by: Meredith Lancaster --- pkg/cmd/attestation/api/client.go | 24 ++++++++++++------------ pkg/cmd/attestation/api/client_test.go | 8 ++++++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pkg/cmd/attestation/api/client.go b/pkg/cmd/attestation/api/client.go index 37579b7bc..746b04411 100644 --- a/pkg/cmd/attestation/api/client.go +++ b/pkg/cmd/attestation/api/client.go @@ -176,23 +176,23 @@ func (c *LiveClient) fetchBundleFromAttestations(attestations []*Attestation) ([ return fmt.Errorf("attestation has no bundle or bundle URL") } - // for now, we fallback to the bundle field if the bundle URL is empty - if a.BundleURL == "" { - c.logger.VerbosePrintf("Bundle URL is empty. Falling back to bundle field\n\n") - fetched[i] = &Attestation{ - Bundle: a.Bundle, + // If the bundle field is nil, try to fetch the bundle with the provided URL + if a.Bundle == nil { + b, err := c.GetBundle(a.BundleURL) + if err != nil { + return fmt.Errorf("failed to fetch bundle with URL: %w", err) + } + fetched[i] = &Attestation{ + Bundle: b, } - return nil } - // otherwise fetch the bundle with the provided URL - b, err := c.GetBundle(a.BundleURL) - if err != nil { - return fmt.Errorf("failed to fetch bundle with URL: %w", err) - } + // otherwise fall back to the bundle field + c.logger.VerbosePrintf("Bundle URL is empty. Falling back to bundle field\n\n") fetched[i] = &Attestation{ - Bundle: b, + Bundle: a.Bundle, } + return nil }) } diff --git a/pkg/cmd/attestation/api/client_test.go b/pkg/cmd/attestation/api/client_test.go index 65f8d59ca..083a5c5c8 100644 --- a/pkg/cmd/attestation/api/client_test.go +++ b/pkg/cmd/attestation/api/client_test.go @@ -180,7 +180,7 @@ func TestGetByDigest_Error(t *testing.T) { require.Nil(t, attestations) } -func TestFetchBundleFromAttestations(t *testing.T) { +func TestFetchBundleFromAttestations_Fallback_Bundle_Field(t *testing.T) { httpClient := &mockHttpClient{} client := LiveClient{ httpClient: httpClient, @@ -194,7 +194,7 @@ func TestFetchBundleFromAttestations(t *testing.T) { require.NoError(t, err) require.Len(t, fetched, 2) require.Equal(t, "application/vnd.dev.sigstore.bundle.v0.3+json", fetched[0].Bundle.GetMediaType()) - httpClient.AssertNumberOfCalls(t, "OnGetSuccess", 2) + httpClient.AssertNumberOfCalls(t, "OnGetSuccess", 0) } func TestFetchBundleFromAttestations_InvalidAttestation(t *testing.T) { @@ -220,7 +220,10 @@ func TestFetchBundleFromAttestations_Fail(t *testing.T) { } att1 := makeTestAttestation() + att1.Bundle = nil att2 := makeTestAttestation() + att2.Bundle = nil + // zero out the bundle field so it tries fetching by URL attestations := []*Attestation{&att1, &att2} fetched, err := c.fetchBundleFromAttestations(attestations) require.Error(t, err) @@ -237,6 +240,7 @@ func TestFetchBundleFromAttestations_FetchByURLFail(t *testing.T) { } a := makeTestAttestation() + a.Bundle = nil attestations := []*Attestation{&a} bundle, err := c.fetchBundleFromAttestations(attestations) require.Error(t, err) From 70ae9f39ef3668bab984a77be34b2ec3be4162b5 Mon Sep 17 00:00:00 2001 From: Meredith Lancaster Date: Thu, 30 Jan 2025 09:26:41 -0700 Subject: [PATCH 15/16] update tests to account for logic flip Signed-off-by: Meredith Lancaster --- pkg/cmd/attestation/api/client.go | 4 +++- pkg/cmd/attestation/api/client_test.go | 11 +++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/attestation/api/client.go b/pkg/cmd/attestation/api/client.go index 746b04411..6054bc98e 100644 --- a/pkg/cmd/attestation/api/client.go +++ b/pkg/cmd/attestation/api/client.go @@ -178,6 +178,7 @@ func (c *LiveClient) fetchBundleFromAttestations(attestations []*Attestation) ([ // If the bundle field is nil, try to fetch the bundle with the provided URL if a.Bundle == nil { + c.logger.VerbosePrintf("Bundle field is empty. Trying to fetch with bundle URL\n\n") b, err := c.GetBundle(a.BundleURL) if err != nil { return fmt.Errorf("failed to fetch bundle with URL: %w", err) @@ -185,10 +186,11 @@ func (c *LiveClient) fetchBundleFromAttestations(attestations []*Attestation) ([ fetched[i] = &Attestation{ Bundle: b, } + return nil } // otherwise fall back to the bundle field - c.logger.VerbosePrintf("Bundle URL is empty. Falling back to bundle field\n\n") + c.logger.VerbosePrintf("Fetching bundle from Bundle field\n\n") fetched[i] = &Attestation{ Bundle: a.Bundle, } diff --git a/pkg/cmd/attestation/api/client_test.go b/pkg/cmd/attestation/api/client_test.go index 083a5c5c8..3d180af8f 100644 --- a/pkg/cmd/attestation/api/client_test.go +++ b/pkg/cmd/attestation/api/client_test.go @@ -180,7 +180,7 @@ func TestGetByDigest_Error(t *testing.T) { require.Nil(t, attestations) } -func TestFetchBundleFromAttestations_Fallback_Bundle_Field(t *testing.T) { +func TestFetchBundleFromAttestations_BundleURL(t *testing.T) { httpClient := &mockHttpClient{} client := LiveClient{ httpClient: httpClient, @@ -188,13 +188,16 @@ func TestFetchBundleFromAttestations_Fallback_Bundle_Field(t *testing.T) { } att1 := makeTestAttestation() + att1.Bundle = nil att2 := makeTestAttestation() + att2.Bundle = nil + // zero out the bundle field so it tries fetching by URL attestations := []*Attestation{&att1, &att2} fetched, err := client.fetchBundleFromAttestations(attestations) require.NoError(t, err) require.Len(t, fetched, 2) - require.Equal(t, "application/vnd.dev.sigstore.bundle.v0.3+json", fetched[0].Bundle.GetMediaType()) - httpClient.AssertNumberOfCalls(t, "OnGetSuccess", 0) + require.NotNil(t, "application/vnd.dev.sigstore.bundle.v0.3+json", fetched[0].Bundle.GetMediaType()) + httpClient.AssertNumberOfCalls(t, "OnGetSuccess", 2) } func TestFetchBundleFromAttestations_InvalidAttestation(t *testing.T) { @@ -211,7 +214,7 @@ func TestFetchBundleFromAttestations_InvalidAttestation(t *testing.T) { require.Nil(t, fetched, 2) } -func TestFetchBundleFromAttestations_Fail(t *testing.T) { +func TestFetchBundleFromAttestations_Fail_BundleURL(t *testing.T) { httpClient := &failAfterOneCallHttpClient{} c := &LiveClient{ From df250a2b538e2860f41b2b370361f291c687407f Mon Sep 17 00:00:00 2001 From: Andy Feller Date: Thu, 30 Jan 2025 13:07:21 -0500 Subject: [PATCH 16/16] Update deployment.yml Fix failing tag validate job --- .github/workflows/deployment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 31cd4b8e7..efc729711 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -33,7 +33,7 @@ jobs: steps: - name: Validate tag name format run: | - if [[ ! "${{ inputs.tag_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$]]; then + if [[ ! "${{ inputs.tag_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "Invalid tag name format. Must be in the form v1.2.3" exit 1 fi