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

update github handler #741

Merged
merged 3 commits into from
Sep 28, 2023
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
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
bard marked this conversation as resolved.
Show resolved Hide resolved
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