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(stash): first push not triggering postsubmits in lighthouse #385

Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
golang.org/x/oauth2 v0.15.0
gopkg.in/h2non/gock.v1 v1.1.2
k8s.io/apimachinery v0.29.0
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/apimachinery v0.29.0 h1:+ACVktwyicPz0oc6MTMLwa2Pw3ouLAfAon1wPLtG48o=
k8s.io/apimachinery v0.29.0/go.mod h1:eVBxQ/cwiJxH58eK/jd/vAk4mrxmVlnpBH5J2GbMeis=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
29 changes: 23 additions & 6 deletions scm/driver/stash/testdata/webhooks/push_branch_create.json.golden
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"Ref": {
"Name": "develop",
"Sha": "208b0a5c05eddadad01f2aed8802fe0c3b3eaf5e"
},
"Ref": "refs/heads/develop",
"Repo": {
"ID": "1",
"Namespace": "PRJ",
Expand All @@ -17,11 +14,31 @@
"Created": "0001-01-01T00:00:00Z",
"Updated": "0001-01-01T00:00:00Z"
},
"Action": "created",
"After": "208b0a5c05eddadad01f2aed8802fe0c3b3eaf5e",
"Commit": {
"Sha": "208b0a5c05eddadad01f2aed8802fe0c3b3eaf5e",
"Message": "",
"Author": {
"Name": "Jane Citizen",
"Email": "[email protected]",
"Date": "2018-07-05T18:24:15Z",
"Login": "jcitizen",
"Avatar": "https://www.gravatar.com/avatar/9e26471d35a78862c17e467d87cddedf.jpg"
},
"Committer": {
"Name": "Jane Citizen",
"Email": "[email protected]",
"Date": "2018-07-05T18:24:15Z",
"Login": "jcitizen",
"Avatar": "https://www.gravatar.com/avatar/9e26471d35a78862c17e467d87cddedf.jpg"
},
"Link": ""
},
"Sender": {
"Login": "jcitizen",
"Name": "Jane Citizen",
"Email": "[email protected]",
"Avatar": "https://www.gravatar.com/avatar/9e26471d35a78862c17e467d87cddedf.jpg"
}
},
"Guid": "ee8d97b4-1479-43f1-9cac-fbbd1b80da55"
}
3 changes: 2 additions & 1 deletion scm/driver/stash/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/jenkins-x/go-scm/pkg/hmac"
"github.com/jenkins-x/go-scm/scm"
"k8s.io/utils/strings/slices"
)

// TODO(bradrydzewski) push hook does not include commit message
Expand Down Expand Up @@ -90,7 +91,7 @@ func (s *webhookService) parsePushHook(data []byte, guid string) (scm.Webhook, e
}
change := dst.Changes[0]
switch {
case change.Ref.Type == "BRANCH" && change.Type != "UPDATE":
case change.Ref.Type == "BRANCH" && !(slices.Contains([]string{"UPDATE", "ADD"}, change.Type)):
return convertBranchHook(dst), nil
case change.Ref.Type == "TAG":
return convertTagHook(dst), nil
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/stash/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestWebhooks(t *testing.T) {
event: "repo:refs_changed",
before: "testdata/webhooks/push_branch_create.json",
after: "testdata/webhooks/push_branch_create.json.golden",
obj: new(scm.BranchHook),
obj: new(scm.PushHook),
},
// delete
{
Expand Down