Skip to content

Commit

Permalink
Merge pull request #741 from bard/fix-update-github-webhook-handler
Browse files Browse the repository at this point in the history
update github handler
  • Loading branch information
rusenask authored Sep 28, 2023
2 parents 3ecd57c + 8834bb8 commit f4415cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pkg/http/github_webhook_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *TriggerServer) githubHandler(resp http.ResponseWriter, req *http.Reques
var imageName, imageTag string

switch hookEvent {
case "package_v2":
case "package":
payload := new(githubPackageV2Webhook)
if err := json.NewDecoder(req.Body).Decode(payload); err != nil {
log.WithFields(log.Fields{
Expand Down Expand Up @@ -143,8 +143,9 @@ func (s *TriggerServer) githubHandler(resp http.ResponseWriter, req *http.Reques
return
}

// XXX <jsonroot>.registry_package.package_version.package_url could work too but it ends with colon
imageName = strings.Join(
[]string{"docker.pkg.github.com", payload.Repository.FullName, payload.RegistryPackage.Name},
[]string{"ghcr.io", payload.Repository.FullName},
"/",
)
imageTag = payload.RegistryPackage.PackageVersion.Version
Expand Down
8 changes: 4 additions & 4 deletions pkg/http/github_webhook_trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var fakeGithubPackageWebhook = `{
"about_url": "https://help.github.com/about-github-package-registry",
"name": "GitHub docker registry",
"type": "docker",
"url": "https://docker.pkg.github.com/DingGGu/UtaiteBOX",
"url": "https://ghcr.io/DingGGu/UtaiteBOX",
"vendor": "GitHub Inc"
}
},
Expand Down Expand Up @@ -361,8 +361,8 @@ func TestGithubPackageWebhookHandler(t *testing.T) {
t.Fatalf("unexpected number of events submitted: %d", len(fp.submitted))
}

if fp.submitted[0].Repository.Name != "docker.pkg.github.com/DingGGu/UtaiteBOX/server" {
t.Errorf("expected docker.pkg.github.com/DingGGu/UtaiteBOX/server but got %s", fp.submitted[0].Repository.Name)
if fp.submitted[0].Repository.Name != "ghcr.io/DingGGu/UtaiteBOX" {
t.Errorf("expected ghcr.io/DingGGu/UtaiteBOX but got %s", fp.submitted[0].Repository.Name)
}

if fp.submitted[0].Repository.Tag != "1.2.3" {
Expand All @@ -380,7 +380,7 @@ func TestGithubContainerRegistryWebhookHandler(t *testing.T) {
if err != nil {
t.Fatalf("failed to create req: %s", err)
}
req.Header.Set("X-GitHub-Event", "package_v2")
req.Header.Set("X-GitHub-Event", "package")

//The response recorder used to record HTTP responses
rec := httptest.NewRecorder()
Expand Down

0 comments on commit f4415cb

Please sign in to comment.