From 341c81e78b85271e890e65b70ecff8183af64b53 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 8 Feb 2022 12:03:18 -0500 Subject: [PATCH 01/31] Auto commit @ 2022-02-08T17:03:18Z --- .vscode/settings.json | 9 ++ server/api/hook.go | 6 +- server/model/const.go | 9 +- server/remote/github/fixtures/hooks.go | 178 +++++++++++++++++++++++++ server/remote/github/parse.go | 41 +++++- server/remote/github/parse_test.go | 24 +++- 6 files changed, 256 insertions(+), 11 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c0622716b9..56977dd5e0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,5 +9,14 @@ "go.lintTool":"golangci-lint", "go.lintFlags": [ "--fast" + ], + "spellright.language": [ + "en" + ], + "spellright.documentTypes": [ + "markdown", + "latex", + "plaintext", + "go" ] } diff --git a/server/api/hook.go b/server/api/hook.go index a2e1aa2a6f..66c028aa37 100644 --- a/server/api/hook.go +++ b/server/api/hook.go @@ -102,7 +102,11 @@ func PostHook(c *gin.Context) { // wrapped in square brackets appear in the commit message skipMatch := skipRe.FindString(build.Message) if len(skipMatch) > 0 { - msg := fmt.Sprintf("ignoring hook: %s found in %s", skipMatch, build.Commit) + ref := build.Commit + if len(ref) == 0 { + ref = build.Ref + } + msg := fmt.Sprintf("ignoring hook: %s found in %s", skipMatch, ref) log.Debug().Msg(msg) c.String(http.StatusNoContent, msg) return diff --git a/server/model/const.go b/server/model/const.go index 6430c0d118..0eef70e6f9 100644 --- a/server/model/const.go +++ b/server/model/const.go @@ -17,10 +17,11 @@ package model type WebhookEvent string const ( - EventPush WebhookEvent = "push" - EventPull WebhookEvent = "pull_request" - EventTag WebhookEvent = "tag" - EventDeploy WebhookEvent = "deployment" + EventPush WebhookEvent = "push" + EventPull WebhookEvent = "pull_request" + EventTag WebhookEvent = "tag" + EventDeploy WebhookEvent = "deployment" + EventRelease WebhookEvent = "release" ) func ValidateWebhookEvent(s WebhookEvent) bool { diff --git a/server/remote/github/fixtures/hooks.go b/server/remote/github/fixtures/hooks.go index be0bfaff80..e84ed8b48e 100644 --- a/server/remote/github/fixtures/hooks.go +++ b/server/remote/github/fixtures/hooks.go @@ -352,3 +352,181 @@ const HookDeploy = ` } } ` + +// HookPush is a sample release hook. +// https://developer.github.com/v3/activity/events/types/#release +const HookRelease = ` +{ + "action": "published", + "release": { + "url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/releases/2", + "assets_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/releases/2/assets", + "upload_url": "https://octocoders.github.io/api/uploads/repos/Codertocat/Hello-World/releases/2/assets{?name,label}", + "html_url": "https://octocoders.github.io/Codertocat/Hello-World/releases/tag/0.0.1", + "id": 2, + "node_id": "MDc6UmVsZWFzZTI=", + "tag_name": "0.0.1", + "target_commitish": "master", + "name": null, + "draft": false, + "author": { + "login": "Codertocat", + "id": 4, + "node_id": "MDQ6VXNlcjQ=", + "avatar_url": "https://octocoders.github.io/avatars/u/4?", + "gravatar_id": "", + "url": "https://octocoders.github.io/api/v3/users/Codertocat", + "html_url": "https://octocoders.github.io/Codertocat", + "followers_url": "https://octocoders.github.io/api/v3/users/Codertocat/followers", + "following_url": "https://octocoders.github.io/api/v3/users/Codertocat/following{/other_user}", + "gists_url": "https://octocoders.github.io/api/v3/users/Codertocat/gists{/gist_id}", + "starred_url": "https://octocoders.github.io/api/v3/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://octocoders.github.io/api/v3/users/Codertocat/subscriptions", + "organizations_url": "https://octocoders.github.io/api/v3/users/Codertocat/orgs", + "repos_url": "https://octocoders.github.io/api/v3/users/Codertocat/repos", + "events_url": "https://octocoders.github.io/api/v3/users/Codertocat/events{/privacy}", + "received_events_url": "https://octocoders.github.io/api/v3/users/Codertocat/received_events", + "type": "User", + "site_admin": false + }, + "prerelease": false, + "created_at": "2019-05-15T19:37:08Z", + "published_at": "2019-05-15T19:38:20Z", + "assets": [], + "tarball_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/tarball/0.0.1", + "zipball_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/zipball/0.0.1", + "body": null + }, + "repository": { + "id": 118, + "node_id": "MDEwOlJlcG9zaXRvcnkxMTg=", + "name": "Hello-World", + "full_name": "Codertocat/Hello-World", + "private": false, + "owner": { + "login": "Codertocat", + "id": 4, + "node_id": "MDQ6VXNlcjQ=", + "avatar_url": "https://octocoders.github.io/avatars/u/4?", + "gravatar_id": "", + "url": "https://octocoders.github.io/api/v3/users/Codertocat", + "html_url": "https://octocoders.github.io/Codertocat", + "followers_url": "https://octocoders.github.io/api/v3/users/Codertocat/followers", + "following_url": "https://octocoders.github.io/api/v3/users/Codertocat/following{/other_user}", + "gists_url": "https://octocoders.github.io/api/v3/users/Codertocat/gists{/gist_id}", + "starred_url": "https://octocoders.github.io/api/v3/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://octocoders.github.io/api/v3/users/Codertocat/subscriptions", + "organizations_url": "https://octocoders.github.io/api/v3/users/Codertocat/orgs", + "repos_url": "https://octocoders.github.io/api/v3/users/Codertocat/repos", + "events_url": "https://octocoders.github.io/api/v3/users/Codertocat/events{/privacy}", + "received_events_url": "https://octocoders.github.io/api/v3/users/Codertocat/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://octocoders.github.io/Codertocat/Hello-World", + "description": null, + "fork": false, + "url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World", + "forks_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/forks", + "keys_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/keys{/key_id}", + "collaborators_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/collaborators{/collaborator}", + "teams_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/teams", + "hooks_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/hooks", + "issue_events_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/issues/events{/number}", + "events_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/events", + "assignees_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/assignees{/user}", + "branches_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/branches{/branch}", + "tags_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/tags", + "blobs_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/git/blobs{/sha}", + "git_tags_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/git/tags{/sha}", + "git_refs_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/git/refs{/sha}", + "trees_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/git/trees{/sha}", + "statuses_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/statuses/{sha}", + "languages_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/languages", + "stargazers_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/stargazers", + "contributors_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/contributors", + "subscribers_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/subscribers", + "subscription_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/subscription", + "commits_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/commits{/sha}", + "git_commits_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/git/commits{/sha}", + "comments_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/comments{/number}", + "issue_comment_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/issues/comments{/number}", + "contents_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/contents/{+path}", + "compare_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/compare/{base}...{head}", + "merges_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/merges", + "archive_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/{archive_format}{/ref}", + "downloads_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/downloads", + "issues_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/issues{/number}", + "pulls_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/pulls{/number}", + "milestones_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/milestones{/number}", + "notifications_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/notifications{?since,all,participating}", + "labels_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/labels{/name}", + "releases_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/releases{/id}", + "deployments_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/deployments", + "created_at": "2019-05-15T19:37:07Z", + "updated_at": "2019-05-15T19:38:15Z", + "pushed_at": "2019-05-15T19:38:19Z", + "git_url": "git://octocoders.github.io/Codertocat/Hello-World.git", + "ssh_url": "git@octocoders.github.io:Codertocat/Hello-World.git", + "clone_url": "https://octocoders.github.io/Codertocat/Hello-World.git", + "svn_url": "https://octocoders.github.io/Codertocat/Hello-World", + "homepage": null, + "size": 0, + "stargazers_count": 0, + "watchers_count": 0, + "language": "Ruby", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 1, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 2, + "license": null, + "forks": 1, + "open_issues": 2, + "watchers": 0, + "default_branch": "master" + }, + "enterprise": { + "id": 1, + "slug": "github", + "name": "GitHub", + "node_id": "MDg6QnVzaW5lc3Mx", + "avatar_url": "https://octocoders.github.io/avatars/b/1?", + "description": null, + "website_url": null, + "html_url": "https://octocoders.github.io/businesses/github", + "created_at": "2019-05-14T19:31:12Z", + "updated_at": "2019-05-14T19:31:12Z" + }, + "sender": { + "login": "Codertocat", + "id": 4, + "node_id": "MDQ6VXNlcjQ=", + "avatar_url": "https://octocoders.github.io/avatars/u/4?", + "gravatar_id": "", + "url": "https://octocoders.github.io/api/v3/users/Codertocat", + "html_url": "https://octocoders.github.io/Codertocat", + "followers_url": "https://octocoders.github.io/api/v3/users/Codertocat/followers", + "following_url": "https://octocoders.github.io/api/v3/users/Codertocat/following{/other_user}", + "gists_url": "https://octocoders.github.io/api/v3/users/Codertocat/gists{/gist_id}", + "starred_url": "https://octocoders.github.io/api/v3/users/Codertocat/starred{/owner}{/repo}", + "subscriptions_url": "https://octocoders.github.io/api/v3/users/Codertocat/subscriptions", + "organizations_url": "https://octocoders.github.io/api/v3/users/Codertocat/orgs", + "repos_url": "https://octocoders.github.io/api/v3/users/Codertocat/repos", + "events_url": "https://octocoders.github.io/api/v3/users/Codertocat/events{/privacy}", + "received_events_url": "https://octocoders.github.io/api/v3/users/Codertocat/received_events", + "type": "User", + "site_admin": false + }, + "installation": { + "id": 5, + "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uNQ==" + } +} + +` diff --git a/server/remote/github/parse.go b/server/remote/github/parse.go index 804df11b85..5b5a65b52e 100644 --- a/server/remote/github/parse.go +++ b/server/remote/github/parse.go @@ -23,6 +23,7 @@ import ( "strings" "github.com/google/go-github/v39/github" + "github.com/rs/zerolog/log" "github.com/woodpecker-ci/woodpecker/server/model" "github.com/woodpecker-ci/woodpecker/shared/utils" @@ -51,7 +52,8 @@ func parseHook(r *http.Request, merge bool) (*github.PullRequest, *model.Repo, * return nil, nil, nil, err } - payload, err := github.ParseWebHook(github.WebHookType(r), raw) + var webhookType string = github.WebHookType(r) + payload, err := github.ParseWebHook(webhookType, raw) if err != nil { return nil, nil, nil, err } @@ -63,10 +65,15 @@ func parseHook(r *http.Request, merge bool) (*github.PullRequest, *model.Repo, * case *github.DeploymentEvent: repo, build, err := parseDeployHook(hook) return nil, repo, build, err + case *github.ReleaseEvent: + repo, build, err := parseReleaseHook(hook) + return nil, repo, build, err case *github.PullRequestEvent: return parsePullHook(hook, merge) + default: + log.Debug().Msg("Github event ignored, and will not be parsed " + webhookType) + return nil, nil, nil, nil } - return nil, nil, nil, nil } // parsePushHook parses a push hook and returns the Repo and Build details. @@ -143,6 +150,36 @@ func parseDeployHook(hook *github.DeploymentEvent) (*model.Repo, *model.Build, e return convertRepo(hook.GetRepo()), build, nil } +// parseDeployHook parses a deployment and returns the Repo and Build details. +// If the commit type is unsupported nil values are returned. +func parseReleaseHook(hook *github.ReleaseEvent) (*model.Repo, *model.Build, error) { + release := hook.GetRelease() + build := &model.Build{ + Event: model.EventRelease, + // Commit: "", + // Cannot retrieve the commit since + // it is hidden in the tag. It seems that github dose + // not provide the commit SHA with a release. + ID: release.GetID(), + Created: release.CreatedAt.UTC().Unix(), + Link: release.GetURL(), + Message: release.GetBody(), // Use the body of the release. There is no message. + Title: release.GetName(), + // Tag name here is the ref. We should add the refs/tags so + // it is known is a tag (git-plugin looks for it) + Ref: "refs/tags/" + release.GetTagName(), + // Branch: *release.TagName, Dose not exist here. Github releases + // is always a tag + + Avatar: hook.GetSender().GetAvatarURL(), + Author: hook.GetSender().GetLogin(), + Sender: hook.GetSender().GetLogin(), + Remote: hook.GetRepo().GetCloneURL(), + } + + return convertRepo(hook.GetRepo()), build, nil +} + // parsePullHook parses a pull request hook and returns the Repo and Build // details. If the pull request is closed nil values are returned. func parsePullHook(hook *github.PullRequestEvent, merge bool) (*github.PullRequest, *model.Repo, *model.Build, error) { diff --git a/server/remote/github/parse_test.go b/server/remote/github/parse_test.go index 862a3c0a08..8e31aa65c2 100644 --- a/server/remote/github/parse_test.go +++ b/server/remote/github/parse_test.go @@ -18,6 +18,7 @@ import ( "bytes" "net/http" "sort" + "strings" "testing" "github.com/franela/goblin" @@ -27,10 +28,11 @@ import ( ) const ( - hookEvent = "X-Github-Event" - hookDeploy = "deployment" - hookPush = "push" - hookPull = "pull_request" + hookEvent = "X-Github-Event" + hookDeploy = "deployment" + hookPush = "push" + hookPull = "pull_request" + hookRelease = "release" ) func testHookRequest(payload []byte, event string) *http.Request { @@ -114,5 +116,19 @@ func Test_parser(t *testing.T) { g.Assert(b.Event).Equal(model.EventDeploy) }) }) + + g.Describe("given a release hook", func() { + g.It("should extract repository and build details", func() { + req := testHookRequest([]byte(fixtures.HookRelease), hookRelease) + p, r, b, err := parseHook(req, false) + g.Assert(err).IsNil() + g.Assert(r).IsNotNil() + g.Assert(b).IsNotNil() + g.Assert(p).IsNil() + g.Assert(b.Event).Equal(model.EventRelease) + g.Assert(len(strings.Split(b.Ref, "/")) == 3).IsTrue() + g.Assert(strings.HasPrefix(b.Ref, "refs/tags/")).IsTrue() + }) + }) }) } From adcae0be32f594c1a5f5f4847d02870f35a62dc4 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 8 Feb 2022 12:18:38 -0500 Subject: [PATCH 02/31] Auto commit @ 2022-02-08T17:18:38Z --- .vscode/settings.json | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 56977dd5e0..c0622716b9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,14 +9,5 @@ "go.lintTool":"golangci-lint", "go.lintFlags": [ "--fast" - ], - "spellright.language": [ - "en" - ], - "spellright.documentTypes": [ - "markdown", - "latex", - "plaintext", - "go" ] } From bb4b36a6b92e6a1ef9aae4750c24e6809ad0abd9 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 8 Feb 2022 12:21:36 -0500 Subject: [PATCH 03/31] Auto commit @ 2022-02-08T17:21:36Z --- server/remote/github/parse.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/remote/github/parse.go b/server/remote/github/parse.go index 5b5a65b52e..2c28541e31 100644 --- a/server/remote/github/parse.go +++ b/server/remote/github/parse.go @@ -166,7 +166,7 @@ func parseReleaseHook(hook *github.ReleaseEvent) (*model.Repo, *model.Build, err Message: release.GetBody(), // Use the body of the release. There is no message. Title: release.GetName(), // Tag name here is the ref. We should add the refs/tags so - // it is known is a tag (git-plugin looks for it) + // it is known its a tag (git-plugin looks for it) Ref: "refs/tags/" + release.GetTagName(), // Branch: *release.TagName, Dose not exist here. Github releases // is always a tag From 571b5d743328c659b324dea3bf893b2511c481eb Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 8 Feb 2022 14:56:55 -0500 Subject: [PATCH 04/31] Auto commit @ 2022-02-08T19:56:55Z From 1fbd411d7c8e0337ef5b3f849bd5f28c5230c4f3 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 8 Feb 2022 15:02:45 -0500 Subject: [PATCH 05/31] Auto commit @ 2022-02-08T20:02:45Z --- docs/docs/30-administration/20-vcs/10-overview.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/30-administration/20-vcs/10-overview.md b/docs/docs/30-administration/20-vcs/10-overview.md index 7ffd93a2c1..317f35389a 100644 --- a/docs/docs/30-administration/20-vcs/10-overview.md +++ b/docs/docs/30-administration/20-vcs/10-overview.md @@ -8,6 +8,7 @@ | Event: Tag | :white_check_mark: | :white_check_mark: | :white_check_mark: | | Event: Pull-Request | :white_check_mark: | :white_check_mark: | :white_check_mark: | | Event: Deploy | :white_check_mark: | :x: | :x: | +| Event: Release | :white_check_mark: | :x: | :x: | | OAuth | :white_check_mark: | :white_check_mark: | :white_check_mark: | | [Multi pipeline](/docs/usage/multi-pipeline) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | | [when-path filter](/docs/usage/conditional-execution#path) | :white_check_mark: | :white_check_mark:ยน | :white_check_mark: | :x: | :x: | :x: | :x: | From 3536eb038d566030dd8e01020782fed88831ce8a Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 8 Feb 2022 16:47:49 -0500 Subject: [PATCH 06/31] Auto commit @ 2022-02-08T21:47:49Z --- server/remote/github/parse.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/remote/github/parse.go b/server/remote/github/parse.go index 2c28541e31..d86610ff89 100644 --- a/server/remote/github/parse.go +++ b/server/remote/github/parse.go @@ -160,10 +160,9 @@ func parseReleaseHook(hook *github.ReleaseEvent) (*model.Repo, *model.Build, err // Cannot retrieve the commit since // it is hidden in the tag. It seems that github dose // not provide the commit SHA with a release. - ID: release.GetID(), Created: release.CreatedAt.UTC().Unix(), Link: release.GetURL(), - Message: release.GetBody(), // Use the body of the release. There is no message. + Message: release.GetName(), Title: release.GetName(), // Tag name here is the ref. We should add the refs/tags so // it is known its a tag (git-plugin looks for it) From c1a4680a8aa79562e1992d3b46f8c1422241c7ce Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 8 Feb 2022 16:55:25 -0500 Subject: [PATCH 07/31] Auto commit @ 2022-02-08T21:55:25Z --- server/remote/github/parse.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/remote/github/parse.go b/server/remote/github/parse.go index d86610ff89..1de2d3a8b6 100644 --- a/server/remote/github/parse.go +++ b/server/remote/github/parse.go @@ -162,7 +162,7 @@ func parseReleaseHook(hook *github.ReleaseEvent) (*model.Repo, *model.Build, err // not provide the commit SHA with a release. Created: release.CreatedAt.UTC().Unix(), Link: release.GetURL(), - Message: release.GetName(), + Message: "Release (" + hook.GetAction() + "):" + release.GetName(), // Use the body of the release. There is no message. Title: release.GetName(), // Tag name here is the ref. We should add the refs/tags so // it is known its a tag (git-plugin looks for it) From 351a429bed684d66a0b32cbcabd834659e0b85af Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 9 Feb 2022 19:03:02 -0500 Subject: [PATCH 08/31] Auto commit @ 2022-02-10T00:03:02Z From ac63f6a5aeb9b9c0ebba749e9fdc134208a1ae31 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 9 Feb 2022 19:03:25 -0500 Subject: [PATCH 09/31] Auto commit @ 2022-02-10T00:03:25Z From af5e7f5ae5f39b7f1ef89ec5340aa62187676bf5 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 9 Feb 2022 19:16:25 -0500 Subject: [PATCH 10/31] Auto commit @ 2022-02-10T00:16:25Z --- web/src/components/repo/settings/SecretsTab.vue | 4 ++++ web/src/lib/api/types/webhook.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/web/src/components/repo/settings/SecretsTab.vue b/web/src/components/repo/settings/SecretsTab.vue index c901209b43..b36d5ae250 100644 --- a/web/src/components/repo/settings/SecretsTab.vue +++ b/web/src/components/repo/settings/SecretsTab.vue @@ -100,6 +100,10 @@ const secretEventsOptions: CheckboxOption[] = [ description: 'Please be careful with this option as a bad actor can submit a malicious pull request that exposes your secrets.', }, + { + value: WebhookEvents.Release, + text: 'Release', + }, { value: WebhookEvents.Deploy, text: 'Deploy' }, ]; diff --git a/web/src/lib/api/types/webhook.ts b/web/src/lib/api/types/webhook.ts index 9b121f6574..7b1b318a5e 100644 --- a/web/src/lib/api/types/webhook.ts +++ b/web/src/lib/api/types/webhook.ts @@ -3,4 +3,5 @@ export enum WebhookEvents { Tag = 'tag', PullRequest = 'pull_request', Deploy = 'deployment', + Release = 'release', } From 7b8d1fcc9e0cdd84d129b3a5273a94616a7e6622 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 9 Feb 2022 19:31:53 -0500 Subject: [PATCH 11/31] Auto commit @ 2022-02-10T00:31:53Z --- server/model/const.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/model/const.go b/server/model/const.go index 0eef70e6f9..292ab42bda 100644 --- a/server/model/const.go +++ b/server/model/const.go @@ -26,7 +26,7 @@ const ( func ValidateWebhookEvent(s WebhookEvent) bool { switch s { - case EventPush, EventPull, EventTag, EventDeploy: + case EventPush, EventPull, EventTag, EventDeploy, EventRelease: return true default: return false From ac1e5bcec279e66d2dde42309347f98332626c73 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 9 Feb 2022 19:33:54 -0500 Subject: [PATCH 12/31] Auto commit @ 2022-02-10T00:33:54Z --- cli/secret/secret_add.go | 1 + pipeline/frontend/metadata.go | 9 +++++---- woodpecker-go/woodpecker/const.go | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cli/secret/secret_add.go b/cli/secret/secret_add.go index bed42d63e6..01bdde7891 100644 --- a/cli/secret/secret_add.go +++ b/cli/secret/secret_add.go @@ -77,5 +77,6 @@ func secretCreate(c *cli.Context) error { var defaultSecretEvents = []string{ woodpecker.EventPush, woodpecker.EventTag, + woodpecker.EventRelease, woodpecker.EventDeploy, } diff --git a/pipeline/frontend/metadata.go b/pipeline/frontend/metadata.go index 830af5c475..950a4c7860 100644 --- a/pipeline/frontend/metadata.go +++ b/pipeline/frontend/metadata.go @@ -10,10 +10,11 @@ import ( // Event types corresponding to scm hooks. const ( - EventPush = "push" - EventPull = "pull_request" - EventTag = "tag" - EventDeploy = "deployment" + EventPush = "push" + EventPull = "pull_request" + EventTag = "tag" + EventDeploy = "deployment" + EventRelease = "release" ) type ( diff --git a/woodpecker-go/woodpecker/const.go b/woodpecker-go/woodpecker/const.go index e77fb9c7fe..5ea6da85de 100644 --- a/woodpecker-go/woodpecker/const.go +++ b/woodpecker-go/woodpecker/const.go @@ -2,10 +2,11 @@ package woodpecker // Event values. const ( - EventPush = "push" - EventPull = "pull_request" - EventTag = "tag" - EventDeploy = "deployment" + EventPush = "push" + EventPull = "pull_request" + EventTag = "tag" + EventDeploy = "deployment" + EventRelease = "release" ) // Status values. From 6d8e019ba180478dfeffb630386166b5931f833c Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 16 Feb 2022 13:09:27 -0500 Subject: [PATCH 13/31] Auto commit @ 2022-02-16T18:09:27Z From 64ebd6eae3c32f32c5ef55061b43a382f5fd87c3 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 22 Feb 2022 11:15:12 -0500 Subject: [PATCH 14/31] Auto commit @ 2022-02-22T16:15:12Z From e38919cea731cd64275ad1a1bec3f5151c6a388e Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Mon, 28 Feb 2022 16:24:15 -0500 Subject: [PATCH 15/31] Auto commit @ 2022-02-28T21:24:15Z From 457069891723e72c893698a6816c20f4a9a17c1c Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Mon, 28 Feb 2022 18:02:48 -0500 Subject: [PATCH 16/31] Auto commit @ 2022-02-28T23:02:48Z From cc69a92c49335ebddd809e49e0a1d5be435fc593 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 1 Mar 2022 12:19:33 -0500 Subject: [PATCH 17/31] Auto commit @ 2022-03-01T17:19:33Z From 6965a38d652448709d2519bbdfd2b08b3eee2870 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 1 Mar 2022 12:52:50 -0500 Subject: [PATCH 18/31] Auto commit @ 2022-03-01T17:52:50Z --- cmd/server/flags.go | 6 +++ cmd/server/setup.go | 17 ++++--- .../30-administration/11-vcs/20-github.md | 14 ++++++ server/remote/github/github.go | 45 +++++++++++++------ server/remote/github/parse.go | 26 +++++++++-- 5 files changed, 87 insertions(+), 21 deletions(-) diff --git a/cmd/server/flags.go b/cmd/server/flags.go index 7a89ce7034..612529de2c 100644 --- a/cmd/server/flags.go +++ b/cmd/server/flags.go @@ -269,6 +269,12 @@ var flags = []cli.Flag{ Name: "github-skip-verify", Usage: "github skip ssl verification", }, + &cli.BoolFlag{ + EnvVars: []string{"WOODPECKER_GITHUB_RELEASE_ACTIONS"}, + Name: "github-release-actions", + Usage: "On which actions to trigger a release pipeline", + Value: "prereleased, released", + }, // // Gogs // diff --git a/cmd/server/setup.go b/cmd/server/setup.go index e021501a45..c5876d1954 100644 --- a/cmd/server/setup.go +++ b/cmd/server/setup.go @@ -19,6 +19,7 @@ import ( "fmt" "net/url" "os" + "regexp" "strings" "time" @@ -267,12 +268,18 @@ func setupGitlab(c *cli.Context) (remote.Remote, error) { // helper function to setup the GitHub remote from the CLI arguments. func setupGithub(c *cli.Context) (remote.Remote, error) { + releaseActions := []string{} + for _, action := range regexp.MustCompile(`[\s,]+`). + Split(c.String("github-release-actions"), -1) { + releaseActions = append(releaseActions, action) + } opts := github.Opts{ - URL: c.String("github-server"), - Client: c.String("github-client"), - Secret: c.String("github-secret"), - SkipVerify: c.Bool("github-skip-verify"), - MergeRef: c.Bool("github-merge-ref"), + URL: c.String("github-server"), + Client: c.String("github-client"), + Secret: c.String("github-secret"), + SkipVerify: c.Bool("github-skip-verify"), + MergeRef: c.Bool("github-merge-ref"), + ReleaseActions: releaseActions, } log.Trace().Msgf("Remote (github) opts: %#v", opts) return github.New(opts) diff --git a/docs/docs/30-administration/11-vcs/20-github.md b/docs/docs/30-administration/11-vcs/20-github.md index c6b599e8c3..549fb5543e 100644 --- a/docs/docs/30-administration/11-vcs/20-github.md +++ b/docs/docs/30-administration/11-vcs/20-github.md @@ -32,41 +32,55 @@ Please use this screenshot for reference: This is a full list of configuration options. Please note that many of these options use default configuration values that should work for the majority of installations. ### `WOODPECKER_GITHUB` + > Default: `false` Enables the GitHub driver. ### `WOODPECKER_GITHUB_URL` + > Default: `https://github.com` Configures the GitHub server address. ### `WOODPECKER_GITHUB_CLIENT` + > Default: empty Configures the GitHub OAuth client id. This is used to authorize access. ### `WOODPECKER_GITHUB_CLIENT_FILE` + > Default: empty Read the value for `WOODPECKER_GITHUB_CLIENT` from the specified filepath ### `WOODPECKER_GITHUB_SECRET` + > Default: empty Configures the GitHub OAuth client secret. This is used to authorize access. ### `WOODPECKER_GITHUB_SECRET_FILE` + > Default: empty Read the value for `WOODPECKER_GITHUB_SECRET` from the specified filepath ### `WOODPECKER_GITHUB_MERGE_REF` + > Default: `true` TODO ### `WOODPECKER_GITHUB_SKIP_VERIFY` + > Default: `false` Configure if SSL verification should be skipped. + +### `WOODPECKER_GITHUB_RELEASE_ACTIONS` + +> Default: `released, prereleased` + +The actions to allow on release (trigger), comma seperated. diff --git a/server/remote/github/github.go b/server/remote/github/github.go index 34b11a8bf3..049e17c6ae 100644 --- a/server/remote/github/github.go +++ b/server/remote/github/github.go @@ -41,6 +41,17 @@ const ( defaultAPI = "https://api.github.com/" // Default GitHub API URL ) +// Release events. +/* + published: a release, pre-release, or draft of a release is published + unpublished: a release or pre-release is deleted + created: a draft is saved, or a release or pre-release is published without previously being saved as a draft + edited: a release, pre-release, or draft release is edited + deleted: a release, pre-release, or draft release is deleted + prereleased: a pre-release is created + released: a release or draft of a release is published, or a pre-release is changed to a release +*/ + // Opts defines configuration options. type Opts struct { URL string // GitHub server url. @@ -48,18 +59,25 @@ type Opts struct { Secret string // GitHub oauth client secret. SkipVerify bool // Skip ssl verification. MergeRef bool // Clone pull requests using the merge ref. + + /* + On which actions to trigger a release. + Can be: published, unpublished, created, edited, deleted, prereleased, released + */ + ReleaseActions []string } // New returns a Remote implementation that integrates with a GitHub Cloud or // GitHub Enterprise version control hosting provider. func New(opts Opts) (remote.Remote, error) { r := &client{ - API: defaultAPI, - URL: defaultURL, - Client: opts.Client, - Secret: opts.Secret, - SkipVerify: opts.SkipVerify, - MergeRef: opts.MergeRef, + API: defaultAPI, + URL: defaultURL, + Client: opts.Client, + Secret: opts.Secret, + SkipVerify: opts.SkipVerify, + MergeRef: opts.MergeRef, + ReleaseActions: opts.ReleaseActions, } if opts.URL != defaultURL { r.URL = strings.TrimSuffix(opts.URL, "/") @@ -70,12 +88,13 @@ func New(opts Opts) (remote.Remote, error) { } type client struct { - URL string - API string - Client string - Secret string - SkipVerify bool - MergeRef bool + URL string + API string + Client string + Secret string + SkipVerify bool + MergeRef bool + ReleaseActions []string // On which actions to trigger a release. } // Login authenticates the session and returns the remote user details. @@ -479,7 +498,7 @@ func (c *client) Branches(ctx context.Context, u *model.User, r *model.Repo) ([] // Hook parses the post-commit hook from the Request body // and returns the required data in a standard format. func (c *client) Hook(ctx context.Context, r *http.Request) (*model.Repo, *model.Build, error) { - pull, repo, build, err := parseHook(r, c.MergeRef) + pull, repo, build, err := parseHook(r, c) if err != nil { return nil, nil, err } diff --git a/server/remote/github/parse.go b/server/remote/github/parse.go index 1de2d3a8b6..c38709afd2 100644 --- a/server/remote/github/parse.go +++ b/server/remote/github/parse.go @@ -40,7 +40,7 @@ const ( // parseHook parses a GitHub hook from an http.Request request and returns // Repo and Build detail. If a hook type is unsupported nil values are returned. -func parseHook(r *http.Request, merge bool) (*github.PullRequest, *model.Repo, *model.Build, error) { +func parseHook(r *http.Request, c *client) (*github.PullRequest, *model.Repo, *model.Build, error) { var reader io.Reader = r.Body if payload := r.FormValue(hookField); payload != "" { @@ -66,12 +66,30 @@ func parseHook(r *http.Request, merge bool) (*github.PullRequest, *model.Repo, * repo, build, err := parseDeployHook(hook) return nil, repo, build, err case *github.ReleaseEvent: + hasAction := false + for _, actionType := range c.ReleaseActions { + if actionType == *hook.Action { + hasAction = true + break + } + } + if !hasAction { + log.Debug(). + Str("Hook", webhookType). + Str("Action", *hook.Action). + Msg( + "Github release action ignored. " + + "See WOODPECKER_GITHUB_RELEASE_ACTIONS") + return nil, nil, nil, nil + } repo, build, err := parseReleaseHook(hook) return nil, repo, build, err case *github.PullRequestEvent: - return parsePullHook(hook, merge) + return parsePullHook(hook, c.MergeRef) default: - log.Debug().Msg("Github event ignored, and will not be parsed " + webhookType) + log.Debug(). + Str("Hook", webhookType). + Msg("Github event ignored, and will not be parsed") return nil, nil, nil, nil } } @@ -154,7 +172,9 @@ func parseDeployHook(hook *github.DeploymentEvent) (*model.Repo, *model.Build, e // If the commit type is unsupported nil values are returned. func parseReleaseHook(hook *github.ReleaseEvent) (*model.Repo, *model.Build, error) { release := hook.GetRelease() + build := &model.Build{ + Event: model.EventRelease, // Commit: "", // Cannot retrieve the commit since From 8a95a0b7d7fed50771d8ccc0ea0149f6424a2b25 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 1 Mar 2022 13:00:16 -0500 Subject: [PATCH 19/31] Auto commit @ 2022-03-01T18:00:16Z --- cmd/server/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/server/flags.go b/cmd/server/flags.go index 612529de2c..226c72ae85 100644 --- a/cmd/server/flags.go +++ b/cmd/server/flags.go @@ -269,7 +269,7 @@ var flags = []cli.Flag{ Name: "github-skip-verify", Usage: "github skip ssl verification", }, - &cli.BoolFlag{ + &cli.StringFlag{ EnvVars: []string{"WOODPECKER_GITHUB_RELEASE_ACTIONS"}, Name: "github-release-actions", Usage: "On which actions to trigger a release pipeline", From 04c5a0da5dc11caafe473223f43be5f652043cda Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 1 Mar 2022 19:11:36 -0500 Subject: [PATCH 20/31] Auto commit @ 2022-03-02T00:11:36Z --- server/remote/gitlab/convert.go | 45 +++++++++++++++++ server/remote/gitlab/gitlab.go | 5 +- server/remote/gitlab/gitlab_test.go | 23 +++++++++ server/remote/gitlab/testdata/hooks.go | 67 ++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 1 deletion(-) diff --git a/server/remote/gitlab/convert.go b/server/remote/gitlab/convert.go index 1e14bc08be..7b0d27f472 100644 --- a/server/remote/gitlab/convert.go +++ b/server/remote/gitlab/convert.go @@ -227,6 +227,51 @@ func convertTagHook(hook *gitlab.TagEvent) (*model.Repo, *model.Build, error) { return repo, build, nil } +func convertReleaseHook(hook *gitlab.ReleaseEvent) (*model.Repo, *model.Build, error) { + var err error + var repo_owner, repo_name string + if repo_owner, repo_name, err = extractFromPath(hook.Project.PathWithNamespace); err != nil { + return nil, nil, err + } + repo := &model.Repo{ + Name: repo_name, + Owner: repo_owner, + Avatar: *hook.Project.AvatarURL, + Link: hook.Project.WebURL, + Clone: hook.Project.GitHTTPURL, + FullName: hook.Project.PathWithNamespace, + Branch: hook.Project.DefaultBranch, + IsSCMPrivate: hook.Project.VisibilityLevel > 10, + } + + build := &model.Build{ + Event: model.EventRelease, + Commit: hook.Commit.ID, + Link: hook.URL, + Message: "Release (" + hook.Action + "):" + hook.Name, + Title: hook.Name, + Author: hook.Commit.Author.Name, + Email: hook.Commit.Author.Email, + + // Tag name here is the ref. We should add the refs/tags so + // it is known its a tag (git-plugin looks for it) + Ref: "refs/tags/" + hook.Tag, + + // Since release make the avatar the project avatar + Avatar: *hook.Project.AvatarURL, + } + + repo.IsSCMPrivate = false + if hook.Project.VisibilityLevel > 10 { + repo.IsSCMPrivate = true + } + + build.Commit = hook.Commit.ID + build.Title = hook.Name + + return repo, build, nil +} + func getUserAvatar(email string) string { hasher := md5.New() hasher.Write([]byte(email)) diff --git a/server/remote/gitlab/gitlab.go b/server/remote/gitlab/gitlab.go index 70be780ca8..03bf10f6ce 100644 --- a/server/remote/gitlab/gitlab.go +++ b/server/remote/gitlab/gitlab.go @@ -538,12 +538,15 @@ func (g *Gitlab) Hook(ctx context.Context, req *http.Request) (*model.Repo, *mod if build, err = g.loadChangedFilesFromMergeRequest(ctx, repo, build, mergeIID); err != nil { return nil, nil, err } - return repo, build, nil case *gitlab.PushEvent: return convertPushHook(event) case *gitlab.TagEvent: return convertTagHook(event) + case *gitlab.ReleaseEvent: + // will create a run for all release types. + // TODO: add support for event action filtering. + return convertReleaseHook(event) default: return nil, nil, nil } diff --git a/server/remote/gitlab/gitlab_test.go b/server/remote/gitlab/gitlab_test.go index 8a3ed7381b..dab21a6e60 100644 --- a/server/remote/gitlab/gitlab_test.go +++ b/server/remote/gitlab/gitlab_test.go @@ -227,6 +227,29 @@ func Test_Gitlab(t *testing.T) { } }) }) + + g.Describe("Release hook", func() { + g.It("Should parse merge request hook", func() { + req, _ := http.NewRequest( + testdata.ServiceHookMethod, + testdata.ServiceHookURL.String(), + bytes.NewReader(testdata.WebhookReleqaseBody), + ) + req.Header = testdata.ServiceHookHeaders + + // TODO: insert fake store into context to retrieve user & repo, this will activate fetching of ChangedFiles + hookRepo, build, err := client.Hook(ctx, req) + assert.NoError(t, err) + if assert.NotNil(t, hookRepo) && assert.NotNil(t, build) { + assert.Equal(t, "http://example.com/uploads/project/avatar/555/Outh-20-Logo.jpg", hookRepo.Avatar) + assert.Equal(t, "main", hookRepo.Branch) + assert.Equal(t, "anbraten", hookRepo.Owner) + assert.Equal(t, "woodpecker", hookRepo.Name) + assert.Equal(t, "Update client.go ๐ŸŽ‰", build.Title) + assert.Len(t, build.ChangedFiles, 0) // see L217 + } + }) + }) }) }) } diff --git a/server/remote/gitlab/testdata/hooks.go b/server/remote/gitlab/testdata/hooks.go index 7d39306b62..1f8570d01c 100644 --- a/server/remote/gitlab/testdata/hooks.go +++ b/server/remote/gitlab/testdata/hooks.go @@ -314,3 +314,70 @@ var WebhookMergeRequestBody = []byte(`{ ] } `) + +var WebhookReleqaseBody = []byte(` +{ + "id": 4268085, + "created_at": "2022-02-09 20:19:09 UTC", + "description": "new version desc", + "name": "Awesome version 0.0.2", + "released_at": "2022-02-09 20:19:09 UTC", + "tag": "0.0.2", + "object_kind": "release", + "project": { + "id": 32521798, + "name": "ci", + "description": "", + "web_url": "https://gitlab.com/anbratens-test/ci", + "avatar_url": null, + "git_ssh_url": "git@gitlab.com:anbratens-test/ci.git", + "git_http_url": "https://gitlab.com/anbratens-test/ci.git", + "namespace": "anbratens-test", + "visibility_level": 0, + "path_with_namespace": "anbratens-test/ci", + "default_branch": "main", + "ci_config_path": "", + "homepage": "https://gitlab.com/anbratens-test/ci", + "url": "git@gitlab.com:anbratens-test/ci.git", + "ssh_url": "git@gitlab.com:anbratens-test/ci.git", + "http_url": "https://gitlab.com/anbratens-test/ci.git" + }, + "url": "https://gitlab.com/anbratens-test/ci/-/releases/0.0.2", + "action": "create", + "assets": { + "count": 4, + "links": [ + + ], + "sources": [ + { + "format": "zip", + "url": "https://gitlab.com/anbratens-test/ci/-/archive/0.0.2/ci-0.0.2.zip" + }, + { + "format": "tar.gz", + "url": "https://gitlab.com/anbratens-test/ci/-/archive/0.0.2/ci-0.0.2.tar.gz" + }, + { + "format": "tar.bz2", + "url": "https://gitlab.com/anbratens-test/ci/-/archive/0.0.2/ci-0.0.2.tar.bz2" + }, + { + "format": "tar", + "url": "https://gitlab.com/anbratens-test/ci/-/archive/0.0.2/ci-0.0.2.tar" + } + ] + }, + "commit": { + "id": "0b8c02955ba445ea70d22824d9589678852e2b93", + "message": "Initial commit", + "title": "Initial commit", + "timestamp": "2022-01-03T10:39:51+00:00", + "url": "https://gitlab.com/anbratens-test/ci/-/commit/0b8c02955ba445ea70d22824d9589678852e2b93", + "author": { + "name": "Anbraten", + "email": "2251488-anbraten@users.noreply.gitlab.com" + } + } +} +`) From 2abcd3cea9e39afa37c56e74fd4224f0a23bae90 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Tue, 1 Mar 2022 19:38:27 -0500 Subject: [PATCH 21/31] Auto commit @ 2022-03-02T00:38:27Z --- server/remote/gitea/fixtures/hooks.go | 76 ++++++++++++++ server/remote/gitea/helper.go | 47 ++++++--- server/remote/gitea/helper_test.go | 4 +- server/remote/gitea/parse.go | 27 ++++- server/remote/gitea/parse_test.go | 13 +++ server/remote/gitea/types.go | 146 +++++++++++++------------- 6 files changed, 221 insertions(+), 92 deletions(-) diff --git a/server/remote/gitea/fixtures/hooks.go b/server/remote/gitea/fixtures/hooks.go index 30f1905326..4be723b7c9 100644 --- a/server/remote/gitea/fixtures/hooks.go +++ b/server/remote/gitea/fixtures/hooks.go @@ -157,3 +157,79 @@ const HookPullRequest = `{ "avatar_url": "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87" } }` + +const HookRelease = ` +{ + "action": "published", + "release": { + "id": 48, + "tag_name": "0.0.5", + "target_commitish": "main", + "name": "Version 0.0.5", + "body": "", + "url": "https://git.xxx/api/v1/repos/anbraten/demo/releases/48", + "html_url": "https://git.xxx/anbraten/demo/releases/tag/0.0.5", + "tarball_url": "https://git.xxx/anbraten/demo/archive/0.0.5.tar.gz", + "zipball_url": "https://git.xxx/anbraten/demo/archive/0.0.5.zip", + "draft": false, + "prerelease": false, + "created_at": "2022-02-09T20:23:05Z", + "published_at": "2022-02-09T20:23:05Z", + "author": {"id":1,"login":"anbraten","full_name":"Anton Bracke","email":"anbraten@noreply.xxx","avatar_url":"https://git.xxx/user/avatar/anbraten/-1","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2018-03-21T10:04:48Z","restricted":false,"active":false,"prohibit_login":false,"location":"world","website":"https://xxx","description":"","visibility":"public","followers_count":1,"following_count":1,"starred_repos_count":1,"username":"anbraten"}, + "assets": [] + }, + "repository": { + "id": 77, + "owner": {"id":1,"login":"anbraten","full_name":"Anton Bracke","email":"anbraten@noreply.xxx","avatar_url":"https://git.xxx/user/avatar/anbraten/-1","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2018-03-21T10:04:48Z","restricted":false,"active":false,"prohibit_login":false,"location":"world","website":"https://xxx","description":"","visibility":"public","followers_count":1,"following_count":1,"starred_repos_count":1,"username":"anbraten"}, + "name": "demo", + "full_name": "anbraten/demo", + "description": "", + "empty": false, + "private": true, + "fork": false, + "template": false, + "parent": null, + "mirror": false, + "size": 59, + "html_url": "https://git.xxx/anbraten/demo", + "ssh_url": "ssh://git@git.xxx:22/anbraten/demo.git", + "clone_url": "https://git.xxx/anbraten/demo.git", + "original_url": "", + "website": "", + "stars_count": 0, + "forks_count": 1, + "watchers_count": 1, + "open_issues_count": 2, + "open_pr_counter": 2, + "release_counter": 4, + "default_branch": "main", + "archived": false, + "created_at": "2021-08-30T20:54:13Z", + "updated_at": "2022-01-09T01:29:23Z", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "has_issues": true, + "internal_tracker": { + "enable_time_tracker": true, + "allow_only_contributors_to_track_time": true, + "enable_issue_dependencies": true + }, + "has_wiki": false, + "has_pull_requests": true, + "has_projects": true, + "ignore_whitespace_conflicts": false, + "allow_merge_commits": true, + "allow_rebase": true, + "allow_rebase_explicit": true, + "allow_squash_merge": true, + "default_merge_style": "squash", + "avatar_url": "", + "internal": false, + "mirror_interval": "" + }, + "sender": {"id":1,"login":"anbraten","full_name":"Anbraten","email":"anbraten@noreply.xxx","avatar_url":"https://git.xxx/user/avatar/anbraten/-1","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2018-03-21T10:04:48Z","restricted":false,"active":false,"prohibit_login":false,"location":"World","website":"https://xxx","description":"","visibility":"public","followers_count":1,"following_count":1,"starred_repos_count":1,"username":"anbraten"} +} +` diff --git a/server/remote/gitea/helper.go b/server/remote/gitea/helper.go index 1132bb33b8..f92a984694 100644 --- a/server/remote/gitea/helper.go +++ b/server/remote/gitea/helper.go @@ -176,23 +176,40 @@ func buildFromPullRequest(hook *pullRequestHook) *model.Build { return build } -// helper function that extracts the Repository data from a Gitea push hook -func repoFromPush(hook *pushHook) *model.Repo { - return &model.Repo{ - Name: hook.Repo.Name, - Owner: hook.Repo.Owner.Username, - FullName: hook.Repo.FullName, - Link: hook.Repo.URL, +func buildFromRelease(hook *releaseHook) *model.Build { + avatar := expandAvatar( + hook.Repo.URL, + fixMalformedAvatar(hook.Sender.Avatar), + ) + author := hook.Sender.Login + if author == "" { + author = hook.Sender.Username + } + sender := hook.Sender.Username + if sender == "" { + sender = hook.Sender.Login + } + + return &model.Build{ + Event: model.EventRelease, + Ref: fmt.Sprintf("refs/tags/%s", hook.Release.TagName), + Link: fmt.Sprintf("%s/src/tag/%s", hook.Repo.URL, hook.Release.TagName), + Branch: fmt.Sprintf("refs/tags/%s", hook.Release.TagName), + Message: fmt.Sprintf("created tag %s", hook.Release.TagName), + Avatar: avatar, + Author: author, + Sender: sender, + Timestamp: time.Now().UTC().Unix(), } } // helper function that extracts the Repository data from a Gitea pull_request hook -func repoFromPullRequest(hook *pullRequestHook) *model.Repo { +func repoFromHook(repo *giteaRepo) *model.Repo { return &model.Repo{ - Name: hook.Repo.Name, - Owner: hook.Repo.Owner.Username, - FullName: hook.Repo.FullName, - Link: hook.Repo.URL, + Name: repo.Name, + Owner: repo.Owner.Username, + FullName: repo.FullName, + Link: repo.URL, } } @@ -209,6 +226,12 @@ func parsePullRequest(r io.Reader) (*pullRequestHook, error) { return pr, err } +func parseRelease(r io.Reader) (*releaseHook, error) { + pr := new(releaseHook) + err := json.NewDecoder(r).Decode(pr) + return pr, err +} + // fixMalformedAvatar is a helper function that fixes an avatar url if malformed // (currently a known bug with gitea) func fixMalformedAvatar(url string) string { diff --git a/server/remote/gitea/helper_test.go b/server/remote/gitea/helper_test.go index f462b54f5e..48b488ed4d 100644 --- a/server/remote/gitea/helper_test.go +++ b/server/remote/gitea/helper_test.go @@ -113,7 +113,7 @@ func Test_parse(t *testing.T) { g.It("Should return a Repo struct from a push hook", func() { buf := bytes.NewBufferString(fixtures.HookPush) hook, _ := parsePush(buf) - repo := repoFromPush(hook) + repo := repoFromHook(&hook.Repo) g.Assert(repo.Name).Equal(hook.Repo.Name) g.Assert(repo.Owner).Equal(hook.Repo.Owner.Username) g.Assert(repo.FullName).Equal("gordon/hello-world") @@ -150,7 +150,7 @@ func Test_parse(t *testing.T) { g.It("Should return a Repo struct from a pull_request hook", func() { buf := bytes.NewBufferString(fixtures.HookPullRequest) hook, _ := parsePullRequest(buf) - repo := repoFromPullRequest(hook) + repo := repoFromHook(&hook.Repo) g.Assert(repo.Name).Equal(hook.Repo.Name) g.Assert(repo.Owner).Equal(hook.Repo.Owner.Username) g.Assert(repo.FullName).Equal("gordon/hello-world") diff --git a/server/remote/gitea/parse.go b/server/remote/gitea/parse.go index 3869cff0f4..10ee0bdd09 100644 --- a/server/remote/gitea/parse.go +++ b/server/remote/gitea/parse.go @@ -26,6 +26,7 @@ const ( hookEvent = "X-Gitea-Event" hookPush = "push" hookCreated = "create" + hookRelease = "release" hookPullRequest = "pull_request" actionOpen = "opened" @@ -47,7 +48,10 @@ func parseHook(r *http.Request) (*model.Repo, *model.Build, error) { return parseCreatedHook(r.Body) case hookPullRequest: return parsePullRequestHook(r.Body) + case hookRelease: + return parseReleaseHook(r.Body) } + return nil, nil, nil } @@ -69,7 +73,7 @@ func parsePushHook(payload io.Reader) (repo *model.Repo, build *model.Build, err return nil, nil, nil } - repo = repoFromPush(push) + repo = repoFromHook(&push.Repo) build = buildFromPush(push) return repo, build, err } @@ -86,7 +90,7 @@ func parseCreatedHook(payload io.Reader) (repo *model.Repo, build *model.Build, return nil, nil, nil } - repo = repoFromPush(push) + repo = repoFromHook(&push.Repo) build = buildFromTag(push) return repo, build, nil } @@ -111,7 +115,24 @@ func parsePullRequestHook(payload io.Reader) (*model.Repo, *model.Build, error) return nil, nil, nil } - repo = repoFromPullRequest(pr) + repo = repoFromHook(&pr.Repo) build = buildFromPullRequest(pr) return repo, build, err } + +// parsePullRequestHook parses a pull_request hook and returns the Repo and Build details. +func parseReleaseHook(payload io.Reader) (*model.Repo, *model.Build, error) { + var ( + repo *model.Repo + build *model.Build + ) + + release, err := parseRelease(payload) + if err != nil { + return nil, nil, err + } + + repo = repoFromHook(&release.Repo) + build = buildFromRelease(release) + return repo, build, err +} diff --git a/server/remote/gitea/parse_test.go b/server/remote/gitea/parse_test.go index 3193fd593a..9a9fad14f3 100644 --- a/server/remote/gitea/parse_test.go +++ b/server/remote/gitea/parse_test.go @@ -53,5 +53,18 @@ func Test_parser(t *testing.T) { g.Assert(utils.EqualStringSlice(b.ChangedFiles, []string{"CHANGELOG.md", "app/controller/application.rb"})).IsTrue() }) }) + g.Describe("given a release hook", func() { + g.It("should extract repository and build details", func() { + buf := bytes.NewBufferString(fixtures.HookRelease) + req, _ := http.NewRequest("POST", "/hook", buf) + req.Header = http.Header{} + req.Header.Set(hookEvent, hookRelease) + r, b, err := parseHook(req) + g.Assert(err).IsNil() + g.Assert(r).IsNotNil() + g.Assert(b).IsNotNil() + g.Assert(b.Event).Equal(model.EventRelease) + }) + }) }) } diff --git a/server/remote/gitea/types.go b/server/remote/gitea/types.go index e7c87cadb6..b381c8f3df 100644 --- a/server/remote/gitea/types.go +++ b/server/remote/gitea/types.go @@ -14,6 +14,34 @@ package gitea +type giteaUser struct { + ID int64 `json:"id"` + Username string `json:"username"` + Name string `json:"name"` + FullName string `json:"full_name"` + Email string `json:"email"` + Login string `json:"login"` + Avatar string `json:"avatar_url"` +} + +type giteaRepo struct { + ID int64 `json:"id"` + Name string `json:"name"` + FullName string `json:"full_name"` + URL string `json:"html_url"` + Private bool `json:"private"` + Owner giteaUser `json:"owner,omitempty"` +} + +type giteaSender struct { + ID int64 `json:"id"` + Login string `json:"login"` + Username string `json:"username"` + Name string `json:"full_name"` + Email string `json:"email"` + Avatar string `json:"avatar_url"` +} + type pushHook struct { Sha string `json:"sha"` Ref string `json:"ref"` @@ -22,25 +50,9 @@ type pushHook struct { Compare string `json:"compare_url"` RefType string `json:"ref_type"` - Pusher struct { - Name string `json:"name"` - Email string `json:"email"` - Login string `json:"login"` - Username string `json:"username"` - } `json:"pusher"` - - Repo struct { - ID int64 `json:"id"` - Name string `json:"name"` - FullName string `json:"full_name"` - URL string `json:"html_url"` - Private bool `json:"private"` - Owner struct { - Name string `json:"name"` - Email string `json:"email"` - Username string `json:"username"` - } `json:"owner"` - } `json:"repository"` + Sender giteaSender `json:"sender"` + Repo giteaRepo `json:"repository"` + Pusher giteaUser `json:"pusher"` Commits []struct { ID string `json:"id"` @@ -50,19 +62,14 @@ type pushHook struct { Removed []string `json:"removed"` Modified []string `json:"modified"` } `json:"commits"` - - Sender struct { - ID int64 `json:"id"` - Login string `json:"login"` - Username string `json:"username"` - Email string `json:"email"` - Avatar string `json:"avatar_url"` - } `json:"sender"` } type pullRequestHook struct { - Action string `json:"action"` - Number int64 `json:"number"` + Action string `json:"action"` + Number int64 `json:"number"` + Repo giteaRepo `json:"repository"` + Sender giteaSender `json:"sender"` + PullRequest struct { ID int64 `json:"id"` User struct { @@ -84,18 +91,12 @@ type pullRequestHook struct { Ref string `json:"ref"` Sha string `json:"sha"` Repo struct { - ID int64 `json:"id"` - Name string `json:"name"` - FullName string `json:"full_name"` - URL string `json:"html_url"` - Private bool `json:"private"` - Owner struct { - ID int64 `json:"id"` - Username string `json:"username"` - Name string `json:"full_name"` - Email string `json:"email"` - Avatar string `json:"avatar_url"` - } `json:"owner"` + ID int64 `json:"id"` + Name string `json:"name"` + FullName string `json:"full_name"` + URL string `json:"html_url"` + Private bool `json:"private"` + Owner giteaUser `json:"owner"` } `json:"repo"` } `json:"base"` Head struct { @@ -103,41 +104,36 @@ type pullRequestHook struct { Ref string `json:"ref"` Sha string `json:"sha"` Repo struct { - ID int64 `json:"id"` - Name string `json:"name"` - FullName string `json:"full_name"` - URL string `json:"html_url"` - Private bool `json:"private"` - Owner struct { - ID int64 `json:"id"` - Username string `json:"username"` - Name string `json:"full_name"` - Email string `json:"email"` - Avatar string `json:"avatar_url"` - } `json:"owner"` + ID int64 `json:"id"` + Name string `json:"name"` + FullName string `json:"full_name"` + URL string `json:"html_url"` + Private bool `json:"private"` + Owner giteaUser `json:"owner"` } `json:"repo"` } `json:"head"` } `json:"pull_request"` - Repo struct { - ID int64 `json:"id"` - Name string `json:"name"` - FullName string `json:"full_name"` - URL string `json:"html_url"` - Private bool `json:"private"` - Owner struct { - ID int64 `json:"id"` - Username string `json:"username"` - Name string `json:"full_name"` - Email string `json:"email"` - Avatar string `json:"avatar_url"` - } `json:"owner"` - } `json:"repository"` - Sender struct { - ID int64 `json:"id"` - Login string `json:"login"` - Username string `json:"username"` - Name string `json:"full_name"` - Email string `json:"email"` - Avatar string `json:"avatar_url"` - } `json:"sender"` +} + +type releaseHook struct { + Action string `json:"action"` + Repo giteaRepo `json:"repository"` + Sender giteaSender `json:"sender"` + Release struct { + ID int64 `json:"id"` + TagName string `json:"tag_name"` + TargetCommitish string `json:"target_commitish"` + Name string `json:"name"` + Body string `json:"body"` + URL string `json:"url"` + HTMLURL string `json:"html_url"` + TarballURL string `json:"tarball_url"` + ZipballURL string `json:"zipball_url"` + Draft bool `json:"draft"` + Prerelease bool `json:"prerelease"` + CreatedAt string `json:"created_at"` + PublishedAt string `json:"published_at"` + Assets []string `json:"assets"` + Author giteaUser `json:"author"` + } } From 58853d41f5d7b33fe6dbfbeb5d82559384679309 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 2 Mar 2022 12:02:32 -0500 Subject: [PATCH 22/31] Auto commit @ 2022-03-02T17:02:32Z --- server/remote/gitlab/convert.go | 12 +----------- server/remote/gitlab/gitlab.go | 10 +++++++++- server/remote/gitlab/gitlab_test.go | 17 +++++++---------- server/remote/gitlab/testdata/hooks.go | 7 ++++++- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/server/remote/gitlab/convert.go b/server/remote/gitlab/convert.go index 7b0d27f472..7a9d576442 100644 --- a/server/remote/gitlab/convert.go +++ b/server/remote/gitlab/convert.go @@ -228,15 +228,8 @@ func convertTagHook(hook *gitlab.TagEvent) (*model.Repo, *model.Build, error) { } func convertReleaseHook(hook *gitlab.ReleaseEvent) (*model.Repo, *model.Build, error) { - var err error - var repo_owner, repo_name string - if repo_owner, repo_name, err = extractFromPath(hook.Project.PathWithNamespace); err != nil { - return nil, nil, err - } repo := &model.Repo{ - Name: repo_name, - Owner: repo_owner, - Avatar: *hook.Project.AvatarURL, + Name: hook.Project.Name, Link: hook.Project.WebURL, Clone: hook.Project.GitHTTPURL, FullName: hook.Project.PathWithNamespace, @@ -256,9 +249,6 @@ func convertReleaseHook(hook *gitlab.ReleaseEvent) (*model.Repo, *model.Build, e // Tag name here is the ref. We should add the refs/tags so // it is known its a tag (git-plugin looks for it) Ref: "refs/tags/" + hook.Tag, - - // Since release make the avatar the project avatar - Avatar: *hook.Project.AvatarURL, } repo.IsSCMPrivate = false diff --git a/server/remote/gitlab/gitlab.go b/server/remote/gitlab/gitlab.go index 03bf10f6ce..b25703667d 100644 --- a/server/remote/gitlab/gitlab.go +++ b/server/remote/gitlab/gitlab.go @@ -21,6 +21,7 @@ import ( "io/ioutil" "net/http" "net/url" + "reflect" "strings" "github.com/rs/zerolog/log" @@ -523,13 +524,17 @@ func (g *Gitlab) Hook(ctx context.Context, req *http.Request) (*model.Repo, *mod return nil, nil, err } - parsed, err := gitlab.ParseWebhook(gitlab.WebhookEventType(req), payload) + gitlabEventType := gitlab.WebhookEventType(req) + println("Received event: " + gitlabEventType) + parsed, err := gitlab.ParseWebhook(gitlabEventType, payload) + println("Parsed event: ", parsed) if err != nil { return nil, nil, err } switch event := parsed.(type) { case *gitlab.MergeEvent: + println("Processing merge hook: " + reflect.TypeOf(*event).Name()) mergeIID, repo, build, err := convertMergeRequestHook(event, req) if err != nil { return nil, nil, err @@ -540,10 +545,13 @@ func (g *Gitlab) Hook(ctx context.Context, req *http.Request) (*model.Repo, *mod } return repo, build, nil case *gitlab.PushEvent: + println("Processing push hook: " + reflect.TypeOf(*event).Name()) return convertPushHook(event) case *gitlab.TagEvent: + println("Processing tag hook: " + reflect.TypeOf(*event).Name()) return convertTagHook(event) case *gitlab.ReleaseEvent: + println("Processing release hook: " + reflect.TypeOf(*event).Name()) // will create a run for all release types. // TODO: add support for event action filtering. return convertReleaseHook(event) diff --git a/server/remote/gitlab/gitlab_test.go b/server/remote/gitlab/gitlab_test.go index dab21a6e60..a01952e4a5 100644 --- a/server/remote/gitlab/gitlab_test.go +++ b/server/remote/gitlab/gitlab_test.go @@ -228,25 +228,22 @@ func Test_Gitlab(t *testing.T) { }) }) - g.Describe("Release hook", func() { - g.It("Should parse merge request hook", func() { + g.Describe("Release request hook", func() { + g.It("Should parse release request hook", func() { req, _ := http.NewRequest( testdata.ServiceHookMethod, testdata.ServiceHookURL.String(), - bytes.NewReader(testdata.WebhookReleqaseBody), + bytes.NewReader(testdata.WebhookReleaseBody), ) - req.Header = testdata.ServiceHookHeaders + req.Header = testdata.ReleaseHookHeaders // TODO: insert fake store into context to retrieve user & repo, this will activate fetching of ChangedFiles hookRepo, build, err := client.Hook(ctx, req) assert.NoError(t, err) if assert.NotNil(t, hookRepo) && assert.NotNil(t, build) { - assert.Equal(t, "http://example.com/uploads/project/avatar/555/Outh-20-Logo.jpg", hookRepo.Avatar) - assert.Equal(t, "main", hookRepo.Branch) - assert.Equal(t, "anbraten", hookRepo.Owner) - assert.Equal(t, "woodpecker", hookRepo.Name) - assert.Equal(t, "Update client.go ๐ŸŽ‰", build.Title) - assert.Len(t, build.ChangedFiles, 0) // see L217 + assert.Equal(t, "refs/tags/0.0.2", build.Ref) + assert.Equal(t, "ci", hookRepo.Name) + assert.Equal(t, "Awesome version 0.0.2", build.Title) } }) }) diff --git a/server/remote/gitlab/testdata/hooks.go b/server/remote/gitlab/testdata/hooks.go index 1f8570d01c..86b1c75117 100644 --- a/server/remote/gitlab/testdata/hooks.go +++ b/server/remote/gitlab/testdata/hooks.go @@ -29,6 +29,11 @@ var ( "User-Agent": []string{"GitLab/14.3.0"}, "X-Gitlab-Event": []string{"Service Hook"}, } + ReleaseHookHeaders = http.Header{ + "Content-Type": []string{"application/json"}, + "User-Agent": []string{"GitLab/14.3.0"}, + "X-Gitlab-Event": []string{"Release Hook"}, + } ) // ServiceHookPushBody is payload of ServiceHook: Push @@ -315,7 +320,7 @@ var WebhookMergeRequestBody = []byte(`{ } `) -var WebhookReleqaseBody = []byte(` +var WebhookReleaseBody = []byte(` { "id": 4268085, "created_at": "2022-02-09 20:19:09 UTC", From 9a2764d9937e04717c236cc9dd1aa41a073b0675 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 2 Mar 2022 12:03:45 -0500 Subject: [PATCH 23/31] Auto commit @ 2022-03-02T17:03:45Z From b71ef6095345a2e72d1eea143022c0cc7a1276a5 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 2 Mar 2022 12:15:14 -0500 Subject: [PATCH 24/31] Auto commit @ 2022-03-02T17:15:14Z --- server/remote/github/fixtures/hooks.go | 2 +- server/remote/github/parse.go | 1 + server/remote/github/parse_test.go | 20 ++++++++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/server/remote/github/fixtures/hooks.go b/server/remote/github/fixtures/hooks.go index e84ed8b48e..74a85acb8a 100644 --- a/server/remote/github/fixtures/hooks.go +++ b/server/remote/github/fixtures/hooks.go @@ -357,7 +357,7 @@ const HookDeploy = ` // https://developer.github.com/v3/activity/events/types/#release const HookRelease = ` { - "action": "published", + "action": "released", "release": { "url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/releases/2", "assets_url": "https://octocoders.github.io/api/v3/repos/Codertocat/Hello-World/releases/2/assets", diff --git a/server/remote/github/parse.go b/server/remote/github/parse.go index c38709afd2..5a45d191e9 100644 --- a/server/remote/github/parse.go +++ b/server/remote/github/parse.go @@ -67,6 +67,7 @@ func parseHook(r *http.Request, c *client) (*github.PullRequest, *model.Repo, *m return nil, repo, build, err case *github.ReleaseEvent: hasAction := false + println(*hook.Action) for _, actionType := range c.ReleaseActions { if actionType == *hook.Action { hasAction = true diff --git a/server/remote/github/parse_test.go b/server/remote/github/parse_test.go index 8e31aa65c2..8a9f726e57 100644 --- a/server/remote/github/parse_test.go +++ b/server/remote/github/parse_test.go @@ -46,9 +46,13 @@ func testHookRequest(payload []byte, event string) *http.Request { func Test_parser(t *testing.T) { g := goblin.Goblin(t) g.Describe("GitHub parser", func() { + client := &client{ + ReleaseActions: []string{"released", "prereleased"}, + MergeRef: false, + } g.It("should ignore unsupported hook events", func() { req := testHookRequest([]byte(fixtures.HookPullRequest), "issues") - p, r, b, err := parseHook(req, false) + p, r, b, err := parseHook(req, client) g.Assert(r).IsNil() g.Assert(b).IsNil() g.Assert(err).IsNil() @@ -58,7 +62,7 @@ func Test_parser(t *testing.T) { g.Describe("given a push hook", func() { g.It("should skip when action is deleted", func() { req := testHookRequest([]byte(fixtures.HookPushDeleted), hookPush) - p, r, b, err := parseHook(req, false) + p, r, b, err := parseHook(req, client) g.Assert(r).IsNil() g.Assert(b).IsNil() g.Assert(err).IsNil() @@ -66,7 +70,7 @@ func Test_parser(t *testing.T) { }) g.It("should extract repository and build details", func() { req := testHookRequest([]byte(fixtures.HookPush), hookPush) - p, r, b, err := parseHook(req, false) + p, r, b, err := parseHook(req, client) g.Assert(err).IsNil() g.Assert(p).IsNil() g.Assert(r).IsNotNil() @@ -80,7 +84,7 @@ func Test_parser(t *testing.T) { g.Describe("given a pull request hook", func() { g.It("should skip when action is not open or sync", func() { req := testHookRequest([]byte(fixtures.HookPullRequestInvalidAction), hookPull) - p, r, b, err := parseHook(req, false) + p, r, b, err := parseHook(req, client) g.Assert(r).IsNil() g.Assert(b).IsNil() g.Assert(err).IsNil() @@ -88,7 +92,7 @@ func Test_parser(t *testing.T) { }) g.It("should skip when state is not open", func() { req := testHookRequest([]byte(fixtures.HookPullRequestInvalidState), hookPull) - p, r, b, err := parseHook(req, false) + p, r, b, err := parseHook(req, client) g.Assert(r).IsNil() g.Assert(b).IsNil() g.Assert(err).IsNil() @@ -96,7 +100,7 @@ func Test_parser(t *testing.T) { }) g.It("should extract repository and build details", func() { req := testHookRequest([]byte(fixtures.HookPullRequest), hookPull) - p, r, b, err := parseHook(req, false) + p, r, b, err := parseHook(req, client) g.Assert(err).IsNil() g.Assert(r).IsNotNil() g.Assert(b).IsNotNil() @@ -108,7 +112,7 @@ func Test_parser(t *testing.T) { g.Describe("given a deployment hook", func() { g.It("should extract repository and build details", func() { req := testHookRequest([]byte(fixtures.HookDeploy), hookDeploy) - p, r, b, err := parseHook(req, false) + p, r, b, err := parseHook(req, client) g.Assert(err).IsNil() g.Assert(r).IsNotNil() g.Assert(b).IsNotNil() @@ -120,7 +124,7 @@ func Test_parser(t *testing.T) { g.Describe("given a release hook", func() { g.It("should extract repository and build details", func() { req := testHookRequest([]byte(fixtures.HookRelease), hookRelease) - p, r, b, err := parseHook(req, false) + p, r, b, err := parseHook(req, client) g.Assert(err).IsNil() g.Assert(r).IsNotNil() g.Assert(b).IsNotNil() From e8336cb8e9e13a341979f44940d5fa9b9975c6af Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 2 Mar 2022 13:47:06 -0500 Subject: [PATCH 25/31] Auto commit @ 2022-03-02T18:47:06Z From aeba27d9b546fbba6853e5b44ce2d9810cec2764 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 2 Mar 2022 19:30:46 -0500 Subject: [PATCH 26/31] Auto commit @ 2022-03-03T00:30:46Z --- cmd/server/setup.go | 10 +++++----- server/remote/github/parse.go | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cmd/server/setup.go b/cmd/server/setup.go index c5876d1954..926d262812 100644 --- a/cmd/server/setup.go +++ b/cmd/server/setup.go @@ -268,11 +268,10 @@ func setupGitlab(c *cli.Context) (remote.Remote, error) { // helper function to setup the GitHub remote from the CLI arguments. func setupGithub(c *cli.Context) (remote.Remote, error) { - releaseActions := []string{} - for _, action := range regexp.MustCompile(`[\s,]+`). - Split(c.String("github-release-actions"), -1) { - releaseActions = append(releaseActions, action) - } + releaseActions := regexp. + MustCompile(`[\s,]+`). + Split(c.String("github-release-actions"), -1) + opts := github.Opts{ URL: c.String("github-server"), Client: c.String("github-client"), @@ -281,6 +280,7 @@ func setupGithub(c *cli.Context) (remote.Remote, error) { MergeRef: c.Bool("github-merge-ref"), ReleaseActions: releaseActions, } + log.Trace().Msgf("Remote (github) opts: %#v", opts) return github.New(opts) } diff --git a/server/remote/github/parse.go b/server/remote/github/parse.go index 5a45d191e9..347fd82358 100644 --- a/server/remote/github/parse.go +++ b/server/remote/github/parse.go @@ -175,7 +175,6 @@ func parseReleaseHook(hook *github.ReleaseEvent) (*model.Repo, *model.Build, err release := hook.GetRelease() build := &model.Build{ - Event: model.EventRelease, // Commit: "", // Cannot retrieve the commit since From cfd70e5ccf840924eeebe607556c5bf4f5f167b2 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 2 Mar 2022 19:31:15 -0500 Subject: [PATCH 27/31] Auto commit @ 2022-03-03T00:31:15Z From 973b3186cad43acdd17a7666bd31b877bb530528 Mon Sep 17 00:00:00 2001 From: Zav Shotan Date: Wed, 2 Mar 2022 21:22:25 -0500 Subject: [PATCH 28/31] Auto commit @ 2022-03-03T02:22:25Z --- pipeline/frontend/metadata.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline/frontend/metadata.go b/pipeline/frontend/metadata.go index 964cb4e188..37c7a39ff7 100644 --- a/pipeline/frontend/metadata.go +++ b/pipeline/frontend/metadata.go @@ -204,7 +204,7 @@ func (m *Metadata) Environ() map[string]string { "CI_TAG": "", // use CI_COMMIT_TAG "CI_PULL_REQUEST": "", // use CI_COMMIT_PULL_REQUEST } - if m.Curr.Event == EventTag { + if m.Curr.Event == EventTag || m.Curr.Event == EventRelease { params["CI_COMMIT_TAG"] = strings.TrimPrefix(m.Curr.Commit.Ref, "refs/tags/") params["CI_TAG"] = params["CI_COMMIT_TAG"] } From 17676a913434bbcf0b8ac6359c4e932a153f8e0e Mon Sep 17 00:00:00 2001 From: Zav Shotan <3694482+LamaAni@users.noreply.github.com> Date: Thu, 3 Mar 2022 13:06:23 -0500 Subject: [PATCH 29/31] Update docs/docs/30-administration/11-vcs/10-overview.md Co-authored-by: 6543 <6543@obermui.de> --- docs/docs/30-administration/11-vcs/10-overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/30-administration/11-vcs/10-overview.md b/docs/docs/30-administration/11-vcs/10-overview.md index a9a7b44d9d..893fe6c070 100644 --- a/docs/docs/30-administration/11-vcs/10-overview.md +++ b/docs/docs/30-administration/11-vcs/10-overview.md @@ -8,7 +8,7 @@ | Event: Tag | :white_check_mark: | :white_check_mark: | :white_check_mark: | | Event: Pull-Request | :white_check_mark: | :white_check_mark: | :white_check_mark: | | Event: Deploy | :white_check_mark: | :x: | :x: | -| Event: Release | :white_check_mark: | :x: | :x: | +| Event: Release | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | OAuth | :white_check_mark: | :white_check_mark: | :white_check_mark: | | [Multi pipeline](/docs/usage/multi-pipeline) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | | [when.path filter](/docs/usage/conditional-execution#path) | :white_check_mark: | :white_check_mark:ยน | :white_check_mark: | :x: | :x: | :x: | :x: | From dd401c8ee438701306f3f167a368c9caca60f80b Mon Sep 17 00:00:00 2001 From: Zav Shotan <3694482+LamaAni@users.noreply.github.com> Date: Thu, 3 Mar 2022 13:10:31 -0500 Subject: [PATCH 30/31] Update server/remote/gitea/helper.go Co-authored-by: 6543 <6543@obermui.de> --- server/remote/gitea/helper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/remote/gitea/helper.go b/server/remote/gitea/helper.go index f92a984694..b446c51c96 100644 --- a/server/remote/gitea/helper.go +++ b/server/remote/gitea/helper.go @@ -195,7 +195,7 @@ func buildFromRelease(hook *releaseHook) *model.Build { Ref: fmt.Sprintf("refs/tags/%s", hook.Release.TagName), Link: fmt.Sprintf("%s/src/tag/%s", hook.Repo.URL, hook.Release.TagName), Branch: fmt.Sprintf("refs/tags/%s", hook.Release.TagName), - Message: fmt.Sprintf("created tag %s", hook.Release.TagName), + Message: fmt.Sprintf("created release %s", hook.Release.TagName), <- release Title? Avatar: avatar, Author: author, Sender: sender, From cfc2d835eff605e1dc9f3738cc006f3a786f1292 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 3 Mar 2022 19:18:07 +0100 Subject: [PATCH 31/31] Update server/remote/gitea/helper.go --- server/remote/gitea/helper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/remote/gitea/helper.go b/server/remote/gitea/helper.go index b446c51c96..1f35b184f2 100644 --- a/server/remote/gitea/helper.go +++ b/server/remote/gitea/helper.go @@ -195,7 +195,7 @@ func buildFromRelease(hook *releaseHook) *model.Build { Ref: fmt.Sprintf("refs/tags/%s", hook.Release.TagName), Link: fmt.Sprintf("%s/src/tag/%s", hook.Repo.URL, hook.Release.TagName), Branch: fmt.Sprintf("refs/tags/%s", hook.Release.TagName), - Message: fmt.Sprintf("created release %s", hook.Release.TagName), <- release Title? + Message: fmt.Sprintf("created release %s", hook.Release.Name), Avatar: avatar, Author: author, Sender: sender,