From 7bdb79cc6b7fd17f8578862769437c69b27b1091 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 13:57:20 -0500 Subject: [PATCH 01/17] chore: delete legacy events fields: --- action/repo/table.go | 39 ++-------------------------------- action/repo/table_test.go | 24 +++++++++++---------- action/secret/add.go | 7 +++--- action/secret/secret.go | 2 +- action/secret/table.go | 2 +- action/secret/table_test.go | 4 +++- action/secret/update.go | 7 +++--- action/secret/validate.go | 2 +- action/secret/validate_test.go | 36 +++++++++++++++---------------- command/secret/add.go | 24 ++++++++++----------- command/secret/update.go | 24 ++++++++++----------- go.mod | 11 ++++++---- go.sum | 22 ++++++++++++------- 13 files changed, 90 insertions(+), 114 deletions(-) diff --git a/action/repo/table.go b/action/repo/table.go index 79fdc683..f093a514 100644 --- a/action/repo/table.go +++ b/action/repo/table.go @@ -7,7 +7,6 @@ import ( "github.com/go-vela/cli/internal/output" - "github.com/go-vela/types/constants" "github.com/go-vela/types/library" "github.com/gosuri/uitable" @@ -48,7 +47,7 @@ func table(repos *[]library.Repo) error { logrus.Tracef("adding repo %s to repo table", r.GetFullName()) //nolint:gosec // ignore memory aliasing - e := strings.Join(events(&r), ",") + e := strings.Join(r.AllowEvents.List(), ",") // add a row to the table with the specified values // @@ -95,7 +94,7 @@ func wideTable(repos *[]library.Repo) error { logrus.Tracef("adding repo %s to wide repo table", r.GetFullName()) //nolint:gosec // ignore memory aliasing - e := strings.Join(events(&r), ",") + e := strings.Join(r.AllowEvents.List(), ",") // add a row to the table with the specified values // @@ -108,37 +107,3 @@ func wideTable(repos *[]library.Repo) error { // https://pkg.go.dev/github.com/go-vela/cli/internal/output?tab=doc#Stdout return output.Stdout(table) } - -// events is a helper function to output -// the event types a repo is configured -// to trigger builds off of. -func events(r *library.Repo) []string { - e := []string{} - - // check if the repository allows comment events - if r.GetAllowComment() { - e = append(e, constants.EventComment) - } - - // check if the repository allows deployment events - if r.GetAllowDeploy() { - e = append(e, constants.EventDeploy) - } - - // check if the repository allows pull_request events - if r.GetAllowPull() { - e = append(e, constants.EventPull) - } - - // check if the repository allows push events - if r.GetAllowPush() { - e = append(e, constants.EventPush) - } - - // check if the repository allows tag events - if r.GetAllowTag() { - e = append(e, constants.EventTag) - } - - return e -} diff --git a/action/repo/table_test.go b/action/repo/table_test.go index c3748b1d..9edb0775 100644 --- a/action/repo/table_test.go +++ b/action/repo/table_test.go @@ -11,9 +11,9 @@ import ( func TestRepo_table(t *testing.T) { // setup types r1 := testRepo() - r1.SetAllowDeploy(true) - r1.SetAllowTag(true) - r1.SetAllowComment(true) + r1.GetAllowEvents().GetDeployment().SetCreated(true) + r1.GetAllowEvents().GetPush().SetTag(true) + r1.GetAllowEvents().GetComment().SetCreated(true) r2 := testRepo() r2.SetID(2) @@ -55,9 +55,9 @@ func TestRepo_table(t *testing.T) { func TestRepo_wideTable(t *testing.T) { // setup types r1 := testRepo() - r1.SetAllowDeploy(true) - r1.SetAllowTag(true) - r1.SetAllowComment(true) + r1.GetAllowEvents().GetDeployment().SetCreated(true) + r1.GetAllowEvents().GetPush().SetTag(true) + r1.GetAllowEvents().GetComment().SetCreated(true) r2 := testRepo() r2.SetID(2) @@ -113,11 +113,13 @@ func testRepo() *library.Repo { r.SetPrivate(false) r.SetTrusted(false) r.SetActive(true) - r.SetAllowPull(true) - r.SetAllowPush(true) - r.SetAllowDeploy(false) - r.SetAllowTag(false) - r.SetAllowComment(false) + r.GetAllowEvents().GetPullRequest().SetOpened(true) + r.GetAllowEvents().GetPullRequest().SetSynchronize(true) + r.GetAllowEvents().GetPullRequest().SetEdited(true) + r.GetAllowEvents().GetPush().SetBranch(true) + r.GetAllowEvents().GetDeployment().SetCreated(false) + r.GetAllowEvents().GetPush().SetTag(false) + r.GetAllowEvents().GetComment().SetCreated(false) return r } diff --git a/action/secret/add.go b/action/secret/add.go index 7f741b9e..eab22d87 100644 --- a/action/secret/add.go +++ b/action/secret/add.go @@ -57,14 +57,13 @@ func (c *Config) Add(client *vela.Client) error { Name: &c.Name, Value: &c.Value, Images: &c.Images, - Events: &c.Events, AllowCommand: c.AllowCommand, AllowSubstitution: c.AllowSubstitution, } // populate events if provided - if len(c.Events) > 0 { - s.SetAllowEvents(library.NewEventsFromSlice(c.Events)) + if len(c.AllowEvents) > 0 { + s.SetAllowEvents(library.NewEventsFromSlice(c.AllowEvents)) } logrus.Tracef("adding secret %s/%s/%s/%s/%s", c.Engine, c.Type, c.Org, name, c.Name) @@ -154,7 +153,7 @@ func (c *Config) AddFromFile(client *vela.Client) error { Name: s.GetName(), Value: s.GetValue(), Images: s.GetImages(), - Events: s.GetEvents(), + AllowEvents: s.GetAllowEvents().List(), AllowCommand: s.AllowCommand, AllowSubstitution: s.AllowSubstitution, Output: c.Output, diff --git a/action/secret/secret.go b/action/secret/secret.go index 9b8414ea..3733955b 100644 --- a/action/secret/secret.go +++ b/action/secret/secret.go @@ -22,7 +22,7 @@ type Config struct { Name string Value string Images []string - Events []string + AllowEvents []string AllowCommand *bool AllowSubstitution *bool File string diff --git a/action/secret/table.go b/action/secret/table.go index c3f802ff..849e4417 100644 --- a/action/secret/table.go +++ b/action/secret/table.go @@ -98,7 +98,7 @@ func wideTable(secrets *[]library.Secret) error { logrus.Tracef("adding secret %s to wide secret table", s.GetName()) // capture list of events for secret - e := strings.Join(s.GetEvents(), ",") + e := strings.Join(s.GetAllowEvents().List(), ",") // capture list of images for secret i := strings.Join(s.GetImages(), ",") diff --git a/action/secret/table_test.go b/action/secret/table_test.go index 82a6416a..6499b23d 100644 --- a/action/secret/table_test.go +++ b/action/secret/table_test.go @@ -117,7 +117,9 @@ func testSecret() *library.Secret { s.SetValue("bar") s.SetType("repo") s.SetImages([]string{"alpine"}) - s.SetEvents([]string{"push", "tag", "deployment"}) + s.GetAllowEvents().GetPush().SetBranch(true) + s.GetAllowEvents().GetDeployment().SetCreated(false) + s.GetAllowEvents().GetPush().SetTag(false) s.SetAllowCommand(true) s.SetAllowSubstitution(true) diff --git a/action/secret/update.go b/action/secret/update.go index 020677bd..7c580fd3 100644 --- a/action/secret/update.go +++ b/action/secret/update.go @@ -57,14 +57,13 @@ func (c *Config) Update(client *vela.Client) error { Name: &c.Name, Value: &c.Value, Images: &c.Images, - Events: &c.Events, AllowCommand: c.AllowCommand, AllowSubstitution: c.AllowSubstitution, } // populate events if provided - if len(c.Events) > 0 { - s.SetAllowEvents(library.NewEventsFromSlice(c.Events)) + if len(c.AllowEvents) > 0 { + s.SetAllowEvents(library.NewEventsFromSlice(c.AllowEvents)) } logrus.Tracef("modifying secret %s/%s/%s/%s/%s", c.Engine, c.Type, c.Org, name, c.Name) @@ -154,7 +153,7 @@ func (c *Config) UpdateFromFile(client *vela.Client) error { Name: s.GetName(), Value: s.GetValue(), Images: s.GetImages(), - Events: s.GetEvents(), + AllowEvents: s.GetAllowEvents().List(), AllowCommand: s.AllowCommand, AllowSubstitution: s.AllowSubstitution, Output: c.Output, diff --git a/action/secret/validate.go b/action/secret/validate.go index caac79df..b52264a8 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -83,7 +83,7 @@ func (c *Config) Validate() error { // check if secret action is add or update if c.Action == "add" || c.Action == "update" { // iterate through all secret events - for _, event := range c.Events { + for _, event := range c.AllowEvents { // check if the secret event provided is valid switch event { case constants.EventComment: diff --git a/action/secret/validate_test.go b/action/secret/validate_test.go index 37c4f7f6..83a251a5 100644 --- a/action/secret/validate_test.go +++ b/action/secret/validate_test.go @@ -94,29 +94,29 @@ func TestSecret_Config_Validate(t *testing.T) { { failure: false, config: &Config{ - Action: "add", - Engine: "native", - Type: "repo", - Org: "github", - Repo: "octocat", - Name: "foo", - Value: "bar", - Events: []string{"comment", "push", "pull_request", "tag", "deployment", "schedule"}, - Output: "", + Action: "add", + Engine: "native", + Type: "repo", + Org: "github", + Repo: "octocat", + Name: "foo", + Value: "bar", + AllowEvents: []string{"comment", "push", "pull_request", "tag", "deployment", "schedule"}, + Output: "", }, }, { failure: true, config: &Config{ - Action: "add", - Engine: "native", - Type: "repo", - Org: "github", - Repo: "octocat", - Name: "foo", - Value: "bar", - Events: []string{"foo"}, - Output: "", + Action: "add", + Engine: "native", + Type: "repo", + Org: "github", + Repo: "octocat", + Name: "foo", + Value: "bar", + AllowEvents: []string{"foo"}, + Output: "", }, }, { diff --git a/command/secret/add.go b/command/secret/add.go index de646b60..ebf3b592 100644 --- a/command/secret/add.go +++ b/command/secret/add.go @@ -167,18 +167,18 @@ func add(c *cli.Context) error { // // https://pkg.go.dev/github.com/go-vela/cli/action/secret?tab=doc#Config s := &secret.Config{ - Action: internal.ActionAdd, - Engine: c.String(internal.FlagSecretEngine), - Type: c.String(internal.FlagSecretType), - Org: c.String(internal.FlagOrg), - Repo: c.String(internal.FlagRepo), - Team: c.String("team"), - Name: c.String("name"), - Value: c.String("value"), - Images: c.StringSlice("image"), - Events: c.StringSlice("event"), - File: c.String("file"), - Output: c.String(internal.FlagOutput), + Action: internal.ActionAdd, + Engine: c.String(internal.FlagSecretEngine), + Type: c.String(internal.FlagSecretType), + Org: c.String(internal.FlagOrg), + Repo: c.String(internal.FlagRepo), + Team: c.String("team"), + Name: c.String("name"), + Value: c.String("value"), + Images: c.StringSlice("image"), + AllowEvents: c.StringSlice("event"), + File: c.String("file"), + Output: c.String(internal.FlagOutput), } // check if allow_command and allow_substitution are provided diff --git a/command/secret/update.go b/command/secret/update.go index dcc66824..ddd8327e 100644 --- a/command/secret/update.go +++ b/command/secret/update.go @@ -167,18 +167,18 @@ func update(c *cli.Context) error { // // https://pkg.go.dev/github.com/go-vela/cli/action/secret?tab=doc#Config s := &secret.Config{ - Action: internal.ActionUpdate, - Engine: c.String(internal.FlagSecretEngine), - Type: c.String(internal.FlagSecretType), - Org: c.String(internal.FlagOrg), - Repo: c.String(internal.FlagRepo), - Team: c.String("team"), - Name: c.String("name"), - Value: c.String("value"), - Images: c.StringSlice("image"), - Events: c.StringSlice("event"), - File: c.String("file"), - Output: c.String(internal.FlagOutput), + Action: internal.ActionUpdate, + Engine: c.String(internal.FlagSecretEngine), + Type: c.String(internal.FlagSecretType), + Org: c.String(internal.FlagOrg), + Repo: c.String(internal.FlagRepo), + Team: c.String("team"), + Name: c.String("name"), + Value: c.String("value"), + Images: c.StringSlice("image"), + AllowEvents: c.StringSlice("event"), + File: c.String("file"), + Output: c.String(internal.FlagOutput), } // check if allow_command and allow_substitution are provided diff --git a/go.mod b/go.mod index 28d03b11..846bed27 100644 --- a/go.mod +++ b/go.mod @@ -10,10 +10,10 @@ require ( github.com/dustin/go-humanize v1.0.1 github.com/gin-gonic/gin v1.9.1 github.com/go-git/go-git/v5 v5.11.0 - github.com/go-vela/sdk-go v0.23.3 - github.com/go-vela/server v0.23.4 - github.com/go-vela/types v0.23.3 - github.com/go-vela/worker v0.23.3 + github.com/go-vela/sdk-go v0.23.2 + github.com/go-vela/server v0.23.4-0.20240401175144-f591935d2fc9 + github.com/go-vela/types v0.23.4-0.20240401132228-9b43c701ab32 + github.com/go-vela/worker v0.23.2 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/gosuri/uitable v0.0.4 github.com/joho/godotenv v1.5.1 @@ -36,6 +36,7 @@ require ( github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect + github.com/aymerick/douceur v0.2.0 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect @@ -76,6 +77,7 @@ require ( github.com/google/go-querystring v1.1.0 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/uuid v1.6.0 // indirect + github.com/gorilla/css v1.0.0 // indirect github.com/goware/urlx v0.3.2 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect @@ -93,6 +95,7 @@ require ( github.com/mattn/go-colorable v0.1.8 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/microcosm-cc/bluemonday v1.0.26 // indirect github.com/mitchellh/copystructure v1.0.0 // indirect github.com/mitchellh/reflectwalk v1.0.1 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect diff --git a/go.sum b/go.sum index 79846dae..7b957c2b 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFI github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= +github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= +github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= github.com/buildkite/yaml v0.0.0-20230306222819-0e4e032d4835 h1:Zfkih+Opdv9y5AOob+8iMsaMYnans+Ozrkb8wiPHbj0= github.com/buildkite/yaml v0.0.0-20230306222819-0e4e032d4835/go.mod h1:AV5wtJnn1/CRaRGlJ8xspkMWfKXV0/pkJVgGleTIrfk= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= @@ -114,14 +116,14 @@ github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= -github.com/go-vela/sdk-go v0.23.3 h1:0MxD3iFUNaCvjMOW2cJp9uz0Pn5VLQqZPDnma9XTMgg= -github.com/go-vela/sdk-go v0.23.3/go.mod h1:F47QqtcAoQ1aulS+ze4kWcd3/m8QNEIB5IyiZoP7n4U= -github.com/go-vela/server v0.23.4 h1:0ENIF2/B3Ldjae7MJILk6SdMCuG1AJ6dnWvGVYyjucM= -github.com/go-vela/server v0.23.4/go.mod h1:4f6bFTtHgOGBkJdDJ76AYk/Ms+nyBEP8RebTFiYUKZ0= -github.com/go-vela/types v0.23.3 h1:Ktt5g5NW9NVkclP7UiuANblkJB2dDaG5xVnnLEFjIWM= -github.com/go-vela/types v0.23.3/go.mod h1:mEF9dLkk00rUXf/t39n2WvXZgJbxnPEEWy+DHqIlRUo= -github.com/go-vela/worker v0.23.3 h1:dejrxSO3t9/toD2mQ3LWvyJt6NXxoZcceteS9h9vFhY= -github.com/go-vela/worker v0.23.3/go.mod h1:FcM0YPBVU1j683r9B0JomkaBxM/deSGI8nbIXL4Zpb4= +github.com/go-vela/sdk-go v0.23.2 h1:DQzhz7ggbLXmi2Kg0x0C4h/ujSujSSyHbxUORMgt/hk= +github.com/go-vela/sdk-go v0.23.2/go.mod h1:kppIcwY9Bd6qke7sHVWJ0F+SNvYuTUw2sNvAnrkqayg= +github.com/go-vela/server v0.23.4-0.20240401175144-f591935d2fc9 h1:R3TxguOk3JsIRoZn0oQBTLZRDIj4Xpeon+L/YJOF2Vw= +github.com/go-vela/server v0.23.4-0.20240401175144-f591935d2fc9/go.mod h1:Rbe6vgYe3gao8sBcALlhrM2YH4yu2cxJAFpWdDUbdZY= +github.com/go-vela/types v0.23.4-0.20240401132228-9b43c701ab32 h1:fqmNnM1LdH3Zg1zCADfgR7a51EOSZvLFAB2Em4CG+Pg= +github.com/go-vela/types v0.23.4-0.20240401132228-9b43c701ab32/go.mod h1:mEF9dLkk00rUXf/t39n2WvXZgJbxnPEEWy+DHqIlRUo= +github.com/go-vela/worker v0.23.2 h1:ypYzhLk94xkAUbpBb9d+QU8rw4jVQC9rIOCIZ2XNb90= +github.com/go-vela/worker v0.23.2/go.mod h1:M1GzqlX6bIi/p+Fb6HuJ/uGHzPbaQBS6KVreClInZKg= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= @@ -152,6 +154,8 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLe github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= +github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= github.com/gosuri/uitable v0.0.4 h1:IG2xLKRvErL3uhY6e1BylFzG+aJiwQviDDTfOKeKTpY= github.com/gosuri/uitable v0.0.4/go.mod h1:tKR86bXuXPZazfOTG1FIzvjIdXzd0mo4Vtn16vt0PJo= github.com/goware/urlx v0.3.2 h1:gdoo4kBHlkqZNaf6XlQ12LGtQOmpKJrR04Rc3RnpJEo= @@ -208,6 +212,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58= +github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= From 8001c1544555ec73a6856cd23fbc80f9835e8106 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:12:32 -0500 Subject: [PATCH 02/17] chore: update secret validate switch --- action/secret/validate.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/action/secret/validate.go b/action/secret/validate.go index b52264a8..da5128b2 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -86,17 +86,29 @@ func (c *Config) Validate() error { for _, event := range c.AllowEvents { // check if the secret event provided is valid switch event { - case constants.EventComment: + case constants.EventPush: fallthrough - case constants.EventDeploy: + case constants.EventPull + ":" + constants.ActionOpened: fallthrough - case constants.EventPull: + case constants.EventPull + ":" + constants.ActionSynchronize: fallthrough - case constants.EventPush: + case constants.EventPull + ":" + constants.ActionEdited: fallthrough - case constants.EventSchedule: + case constants.EventPull + ":" + constants.ActionReopened: fallthrough case constants.EventTag: + fallthrough + case constants.EventComment + ":" + constants.ActionCreated: + fallthrough + case constants.EventComment + ":" + constants.ActionEdited: + fallthrough + case constants.EventDeploy: + fallthrough + case constants.EventSchedule: + fallthrough + case constants.EventDelete + ":" + constants.ActionBranch: + fallthrough + case constants.EventDelete + ":" + constants.ActionTag: continue default: return fmt.Errorf("invalid secret event provided: %s", event) From ea0237ee6e0631b042ecb33a0e676ee198c8fb87 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:14:36 -0500 Subject: [PATCH 03/17] chore: verbose test types --- action/secret/validate_test.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/action/secret/validate_test.go b/action/secret/validate_test.go index 83a251a5..c7328c95 100644 --- a/action/secret/validate_test.go +++ b/action/secret/validate_test.go @@ -94,15 +94,21 @@ func TestSecret_Config_Validate(t *testing.T) { { failure: false, config: &Config{ - Action: "add", - Engine: "native", - Type: "repo", - Org: "github", - Repo: "octocat", - Name: "foo", - Value: "bar", - AllowEvents: []string{"comment", "push", "pull_request", "tag", "deployment", "schedule"}, - Output: "", + Action: "add", + Engine: "native", + Type: "repo", + Org: "github", + Repo: "octocat", + Name: "foo", + Value: "bar", + AllowEvents: []string{ + "comment:created", + "pull_request:opened", "pull_request:synchronize", "pull_request:edited", + "push:branch", "push:tag", + "deployment", + "schedule", + }, + Output: "", }, }, { From e4705ca24414af1a6cfa1eb586587a89e298f2ca Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:21:15 -0500 Subject: [PATCH 04/17] chore: more valid events --- action/secret/validate.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action/secret/validate.go b/action/secret/validate.go index da5128b2..01f11787 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -88,6 +88,10 @@ func (c *Config) Validate() error { switch event { case constants.EventPush: fallthrough + case constants.EventPush + ":" + constants.ActionBranch: + fallthrough + case constants.EventPush + ":" + constants.ActionTag: + fallthrough case constants.EventPull + ":" + constants.ActionOpened: fallthrough case constants.EventPull + ":" + constants.ActionSynchronize: From 70c38a0a061d8ee07b2d384c2039cbfb2de9eb3d Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:29:58 -0500 Subject: [PATCH 05/17] fix: use generated validevents list --- action/secret/validate.go | 80 ++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/action/secret/validate.go b/action/secret/validate.go index 01f11787..108dba03 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -7,6 +7,8 @@ import ( "strings" "github.com/go-vela/types/constants" + "github.com/go-vela/types/library" + "github.com/go-vela/types/library/actions" "github.com/sirupsen/logrus" ) @@ -85,36 +87,15 @@ func (c *Config) Validate() error { // iterate through all secret events for _, event := range c.AllowEvents { // check if the secret event provided is valid - switch event { - case constants.EventPush: - fallthrough - case constants.EventPush + ":" + constants.ActionBranch: - fallthrough - case constants.EventPush + ":" + constants.ActionTag: - fallthrough - case constants.EventPull + ":" + constants.ActionOpened: - fallthrough - case constants.EventPull + ":" + constants.ActionSynchronize: - fallthrough - case constants.EventPull + ":" + constants.ActionEdited: - fallthrough - case constants.EventPull + ":" + constants.ActionReopened: - fallthrough - case constants.EventTag: - fallthrough - case constants.EventComment + ":" + constants.ActionCreated: - fallthrough - case constants.EventComment + ":" + constants.ActionEdited: - fallthrough - case constants.EventDeploy: - fallthrough - case constants.EventSchedule: - fallthrough - case constants.EventDelete + ":" + constants.ActionBranch: - fallthrough - case constants.EventDelete + ":" + constants.ActionTag: - continue - default: + valid := false + for _, e := range validEvents() { + if event == e { + valid = true + break + } + } + + if !valid { return fmt.Errorf("invalid secret event provided: %s", event) } } @@ -122,3 +103,42 @@ func (c *Config) Validate() error { return nil } + +func validEvents() []string { + t := true + + evs := library.Events{ + Push: &actions.Push{ + Branch: &t, + Tag: &t, + DeleteBranch: &t, + DeleteTag: &t, + }, + PullRequest: &actions.Pull{ + Opened: &t, + Edited: &t, + Synchronize: &t, + Reopened: &t, + }, + Deployment: &actions.Deploy{ + Created: &t, + }, + Comment: &actions.Comment{ + Created: &t, + Edited: &t, + }, + Schedule: &actions.Schedule{ + Run: &t, + }, + } + + legacyEvs := []string{ + "push", + "pull_request", + "deployment", + "comment", + "schedule", + } + + return append(evs.List(), legacyEvs...) +} From a80af93fae4a7c4ae4c9a3a834ca1cde067727b6 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:31:19 -0500 Subject: [PATCH 06/17] fix: use generated validevents list --- action/secret/validate.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/action/secret/validate.go b/action/secret/validate.go index 108dba03..183074de 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -104,7 +104,16 @@ func (c *Config) Validate() error { return nil } +// returns a useable list of valid events using a combination of hardcoded shorthand names and AllowEvents.List() func validEvents() []string { + shorthands := []string{ + "push", + "pull_request", + "deployment", + "comment", + "schedule", + } + t := true evs := library.Events{ @@ -132,13 +141,5 @@ func validEvents() []string { }, } - legacyEvs := []string{ - "push", - "pull_request", - "deployment", - "comment", - "schedule", - } - - return append(evs.List(), legacyEvs...) + return append(evs.List(), shorthands...) } From 6cd06f072f899ab0b9b6045de41bffba205beb30 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:32:49 -0500 Subject: [PATCH 07/17] fix: pr validator --- .github/workflows/validate-pr-title.yml | 2 +- action/secret/validate.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/validate-pr-title.yml b/.github/workflows/validate-pr-title.yml index aa3588f6..223f7cdf 100644 --- a/.github/workflows/validate-pr-title.yml +++ b/.github/workflows/validate-pr-title.yml @@ -14,4 +14,4 @@ jobs: steps: - name: validate title run: | - echo "${{ github.event.pull_request.title }}" | grep -Eq '^(feat|fix|chore|refactor|enhance|test|docs)\(.*\):.*$' && (echo "Pass"; exit 0) || (echo "Incorrect Format. Please see https://go-vela.github.io/docs/community/contributing_guidelines/#development-workflow"; exit 1) \ No newline at end of file + echo "${{ github.event.pull_request.title }}" | grep -Eq '^(feat|fix|chore|refactor|enhance|test|docs)(\(.*\)|):\s.+$' && (echo "Pass"; exit 0) || (echo "Incorrect Format. Please see https://go-vela.github.io/docs/community/contributing_guidelines/#development-workflow"; exit 1) \ No newline at end of file diff --git a/action/secret/validate.go b/action/secret/validate.go index 183074de..cb8ca1e4 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -88,6 +88,7 @@ func (c *Config) Validate() error { for _, event := range c.AllowEvents { // check if the secret event provided is valid valid := false + for _, e := range validEvents() { if event == e { valid = true From 1909d1b5986914032adb6a3320a87d40d4389fe9 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:33:35 -0500 Subject: [PATCH 08/17] chore: bump go.mod --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 846bed27..2479bc54 100644 --- a/go.mod +++ b/go.mod @@ -10,9 +10,9 @@ require ( github.com/dustin/go-humanize v1.0.1 github.com/gin-gonic/gin v1.9.1 github.com/go-git/go-git/v5 v5.11.0 - github.com/go-vela/sdk-go v0.23.2 + github.com/go-vela/sdk-go v0.23.3-0.20240319181130-4a7c245c93ae github.com/go-vela/server v0.23.4-0.20240401175144-f591935d2fc9 - github.com/go-vela/types v0.23.4-0.20240401132228-9b43c701ab32 + github.com/go-vela/types v0.23.4-0.20240402153726-f16c3e4cb5fb github.com/go-vela/worker v0.23.2 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/gosuri/uitable v0.0.4 diff --git a/go.sum b/go.sum index 7b957c2b..5822dd3d 100644 --- a/go.sum +++ b/go.sum @@ -116,12 +116,12 @@ github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= -github.com/go-vela/sdk-go v0.23.2 h1:DQzhz7ggbLXmi2Kg0x0C4h/ujSujSSyHbxUORMgt/hk= -github.com/go-vela/sdk-go v0.23.2/go.mod h1:kppIcwY9Bd6qke7sHVWJ0F+SNvYuTUw2sNvAnrkqayg= +github.com/go-vela/sdk-go v0.23.3-0.20240319181130-4a7c245c93ae h1:E5sgPxZsuiB00hcAgR/TpzRcovy+GVFzTSZfPHMIfPY= +github.com/go-vela/sdk-go v0.23.3-0.20240319181130-4a7c245c93ae/go.mod h1:4iOo5uuh4S3V//7ipZ9ZxvXc1wR2EGxDCeTqpom8rfU= github.com/go-vela/server v0.23.4-0.20240401175144-f591935d2fc9 h1:R3TxguOk3JsIRoZn0oQBTLZRDIj4Xpeon+L/YJOF2Vw= github.com/go-vela/server v0.23.4-0.20240401175144-f591935d2fc9/go.mod h1:Rbe6vgYe3gao8sBcALlhrM2YH4yu2cxJAFpWdDUbdZY= -github.com/go-vela/types v0.23.4-0.20240401132228-9b43c701ab32 h1:fqmNnM1LdH3Zg1zCADfgR7a51EOSZvLFAB2Em4CG+Pg= -github.com/go-vela/types v0.23.4-0.20240401132228-9b43c701ab32/go.mod h1:mEF9dLkk00rUXf/t39n2WvXZgJbxnPEEWy+DHqIlRUo= +github.com/go-vela/types v0.23.4-0.20240402153726-f16c3e4cb5fb h1:jHao/NNRswInMLEb0m1OJ84d1m/LGWMCmaeRqSDnWQY= +github.com/go-vela/types v0.23.4-0.20240402153726-f16c3e4cb5fb/go.mod h1:mEF9dLkk00rUXf/t39n2WvXZgJbxnPEEWy+DHqIlRUo= github.com/go-vela/worker v0.23.2 h1:ypYzhLk94xkAUbpBb9d+QU8rw4jVQC9rIOCIZ2XNb90= github.com/go-vela/worker v0.23.2/go.mod h1:M1GzqlX6bIi/p+Fb6HuJ/uGHzPbaQBS6KVreClInZKg= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= From 0b6c66b978e515909033bc7a8533424078f76891 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:34:18 -0500 Subject: [PATCH 09/17] chore: appease linter --- action/secret/validate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/secret/validate.go b/action/secret/validate.go index cb8ca1e4..69f56857 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -105,7 +105,7 @@ func (c *Config) Validate() error { return nil } -// returns a useable list of valid events using a combination of hardcoded shorthand names and AllowEvents.List() +// returns a useable list of valid events using a combination of hardcoded shorthand names and AllowEvents.List(). func validEvents() []string { shorthands := []string{ "push", From 0e780e412b11f2e08c5f1509970540dcd2921114 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:38:24 -0500 Subject: [PATCH 10/17] fix: bundling api worker types changes --- action/worker/table.go | 6 +++--- action/worker/table_test.go | 14 +++++++------- action/worker/update.go | 5 ++--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/action/worker/table.go b/action/worker/table.go index c1be4d20..ed65617e 100644 --- a/action/worker/table.go +++ b/action/worker/table.go @@ -6,7 +6,7 @@ import ( "time" "github.com/go-vela/cli/internal/output" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" "github.com/dustin/go-humanize" "github.com/gosuri/uitable" @@ -16,7 +16,7 @@ import ( // table is a helper function to output the // provided workers in a table format with // a specific set of fields displayed. -func table(workers *[]library.Worker) error { +func table(workers *[]api.Worker) error { logrus.Debug("creating table for list of workers") // create a new table @@ -60,7 +60,7 @@ func table(workers *[]library.Worker) error { // wideTable is a helper function to output the // provided workers in a wide table format with // a specific set of fields displayed. -func wideTable(workers *[]library.Worker) error { +func wideTable(workers *[]api.Worker) error { logrus.Debug("creating wide table for list of workers") // create new wide table diff --git a/action/worker/table_test.go b/action/worker/table_test.go index 71ad7f44..e29a8cbc 100644 --- a/action/worker/table_test.go +++ b/action/worker/table_test.go @@ -5,7 +5,7 @@ package worker import ( "testing" - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" ) func TestWorker_table(t *testing.T) { @@ -22,11 +22,11 @@ func TestWorker_table(t *testing.T) { // setup tests tests := []struct { failure bool - workers *[]library.Worker + workers *[]api.Worker }{ { failure: false, - workers: &[]library.Worker{ + workers: &[]api.Worker{ *w1, *w2, }, @@ -66,11 +66,11 @@ func TestWorker_wideTable(t *testing.T) { // setup tests tests := []struct { failure bool - workers *[]library.Worker + workers *[]api.Worker }{ { failure: false, - workers: &[]library.Worker{ + workers: &[]api.Worker{ *w1, *w2, }, @@ -97,8 +97,8 @@ func TestWorker_wideTable(t *testing.T) { // testWorker is a test helper function to create a Worker // type with all fields set to a fake value. -func testWorker() *library.Worker { - w := new(library.Worker) +func testWorker() *api.Worker { + w := new(api.Worker) w.SetID(1) w.SetActive(true) diff --git a/action/worker/update.go b/action/worker/update.go index e9f59845..d86a526a 100644 --- a/action/worker/update.go +++ b/action/worker/update.go @@ -6,8 +6,7 @@ import ( "github.com/go-vela/cli/internal/output" "github.com/go-vela/sdk-go/vela" - - "github.com/go-vela/types/library" + api "github.com/go-vela/server/api/types" "github.com/sirupsen/logrus" ) @@ -19,7 +18,7 @@ func (c *Config) Update(client *vela.Client) error { // create the worker object // // https://pkg.go.dev/github.com/go-vela/types/library?tab=doc#Worker - w := &library.Worker{ + w := &api.Worker{ Hostname: vela.String(c.Hostname), Address: vela.String(c.Address), Active: c.Active, From 6692668d66296d799abdb0f45187e6f6f66550dd Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:49:15 -0500 Subject: [PATCH 11/17] fix: use hardcoded unlisted event tags --- action/secret/validate.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/action/secret/validate.go b/action/secret/validate.go index 69f56857..b7557027 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -90,6 +90,7 @@ func (c *Config) Validate() error { valid := false for _, e := range validEvents() { + fmt.Println(e, event) if event == e { valid = true break @@ -107,12 +108,12 @@ func (c *Config) Validate() error { // returns a useable list of valid events using a combination of hardcoded shorthand names and AllowEvents.List(). func validEvents() []string { - shorthands := []string{ - "push", + unlistedEvents := []string{ "pull_request", - "deployment", - "comment", - "schedule", + "push:branch", + "push:tag", + "deployment:created", + "schedule:run", } t := true @@ -142,5 +143,5 @@ func validEvents() []string { }, } - return append(evs.List(), shorthands...) + return append(evs.List(), unlistedEvents...) } From 5e1e60684ae236b21263163577ea5a161064d8f8 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:50:49 -0500 Subject: [PATCH 12/17] fix: remove debug --- action/secret/validate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action/secret/validate.go b/action/secret/validate.go index b7557027..418f585e 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -90,7 +90,7 @@ func (c *Config) Validate() error { valid := false for _, e := range validEvents() { - fmt.Println(e, event) + if event == e { valid = true break From e867117d1bf56b1b048d4c5b46d64f056b95a678 Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:50:58 -0500 Subject: [PATCH 13/17] fix: remove debug --- action/secret/validate.go | 1 - 1 file changed, 1 deletion(-) diff --git a/action/secret/validate.go b/action/secret/validate.go index 418f585e..85634417 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -90,7 +90,6 @@ func (c *Config) Validate() error { valid := false for _, e := range validEvents() { - if event == e { valid = true break From f2c73074134f62adcc87462a7f23ab5a6cea29ae Mon Sep 17 00:00:00 2001 From: davidvader Date: Wed, 3 Apr 2024 14:52:49 -0500 Subject: [PATCH 14/17] chore: appease linter --- action/secret/validate.go | 1 - 1 file changed, 1 deletion(-) diff --git a/action/secret/validate.go b/action/secret/validate.go index 85634417..b650e73b 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -88,7 +88,6 @@ func (c *Config) Validate() error { for _, event := range c.AllowEvents { // check if the secret event provided is valid valid := false - for _, e := range validEvents() { if event == e { valid = true From dd976c101d33a3ae915262f5cb26daf3c5bec2ff Mon Sep 17 00:00:00 2001 From: davidvader Date: Fri, 5 Apr 2024 14:16:07 -0500 Subject: [PATCH 15/17] fix: check invalid events using err --- action/secret/add.go | 7 ++++++- action/secret/update.go | 7 ++++++- action/secret/validate.go | 17 +++-------------- go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/action/secret/add.go b/action/secret/add.go index eab22d87..8a2e4331 100644 --- a/action/secret/add.go +++ b/action/secret/add.go @@ -63,7 +63,12 @@ func (c *Config) Add(client *vela.Client) error { // populate events if provided if len(c.AllowEvents) > 0 { - s.SetAllowEvents(library.NewEventsFromSlice(c.AllowEvents)) + evs, err := library.NewEventsFromSlice(c.AllowEvents) + if err != nil { + return err + } + + s.SetAllowEvents(evs) } logrus.Tracef("adding secret %s/%s/%s/%s/%s", c.Engine, c.Type, c.Org, name, c.Name) diff --git a/action/secret/update.go b/action/secret/update.go index 7c580fd3..b1b64972 100644 --- a/action/secret/update.go +++ b/action/secret/update.go @@ -63,7 +63,12 @@ func (c *Config) Update(client *vela.Client) error { // populate events if provided if len(c.AllowEvents) > 0 { - s.SetAllowEvents(library.NewEventsFromSlice(c.AllowEvents)) + evs, err := library.NewEventsFromSlice(c.AllowEvents) + if err != nil { + return err + } + + s.SetAllowEvents(evs) } logrus.Tracef("modifying secret %s/%s/%s/%s/%s", c.Engine, c.Type, c.Org, name, c.Name) diff --git a/action/secret/validate.go b/action/secret/validate.go index b650e73b..737145d5 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -84,20 +84,9 @@ func (c *Config) Validate() error { // check if secret action is add or update if c.Action == "add" || c.Action == "update" { - // iterate through all secret events - for _, event := range c.AllowEvents { - // check if the secret event provided is valid - valid := false - for _, e := range validEvents() { - if event == e { - valid = true - break - } - } - - if !valid { - return fmt.Errorf("invalid secret event provided: %s", event) - } + _, err := library.NewEventsFromSlice(c.AllowEvents) + if err != nil { + return err } } diff --git a/go.mod b/go.mod index 2479bc54..876d00f0 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/go-git/go-git/v5 v5.11.0 github.com/go-vela/sdk-go v0.23.3-0.20240319181130-4a7c245c93ae github.com/go-vela/server v0.23.4-0.20240401175144-f591935d2fc9 - github.com/go-vela/types v0.23.4-0.20240402153726-f16c3e4cb5fb + github.com/go-vela/types v0.23.4-0.20240405190958-ea618bf19708 github.com/go-vela/worker v0.23.2 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/gosuri/uitable v0.0.4 diff --git a/go.sum b/go.sum index 5822dd3d..689c18ea 100644 --- a/go.sum +++ b/go.sum @@ -120,8 +120,8 @@ github.com/go-vela/sdk-go v0.23.3-0.20240319181130-4a7c245c93ae h1:E5sgPxZsuiB00 github.com/go-vela/sdk-go v0.23.3-0.20240319181130-4a7c245c93ae/go.mod h1:4iOo5uuh4S3V//7ipZ9ZxvXc1wR2EGxDCeTqpom8rfU= github.com/go-vela/server v0.23.4-0.20240401175144-f591935d2fc9 h1:R3TxguOk3JsIRoZn0oQBTLZRDIj4Xpeon+L/YJOF2Vw= github.com/go-vela/server v0.23.4-0.20240401175144-f591935d2fc9/go.mod h1:Rbe6vgYe3gao8sBcALlhrM2YH4yu2cxJAFpWdDUbdZY= -github.com/go-vela/types v0.23.4-0.20240402153726-f16c3e4cb5fb h1:jHao/NNRswInMLEb0m1OJ84d1m/LGWMCmaeRqSDnWQY= -github.com/go-vela/types v0.23.4-0.20240402153726-f16c3e4cb5fb/go.mod h1:mEF9dLkk00rUXf/t39n2WvXZgJbxnPEEWy+DHqIlRUo= +github.com/go-vela/types v0.23.4-0.20240405190958-ea618bf19708 h1:ETr/ZW0Z+cXT2leqY6iQUxGX2q/QGHW6QME5DcsTiHw= +github.com/go-vela/types v0.23.4-0.20240405190958-ea618bf19708/go.mod h1:mEF9dLkk00rUXf/t39n2WvXZgJbxnPEEWy+DHqIlRUo= github.com/go-vela/worker v0.23.2 h1:ypYzhLk94xkAUbpBb9d+QU8rw4jVQC9rIOCIZ2XNb90= github.com/go-vela/worker v0.23.2/go.mod h1:M1GzqlX6bIi/p+Fb6HuJ/uGHzPbaQBS6KVreClInZKg= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= From edccc7421089549e0f8fba79b14f206dd4ff4665 Mon Sep 17 00:00:00 2001 From: davidvader Date: Fri, 5 Apr 2024 14:18:16 -0500 Subject: [PATCH 16/17] chore: remove unused code --- action/secret/validate.go | 41 --------------------------------------- 1 file changed, 41 deletions(-) diff --git a/action/secret/validate.go b/action/secret/validate.go index 737145d5..ee180c6d 100644 --- a/action/secret/validate.go +++ b/action/secret/validate.go @@ -8,7 +8,6 @@ import ( "github.com/go-vela/types/constants" "github.com/go-vela/types/library" - "github.com/go-vela/types/library/actions" "github.com/sirupsen/logrus" ) @@ -92,43 +91,3 @@ func (c *Config) Validate() error { return nil } - -// returns a useable list of valid events using a combination of hardcoded shorthand names and AllowEvents.List(). -func validEvents() []string { - unlistedEvents := []string{ - "pull_request", - "push:branch", - "push:tag", - "deployment:created", - "schedule:run", - } - - t := true - - evs := library.Events{ - Push: &actions.Push{ - Branch: &t, - Tag: &t, - DeleteBranch: &t, - DeleteTag: &t, - }, - PullRequest: &actions.Pull{ - Opened: &t, - Edited: &t, - Synchronize: &t, - Reopened: &t, - }, - Deployment: &actions.Deploy{ - Created: &t, - }, - Comment: &actions.Comment{ - Created: &t, - Edited: &t, - }, - Schedule: &actions.Schedule{ - Run: &t, - }, - } - - return append(evs.List(), unlistedEvents...) -} From a631229d6372db4ae2aba42203742b44ac4d7147 Mon Sep 17 00:00:00 2001 From: davidvader Date: Fri, 5 Apr 2024 14:21:24 -0500 Subject: [PATCH 17/17] chore: fix setallow funcs --- action/repo/add.go | 7 ++++++- action/repo/update.go | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/action/repo/add.go b/action/repo/add.go index 25f926c1..9b4dd21a 100644 --- a/action/repo/add.go +++ b/action/repo/add.go @@ -43,7 +43,12 @@ func (c *Config) Add(client *vela.Client) error { logrus.Tracef("adding repo %s/%s", c.Org, c.Name) if len(c.Events) > 0 { - r.SetAllowEvents(library.NewEventsFromSlice(c.Events)) + evs, err := library.NewEventsFromSlice(c.Events) + if err != nil { + return err + } + + r.SetAllowEvents(evs) } // send API call to add a repository diff --git a/action/repo/update.go b/action/repo/update.go index d8892659..07c7c70a 100644 --- a/action/repo/update.go +++ b/action/repo/update.go @@ -41,7 +41,12 @@ func (c *Config) Update(client *vela.Client) error { } if len(c.Events) > 0 { - r.SetAllowEvents(library.NewEventsFromSlice(c.Events)) + evs, err := library.NewEventsFromSlice(c.Events) + if err != nil { + return err + } + + r.SetAllowEvents(evs) } logrus.Tracef("updating repo %s/%s", c.Org, c.Name)