From 9b851087ad9a2ebb502fcad9c8bf79747e4fe7c2 Mon Sep 17 00:00:00 2001 From: Anbraten Date: Tue, 30 Jan 2024 19:46:55 +0100 Subject: [PATCH 01/22] Update pipeline list UI --- .../components/repo/pipeline/PipelineItem.vue | 54 ++++++++++++------- web/src/compositions/usePipeline.ts | 8 +-- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/web/src/components/repo/pipeline/PipelineItem.vue b/web/src/components/repo/pipeline/PipelineItem.vue index 7023bbfae7..526ae069c6 100644 --- a/web/src/components/repo/pipeline/PipelineItem.vue +++ b/web/src/components/repo/pipeline/PipelineItem.vue @@ -1,8 +1,8 @@ diff --git a/web/src/compositions/usePipeline.ts b/web/src/compositions/usePipeline.ts index 29458af4de..1a4117b15b 100644 --- a/web/src/compositions/usePipeline.ts +++ b/web/src/compositions/usePipeline.ts @@ -27,14 +27,15 @@ export default (pipeline: Ref) => { const i18n = useI18n(); const since = computed(() => { if (sinceRaw.value === 0) { - return i18n.t('time.not_started'); + // return i18n.t('time.not_started'); + return '-'; } if (sinceElapsed.value === undefined) { return null; } - // TODO check whetehr elapsed works + // TODO check whether elapsed works return timeAgo(sinceElapsed.value); }); @@ -67,7 +68,8 @@ export default (pipeline: Ref) => { } if (durationRaw.value === 0) { - return i18n.t('time.not_started'); + return '-'; + // return i18n.t('time.not_started'); } return prettyDuration(durationElapsed.value); From 9bfd2f3e847383ca9a7fdf370f18d1ebfdfc0ba7 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 21 Feb 2024 16:41:51 +0100 Subject: [PATCH 02/22] gitea parse email too --- server/forge/gitea/fixtures/hooks.go | 6 +++--- server/forge/gitea/helper.go | 2 ++ server/forge/gitea/parse_test.go | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/forge/gitea/fixtures/hooks.go b/server/forge/gitea/fixtures/hooks.go index a551f91c33..a70e5722db 100644 --- a/server/forge/gitea/fixtures/hooks.go +++ b/server/forge/gitea/fixtures/hooks.go @@ -726,7 +726,7 @@ const HookPullRequestClosed = ` "login": "anbraten", "login_name": "", "full_name": "", - "email": "anbraten@noreply.gitea.com", + "email": "anbraten@gitea.com", "avatar_url": "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", "language": "", "is_admin": false, @@ -964,7 +964,7 @@ const HookPullRequestClosed = ` "login": "anbraten", "login_name": "", "full_name": "", - "email": "anbraten@noreply.gitea.com", + "email": "anbraten@repo.gitea.com", "avatar_url": "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", "language": "", "is_admin": false, @@ -1049,7 +1049,7 @@ const HookPullRequestClosed = ` "login": "anbraten", "login_name": "", "full_name": "", - "email": "anbraten@noreply.gitea.com", + "email": "anbraten@sender.gitea.com", "avatar_url": "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", "language": "", "is_admin": false, diff --git a/server/forge/gitea/helper.go b/server/forge/gitea/helper.go index 4383638c23..417a0711b9 100644 --- a/server/forge/gitea/helper.go +++ b/server/forge/gitea/helper.go @@ -138,6 +138,7 @@ func pipelineFromTag(hook *pushHook) *model.Pipeline { Avatar: avatar, Author: hook.Sender.UserName, Sender: hook.Sender.UserName, + Email: hook.Sender.Email, Timestamp: time.Now().UTC().Unix(), } } @@ -164,6 +165,7 @@ func pipelineFromPullRequest(hook *pullRequestHook) *model.Pipeline { Author: hook.PullRequest.Poster.UserName, Avatar: avatar, Sender: hook.Sender.UserName, + Email: hook.Sender.Email, Title: hook.PullRequest.Title, Refspec: fmt.Sprintf("%s:%s", hook.PullRequest.Head.Ref, diff --git a/server/forge/gitea/parse_test.go b/server/forge/gitea/parse_test.go index bda8e6b564..f5c918d912 100644 --- a/server/forge/gitea/parse_test.go +++ b/server/forge/gitea/parse_test.go @@ -54,6 +54,7 @@ func Test_parser(t *testing.T) { g.Assert(r).IsNotNil() g.Assert(b).IsNotNil() g.Assert(b.Event).Equal(model.EventPush) + assert.EqualValues(t, "6543@obermui.de", b.Email) g.Assert(b.Message).Equal("Delete '.woodpecker/.check.yml'\n") g.Assert(b.ChangedFiles).Equal([]string{".woodpecker/.check.yml"}) }) @@ -68,6 +69,7 @@ func Test_parser(t *testing.T) { g.Assert(r).IsNotNil() g.Assert(b).IsNotNil() g.Assert(b.Event).Equal(model.EventPush) + assert.EqualValues(t, "gordon@golang.org", b.Email) g.Assert(utils.EqualSliceValues(b.ChangedFiles, []string{"CHANGELOG.md", "app/controller/application.rb"})).IsTrue() }) }) @@ -83,6 +85,7 @@ func Test_parser(t *testing.T) { g.Assert(b).IsNotNil() g.Assert(err).IsNil() g.Assert(b.Event).Equal(model.EventTag) + assert.EqualValues(t, "gordon@golang.org", b.Email) }) }) @@ -97,6 +100,7 @@ func Test_parser(t *testing.T) { r, b, err := parseHook(req) g.Assert(r).IsNotNil() g.Assert(b).IsNotNil() + assert.EqualValues(t, "gordon@golang.org", b.Email) g.Assert(err).IsNil() g.Assert(b.Event).Equal(model.EventPull) }) @@ -109,6 +113,7 @@ func Test_parser(t *testing.T) { r, b, err := parseHook(req) g.Assert(r).IsNotNil() g.Assert(b).IsNotNil() + assert.EqualValues(t, "anbraten@sender.gitea.com", b.Email) g.Assert(err).IsNil() g.Assert(b.Event).Equal(model.EventPullClosed) }) From d07b161114f494a62ca85061dafbfd32a6234297 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 21 Feb 2024 16:50:18 +0100 Subject: [PATCH 03/22] example how tests should be --- server/forge/gitea/parse_test.go | 46 +++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/server/forge/gitea/parse_test.go b/server/forge/gitea/parse_test.go index f5c918d912..9639ce8c64 100644 --- a/server/forge/gitea/parse_test.go +++ b/server/forge/gitea/parse_test.go @@ -29,7 +29,7 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/shared/utils" ) -func Test_parser(t *testing.T) { +func TestGiteaParser(t *testing.T) { g := goblin.Goblin(t) g.Describe("Gitea parser", func() { g.It("should ignore unsupported hook events", func() { @@ -49,14 +49,42 @@ func Test_parser(t *testing.T) { req, _ := http.NewRequest("POST", "/hook", buf) req.Header = http.Header{} req.Header.Set(hookEvent, hookPush) - r, b, err := parseHook(req) - g.Assert(err).IsNil() - g.Assert(r).IsNotNil() - g.Assert(b).IsNotNil() - g.Assert(b.Event).Equal(model.EventPush) - assert.EqualValues(t, "6543@obermui.de", b.Email) - g.Assert(b.Message).Equal("Delete '.woodpecker/.check.yml'\n") - g.Assert(b.ChangedFiles).Equal([]string{".woodpecker/.check.yml"}) + r, p, err := parseHook(req) + if assert.NoError(t, err) { + assert.EqualValues(t, &model.Repo{ + ForgeRemoteID: "50820", + Owner: "meisam", + Name: "woodpecktester", + FullName: "meisam/woodpecktester", + Avatar: "https://codeberg.org/avatars/96512da76a14cf44e0bb32d1640e878e", + ForgeURL: "https://codeberg.org/meisam/woodpecktester", + Clone: "https://codeberg.org/meisam/woodpecktester.git", + CloneSSH: "git@codeberg.org:meisam/woodpecktester.git", + Branch: "main", + SCMKind: "git", + PREnabled: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, r) + p.Timestamp = 0 + assert.EqualValues(t, &model.Pipeline{ + Author: "6543", + Event: "push", + Commit: "28c3613ae62640216bea5e7dc71aa65356e4298b", + Branch: "fdsafdsa", + Ref: "refs/heads/fdsafdsa", + Message: "Delete '.woodpecker/.check.yml'\n", + Sender: "6543", + Avatar: "https://codeberg.org/avatars/09a234c768cb9bca78f6b2f82d6af173", + Email: "6543@obermui.de", + ForgeURL: "https://codeberg.org/meisam/woodpecktester/compare/main...28c3613ae62640216bea5e7dc71aa65356e4298b", + ChangedFiles: []string{".woodpecker/.check.yml"}, + Title: "", // TODO! + }, p) + } }) g.It("should extract repository and pipeline details", func() { From fb627dba49e1e0fc24008bd7cd0abd84a36010db Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 22 Feb 2024 01:01:57 +0100 Subject: [PATCH 04/22] fix similar bugs --- server/forge/gitea/helper.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/forge/gitea/helper.go b/server/forge/gitea/helper.go index 417a0711b9..d147c97f0d 100644 --- a/server/forge/gitea/helper.go +++ b/server/forge/gitea/helper.go @@ -81,12 +81,12 @@ func pipelineFromPush(hook *pushHook) *model.Pipeline { link := hook.Compare if len(hook.Commits) > 0 { message = hook.Commits[0].Message + if len(hook.Commits) == 1 { + link = hook.Commits[0].URL + } } else { message = hook.HeadCommit.Message - } - - if len(hook.Commits) == 1 { - link = hook.Commits[0].URL + link = hook.HeadCommit.URL } return &model.Pipeline{ @@ -158,7 +158,7 @@ func pipelineFromPullRequest(hook *pullRequestHook) *model.Pipeline { pipeline := &model.Pipeline{ Event: event, Commit: hook.PullRequest.Head.Sha, - ForgeURL: hook.PullRequest.URL, + ForgeURL: hook.PullRequest.HTMLURL, Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number), Branch: hook.PullRequest.Base.Ref, Message: hook.PullRequest.Title, @@ -192,6 +192,7 @@ func pipelineFromRelease(hook *releaseHook) *model.Pipeline { Avatar: avatar, Author: hook.Sender.UserName, Sender: hook.Sender.UserName, + Email: hook.Sender.Email, IsPrerelease: hook.Release.IsPrerelease, } } From 0cf1fb656e117f606bc1ab9147c3b0eeb7d436b5 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 22 Feb 2024 01:03:05 +0100 Subject: [PATCH 05/22] tests tests tests --- server/forge/gitea/fixtures/hooks.go | 206 +++++++++++++++++++++- server/forge/gitea/parse_test.go | 254 +++++++++++++++++++++++---- 2 files changed, 423 insertions(+), 37 deletions(-) diff --git a/server/forge/gitea/fixtures/hooks.go b/server/forge/gitea/fixtures/hooks.go index a70e5722db..06104226a7 100644 --- a/server/forge/gitea/fixtures/hooks.go +++ b/server/forge/gitea/fixtures/hooks.go @@ -75,6 +75,203 @@ const HookPush = ` } ` +// HookPushMulti push multible commits to a branch +const HookPushMulti = ` +{ + "ref": "refs/heads/main", + "before": "6efcf5b7c98f3e7a491675164b7a2e7acac27941", + "after": "29be01c073851cf0db0c6a466e396b725a670453", + "compare_url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets/compare/6efcf5b7c98f3e7a491675164b7a2e7acac27941...29be01c073851cf0db0c6a466e396b725a670453", + "commits": [ + { + "id": "29be01c073851cf0db0c6a466e396b725a670453", + "message": "add some text\n", + "url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets/commit/29be01c073851cf0db0c6a466e396b725a670453", + "author": { + "name": "6543", + "email": "6543@obermui.de", + "username": "test-user" + }, + "committer": { + "name": "6543", + "email": "6543@obermui.de", + "username": "test-user" + }, + "verification": null, + "timestamp": "2024-02-22T00:18:07+01:00", + "added": [], + "removed": [], + "modified": [ + "aaa" + ] + }, + { + "id": "29cd95250404bd007c13b03eabe521196bab98a5", + "message": "rm a a file\n", + "url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets/commit/29cd95250404bd007c13b03eabe521196bab98a5", + "author": { + "name": "6543", + "email": "6543@obermui.de", + "username": "test-user" + }, + "committer": { + "name": "6543", + "email": "6543@obermui.de", + "username": "test-user" + }, + "verification": null, + "timestamp": "2024-02-22T00:17:49+01:00", + "added": [], + "removed": [ + "aa" + ], + "modified": [] + }, + { + "id": "93787b87b3134d0d62c7a24c1ea5b1b6fd17ca91", + "message": "add some a files\n", + "url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets/commit/93787b87b3134d0d62c7a24c1ea5b1b6fd17ca91", + "author": { + "name": "6543", + "email": "6543@obermui.de", + "username": "test-user" + }, + "committer": { + "name": "6543", + "email": "6543@obermui.de", + "username": "test-user" + }, + "verification": null, + "timestamp": "2024-02-22T00:17:33+01:00", + "added": [ + "aa", + "aaa" + ], + "removed": [], + "modified": [] + } + ], + "total_commits": 3, + "head_commit": { + "id": "29be01c073851cf0db0c6a466e396b725a670453", + "message": "add some text\n", + "url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets/commit/29be01c073851cf0db0c6a466e396b725a670453", + "author": { + "name": "6543", + "email": "6543@obermui.de", + "username": "test-user" + }, + "committer": { + "name": "6543", + "email": "6543@obermui.de", + "username": "test-user" + }, + "verification": null, + "timestamp": "2024-02-22T00:18:07+01:00", + "added": [], + "removed": [], + "modified": [ + "aaa" + ] + }, + "repository": { + "id": 6, + "owner": { + "id": 2, + "login": "Test-CI", + "login_name": "", + "full_name": "", + "email": "", + "avatar_url": "http://127.0.0.1:3000/avatars/5b0a83c2185b3cb1ebceb11062d6c2eb", + "language": "", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2023-07-31T19:13:48+02:00", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "Test-CI" + }, + "name": "multi-line-secrets", + "full_name": "Test-CI/multi-line-secrets", + "description": "", + "empty": false, + "private": false, + "fork": false, + "template": false, + "parent": null, + "mirror": false, + "size": 35, + "language": "", + "languages_url": "http://127.0.0.1:3000/api/v1/repos/Test-CI/multi-line-secrets/languages", + "html_url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets", + "url": "http://127.0.0.1:3000/api/v1/repos/Test-CI/multi-line-secrets", + "link": "", + "ssh_url": "ssh://git@127.0.0.1:2200/Test-CI/multi-line-secrets.git", + "clone_url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets.git", + "original_url": "", + "website": "", + "watchers_count": 2, + "open_issues_count": 1, + "default_branch": "main", + "archived": false, + "created_at": "2023-10-31T19:53:15+01:00", + "updated_at": "2023-11-02T06:16:34+01:00", + "archived_at": "1970-01-01T01:00:00+01:00", + "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 + }, + "avatar_url": "", + "object_format_name": "" + }, + "pusher": { + "id": 1, + "login": "test-user", + "login_name": "", + "full_name": "", + "email": "test@noreply.localhost", + "avatar_url": "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2023-07-31T19:13:05+02:00", + "prohibit_login": false, + "description": "", + "visibility": "public", + "username": "test-user" + }, + "sender": { + "id": 1, + "login": "test-user", + "login_name": "", + "full_name": "", + "email": "test@noreply.localhost", + "avatar_url": "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2023-07-31T19:13:05+02:00", + "prohibit_login": false, + "description": "", + "visibility": "public", + "username": "test-user" + } +} +` + // HookPushBranch is a sample Gitea push hook where a new branch was created from an existing commit const HookPushBranch = ` { @@ -226,8 +423,7 @@ const HookPushBranch = ` "starred_repos_count": 55, "username": "6543" } -} -` +}` // HookTag is a sample Gitea tag hook const HookTag = `{ @@ -236,9 +432,9 @@ const HookTag = `{ "ref": "v1.0.0", "ref_type": "tag", "repository": { - "id": 1, + "id": 12, "owner": { - "id": 1, + "id": 4, "username": "gordon", "login": "gordon", "full_name": "Gordon the Gopher", @@ -247,7 +443,7 @@ const HookTag = `{ }, "name": "hello-world", "full_name": "gordon/hello-world", - "description": "", + "description": "a hello world example", "private": true, "fork": false, "html_url": "http://gitea.golang.org/gordon/hello-world", diff --git a/server/forge/gitea/parse_test.go b/server/forge/gitea/parse_test.go index 9639ce8c64..b6d381b772 100644 --- a/server/forge/gitea/parse_test.go +++ b/server/forge/gitea/parse_test.go @@ -26,7 +26,6 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/server/forge/gitea/fixtures" "go.woodpecker-ci.org/woodpecker/v2/server/forge/types" "go.woodpecker-ci.org/woodpecker/v2/server/model" - "go.woodpecker-ci.org/woodpecker/v2/shared/utils" ) func TestGiteaParser(t *testing.T) { @@ -80,9 +79,8 @@ func TestGiteaParser(t *testing.T) { Sender: "6543", Avatar: "https://codeberg.org/avatars/09a234c768cb9bca78f6b2f82d6af173", Email: "6543@obermui.de", - ForgeURL: "https://codeberg.org/meisam/woodpecktester/compare/main...28c3613ae62640216bea5e7dc71aa65356e4298b", + ForgeURL: "https://codeberg.org/meisam/woodpecktester/commit/28c3613ae62640216bea5e7dc71aa65356e4298b", ChangedFiles: []string{".woodpecker/.check.yml"}, - Title: "", // TODO! }, p) } }) @@ -92,13 +90,81 @@ func TestGiteaParser(t *testing.T) { req, _ := http.NewRequest("POST", "/hook", buf) req.Header = http.Header{} req.Header.Set(hookEvent, hookPush) - r, b, err := parseHook(req) - g.Assert(err).IsNil() - g.Assert(r).IsNotNil() - g.Assert(b).IsNotNil() - g.Assert(b.Event).Equal(model.EventPush) - assert.EqualValues(t, "gordon@golang.org", b.Email) - g.Assert(utils.EqualSliceValues(b.ChangedFiles, []string{"CHANGELOG.md", "app/controller/application.rb"})).IsTrue() + r, p, err := parseHook(req) + if assert.NoError(t, err) { + assert.EqualValues(t, &model.Repo{ + ForgeRemoteID: "1", + Owner: "gordon", + Name: "hello-world", + FullName: "gordon/hello-world", + Avatar: "http://gitea.golang.org/gordon/hello-world", + ForgeURL: "http://gitea.golang.org/gordon/hello-world", + Clone: "http://gitea.golang.org/gordon/hello-world.git", + CloneSSH: "git@gitea.golang.org:gordon/hello-world.git", + SCMKind: "git", + IsSCMPrivate: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, r) + p.Timestamp = 0 + assert.EqualValues(t, &model.Pipeline{ + Author: "gordon", + Event: "push", + Commit: "ef98532add3b2feb7a137426bba1248724367df5", + Branch: "main", + Ref: "refs/heads/main", + Message: "bump\n", + Sender: "gordon", + Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + Email: "gordon@golang.org", + ForgeURL: "http://gitea.golang.org/gordon/hello-world/commit/ef98532add3b2feb7a137426bba1248724367df5", + ChangedFiles: []string{"CHANGELOG.md", "app/controller/application.rb"}, + }, p) + } + }) + + g.It("should handle multi commit push", func() { + buf := bytes.NewBufferString(fixtures.HookPushMulti) + req, _ := http.NewRequest("POST", "/hook", buf) + req.Header = http.Header{} + req.Header.Set(hookEvent, hookPush) + r, p, err := parseHook(req) + if assert.NoError(t, err) { + assert.EqualValues(t, &model.Repo{ + ForgeRemoteID: "6", + Owner: "Test-CI", + Name: "multi-line-secrets", + FullName: "Test-CI/multi-line-secrets", + Avatar: "http://127.0.0.1:3000/avatars/5b0a83c2185b3cb1ebceb11062d6c2eb", + ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets", + Clone: "http://127.0.0.1:3000/Test-CI/multi-line-secrets.git", + CloneSSH: "ssh://git@127.0.0.1:2200/Test-CI/multi-line-secrets.git", + Branch: "main", + SCMKind: "git", + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, r) + p.Timestamp = 0 + assert.EqualValues(t, &model.Pipeline{ + Author: "test-user", + Event: "push", + Commit: "29be01c073851cf0db0c6a466e396b725a670453", + Branch: "main", + Ref: "refs/heads/main", + Message: "add some text\n", + Sender: "test-user", + Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", + Email: "test@noreply.localhost", + ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/compare/6efcf5b7c98f3e7a491675164b7a2e7acac27941...29be01c073851cf0db0c6a466e396b725a670453", + ChangedFiles: []string{"aaa", "aa"}, + }, p) + } }) }) @@ -125,12 +191,43 @@ func TestGiteaParser(t *testing.T) { req, _ := http.NewRequest("POST", "/hook", buf) req.Header = http.Header{} req.Header.Set(hookEvent, hookPullRequest) - r, b, err := parseHook(req) - g.Assert(r).IsNotNil() - g.Assert(b).IsNotNil() - assert.EqualValues(t, "gordon@golang.org", b.Email) - g.Assert(err).IsNil() - g.Assert(b.Event).Equal(model.EventPull) + r, p, err := parseHook(req) + if assert.NoError(t, err) { + assert.EqualValues(t, &model.Repo{ + ForgeRemoteID: "35129377", + Owner: "gordon", + Name: "hello-world", + FullName: "gordon/hello-world", + Avatar: "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + ForgeURL: "http://gitea.golang.org/gordon/hello-world", + Clone: "https://gitea.golang.org/gordon/hello-world.git", + CloneSSH: "", + Branch: "main", + SCMKind: "git", + IsSCMPrivate: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, r) + p.Timestamp = 0 + assert.EqualValues(t, &model.Pipeline{ + Author: "gordon", + Event: "pull_request", + Commit: "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c", + Branch: "main", + Ref: "refs/pull/1/head", + Refspec: "feature/changes:main", + Title: "Update the README with new information", + Message: "Update the README with new information", + Sender: "gordon", + Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + Email: "gordon@golang.org", + ForgeURL: "http://gitea.golang.org/gordon/hello-world/pull/1", + PullRequestLabels: []string{}, + }, p) + } }) g.It("should handle a PR closed hook when PR got closed", func() { @@ -138,12 +235,43 @@ func TestGiteaParser(t *testing.T) { req, _ := http.NewRequest("POST", "/hook", buf) req.Header = http.Header{} req.Header.Set(hookEvent, hookPullRequest) - r, b, err := parseHook(req) - g.Assert(r).IsNotNil() - g.Assert(b).IsNotNil() - assert.EqualValues(t, "anbraten@sender.gitea.com", b.Email) - g.Assert(err).IsNil() - g.Assert(b.Event).Equal(model.EventPullClosed) + r, p, err := parseHook(req) + if assert.NoError(t, err) { + assert.EqualValues(t, &model.Repo{ + ForgeRemoteID: "46534", + Owner: "anbraten", + Name: "test-repo", + FullName: "anbraten/test-repo", + Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", + ForgeURL: "https://gitea.com/anbraten/test-repo", + Clone: "https://gitea.com/anbraten/test-repo.git", + CloneSSH: "git@gitea.com:anbraten/test-repo.git", + Branch: "main", + SCMKind: "git", + PREnabled: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, r) + p.Timestamp = 0 + assert.EqualValues(t, &model.Pipeline{ + Author: "anbraten", + Event: "pull_request_closed", + Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", + Branch: "main", + Ref: "refs/pull/1/head", + Refspec: "anbraten-patch-1:main", + Title: "Adjust file", + Message: "Adjust file", + Sender: "anbraten", + Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", + Email: "anbraten@sender.gitea.com", + ForgeURL: "https://gitea.com/anbraten/test-repo/pulls/1", + PullRequestLabels: []string{}, + }, p) + } }) g.It("should handle a PR closed hook when PR was merged", func() { @@ -151,22 +279,84 @@ func TestGiteaParser(t *testing.T) { req, _ := http.NewRequest("POST", "/hook", buf) req.Header = http.Header{} req.Header.Set(hookEvent, hookPullRequest) - r, b, err := parseHook(req) - g.Assert(r).IsNotNil() - g.Assert(b).IsNotNil() - g.Assert(err).IsNil() - g.Assert(b.Event).Equal(model.EventPullClosed) + r, p, err := parseHook(req) + if assert.NoError(t, err) { + assert.EqualValues(t, &model.Repo{ + ForgeRemoteID: "46534", + Owner: "anbraten", + Name: "test-repo", + FullName: "anbraten/test-repo", + Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", + ForgeURL: "https://gitea.com/anbraten/test-repo", + Clone: "https://gitea.com/anbraten/test-repo.git", + CloneSSH: "git@gitea.com:anbraten/test-repo.git", + Branch: "main", + SCMKind: "git", + PREnabled: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, r) + p.Timestamp = 0 + assert.EqualValues(t, &model.Pipeline{ + Author: "anbraten", + Event: "pull_request_closed", + Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", + Branch: "main", + Ref: "refs/pull/1/head", + Refspec: "anbraten-patch-1:main", + Title: "Adjust file", + Message: "Adjust file", + Sender: "anbraten", + Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", + Email: "anbraten@noreply.gitea.com", + ForgeURL: "https://gitea.com/anbraten/test-repo/pulls/1", + PullRequestLabels: []string{}, + }, p) + } }) + g.It("should handle release hook", 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) + r, p, err := parseHook(req) + if assert.NoError(t, err) { + assert.EqualValues(t, &model.Repo{ + ForgeRemoteID: "77", + Owner: "anbraten", + Name: "demo", + FullName: "anbraten/demo", + Avatar: "https://git.xxx/user/avatar/anbraten/-1", + ForgeURL: "https://git.xxx/anbraten/demo", + Clone: "https://git.xxx/anbraten/demo.git", + CloneSSH: "ssh://git@git.xxx:22/anbraten/demo.git", + Branch: "main", + SCMKind: "git", + PREnabled: true, + IsSCMPrivate: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, r) + p.Timestamp = 0 + assert.EqualValues(t, &model.Pipeline{ + Author: "anbraten", + Event: "release", + Branch: "main", + Ref: "refs/tags/0.0.5", + Message: "created release Version 0.0.5", + Sender: "anbraten", + Avatar: "https://git.xxx/user/avatar/anbraten/-1", + Email: "anbraten@noreply.xxx", + ForgeURL: "https://git.xxx/anbraten/demo/releases/tag/0.0.5", + }, p) + } }) }) }) From 55441bff301a5963f4fa2054c61d4e61be6a7327 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 22 Feb 2024 01:29:11 +0100 Subject: [PATCH 06/22] move old tests to new tests --- server/forge/gitea/parse_test.go | 323 ++++++++++++++++--------------- 1 file changed, 172 insertions(+), 151 deletions(-) diff --git a/server/forge/gitea/parse_test.go b/server/forge/gitea/parse_test.go index b6d381b772..3f1025def5 100644 --- a/server/forge/gitea/parse_test.go +++ b/server/forge/gitea/parse_test.go @@ -29,160 +29,181 @@ import ( ) func TestGiteaParser(t *testing.T) { - g := goblin.Goblin(t) - g.Describe("Gitea parser", func() { - g.It("should ignore unsupported hook events", func() { - buf := bytes.NewBufferString(fixtures.HookPullRequest) - req, _ := http.NewRequest("POST", "/hook", buf) - req.Header = http.Header{} - req.Header.Set(hookEvent, "issues") - r, b, err := parseHook(req) - g.Assert(r).IsNil() - g.Assert(b).IsNil() - assert.ErrorIs(t, err, &types.ErrIgnoreEvent{}) - }) + tests := []struct { + name string + data string + event string + err error + repo *model.Repo + pipe *model.Pipeline + }{ + { + name: "should ignore unsupported hook events", + data: fixtures.HookPullRequest, + event: "issues", + err: &types.ErrIgnoreEvent{}, + }, + { + name: "push event should handle a push hook", + data: fixtures.HookPushBranch, + event: "push", + repo: &model.Repo{ + ForgeRemoteID: "50820", + Owner: "meisam", + Name: "woodpecktester", + FullName: "meisam/woodpecktester", + Avatar: "https://codeberg.org/avatars/96512da76a14cf44e0bb32d1640e878e", + ForgeURL: "https://codeberg.org/meisam/woodpecktester", + Clone: "https://codeberg.org/meisam/woodpecktester.git", + CloneSSH: "git@codeberg.org:meisam/woodpecktester.git", + Branch: "main", + SCMKind: "git", + PREnabled: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, + pipe: &model.Pipeline{ + Author: "6543", + Event: "push", + Commit: "28c3613ae62640216bea5e7dc71aa65356e4298b", + Branch: "fdsafdsa", + Ref: "refs/heads/fdsafdsa", + Message: "Delete '.woodpecker/.check.yml'\n", + Sender: "6543", + Avatar: "https://codeberg.org/avatars/09a234c768cb9bca78f6b2f82d6af173", + Email: "6543@obermui.de", + ForgeURL: "https://codeberg.org/meisam/woodpecktester/commit/28c3613ae62640216bea5e7dc71aa65356e4298b", + ChangedFiles: []string{".woodpecker/.check.yml"}, + }, + }, + { + name: "push event should extract repository and pipeline details", + data: fixtures.HookPush, + event: "push", + repo: &model.Repo{ + ForgeRemoteID: "1", + Owner: "gordon", + Name: "hello-world", + FullName: "gordon/hello-world", + Avatar: "http://gitea.golang.org/gordon/hello-world", + ForgeURL: "http://gitea.golang.org/gordon/hello-world", + Clone: "http://gitea.golang.org/gordon/hello-world.git", + CloneSSH: "git@gitea.golang.org:gordon/hello-world.git", + SCMKind: "git", + IsSCMPrivate: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, + pipe: &model.Pipeline{ + Author: "gordon", + Event: "push", + Commit: "ef98532add3b2feb7a137426bba1248724367df5", + Branch: "main", + Ref: "refs/heads/main", + Message: "bump\n", + Sender: "gordon", + Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + Email: "gordon@golang.org", + ForgeURL: "http://gitea.golang.org/gordon/hello-world/commit/ef98532add3b2feb7a137426bba1248724367df5", + ChangedFiles: []string{"CHANGELOG.md", "app/controller/application.rb"}, + }, + }, + { + name: "push event should handle multi commit push", + data: fixtures.HookPushMulti, + event: "push", + repo: &model.Repo{ + ForgeRemoteID: "6", + Owner: "Test-CI", + Name: "multi-line-secrets", + FullName: "Test-CI/multi-line-secrets", + Avatar: "http://127.0.0.1:3000/avatars/5b0a83c2185b3cb1ebceb11062d6c2eb", + ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets", + Clone: "http://127.0.0.1:3000/Test-CI/multi-line-secrets.git", + CloneSSH: "ssh://git@127.0.0.1:2200/Test-CI/multi-line-secrets.git", + Branch: "main", + SCMKind: "git", + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, + pipe: &model.Pipeline{ + Author: "test-user", + Event: "push", + Commit: "29be01c073851cf0db0c6a466e396b725a670453", + Branch: "main", + Ref: "refs/heads/main", + Message: "add some text\n", + Sender: "test-user", + Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", + Email: "test@noreply.localhost", + ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/compare/6efcf5b7c98f3e7a491675164b7a2e7acac27941...29be01c073851cf0db0c6a466e396b725a670453", + ChangedFiles: []string{"aaa", "aa"}, + }, + }, + { + name: "tag event should handle a tag hook", + data: fixtures.HookTag, + event: "create", + repo: &model.Repo{ + ForgeRemoteID: "12", + Owner: "gordon", + Name: "hello-world", + FullName: "gordon/hello-world", + Avatar: "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + ForgeURL: "http://gitea.golang.org/gordon/hello-world", + Clone: "http://gitea.golang.org/gordon/hello-world.git", + CloneSSH: "git@gitea.golang.org:gordon/hello-world.git", + Branch: "main", + SCMKind: "git", + IsSCMPrivate: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, + pipe: &model.Pipeline{ + Author: "gordon", + Event: "tag", + Commit: "ef98532add3b2feb7a137426bba1248724367df5", + Branch: "refs/tags/v1.0.0", + Ref: "refs/tags/v1.0.0", + Message: "created tag v1.0.0", + Sender: "gordon", + Avatar: "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + Email: "gordon@golang.org", + ForgeURL: "http://gitea.golang.org/gordon/hello-world/src/tag/v1.0.0", + }, + }, + } - g.Describe("push event", func() { - g.It("should handle a push hook", func() { - buf := bytes.NewBufferString(fixtures.HookPushBranch) - req, _ := http.NewRequest("POST", "/hook", buf) - req.Header = http.Header{} - req.Header.Set(hookEvent, hookPush) - r, p, err := parseHook(req) - if assert.NoError(t, err) { - assert.EqualValues(t, &model.Repo{ - ForgeRemoteID: "50820", - Owner: "meisam", - Name: "woodpecktester", - FullName: "meisam/woodpecktester", - Avatar: "https://codeberg.org/avatars/96512da76a14cf44e0bb32d1640e878e", - ForgeURL: "https://codeberg.org/meisam/woodpecktester", - Clone: "https://codeberg.org/meisam/woodpecktester.git", - CloneSSH: "git@codeberg.org:meisam/woodpecktester.git", - Branch: "main", - SCMKind: "git", - PREnabled: true, - Perm: &model.Perm{ - Pull: true, - Push: true, - Admin: true, - }, - }, r) - p.Timestamp = 0 - assert.EqualValues(t, &model.Pipeline{ - Author: "6543", - Event: "push", - Commit: "28c3613ae62640216bea5e7dc71aa65356e4298b", - Branch: "fdsafdsa", - Ref: "refs/heads/fdsafdsa", - Message: "Delete '.woodpecker/.check.yml'\n", - Sender: "6543", - Avatar: "https://codeberg.org/avatars/09a234c768cb9bca78f6b2f82d6af173", - Email: "6543@obermui.de", - ForgeURL: "https://codeberg.org/meisam/woodpecktester/commit/28c3613ae62640216bea5e7dc71aa65356e4298b", - ChangedFiles: []string{".woodpecker/.check.yml"}, - }, p) - } - }) - - g.It("should extract repository and pipeline details", func() { - buf := bytes.NewBufferString(fixtures.HookPush) - req, _ := http.NewRequest("POST", "/hook", buf) - req.Header = http.Header{} - req.Header.Set(hookEvent, hookPush) - r, p, err := parseHook(req) - if assert.NoError(t, err) { - assert.EqualValues(t, &model.Repo{ - ForgeRemoteID: "1", - Owner: "gordon", - Name: "hello-world", - FullName: "gordon/hello-world", - Avatar: "http://gitea.golang.org/gordon/hello-world", - ForgeURL: "http://gitea.golang.org/gordon/hello-world", - Clone: "http://gitea.golang.org/gordon/hello-world.git", - CloneSSH: "git@gitea.golang.org:gordon/hello-world.git", - SCMKind: "git", - IsSCMPrivate: true, - Perm: &model.Perm{ - Pull: true, - Push: true, - Admin: true, - }, - }, r) - p.Timestamp = 0 - assert.EqualValues(t, &model.Pipeline{ - Author: "gordon", - Event: "push", - Commit: "ef98532add3b2feb7a137426bba1248724367df5", - Branch: "main", - Ref: "refs/heads/main", - Message: "bump\n", - Sender: "gordon", - Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", - Email: "gordon@golang.org", - ForgeURL: "http://gitea.golang.org/gordon/hello-world/commit/ef98532add3b2feb7a137426bba1248724367df5", - ChangedFiles: []string{"CHANGELOG.md", "app/controller/application.rb"}, - }, p) - } - }) - - g.It("should handle multi commit push", func() { - buf := bytes.NewBufferString(fixtures.HookPushMulti) - req, _ := http.NewRequest("POST", "/hook", buf) - req.Header = http.Header{} - req.Header.Set(hookEvent, hookPush) - r, p, err := parseHook(req) - if assert.NoError(t, err) { - assert.EqualValues(t, &model.Repo{ - ForgeRemoteID: "6", - Owner: "Test-CI", - Name: "multi-line-secrets", - FullName: "Test-CI/multi-line-secrets", - Avatar: "http://127.0.0.1:3000/avatars/5b0a83c2185b3cb1ebceb11062d6c2eb", - ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets", - Clone: "http://127.0.0.1:3000/Test-CI/multi-line-secrets.git", - CloneSSH: "ssh://git@127.0.0.1:2200/Test-CI/multi-line-secrets.git", - Branch: "main", - SCMKind: "git", - Perm: &model.Perm{ - Pull: true, - Push: true, - Admin: true, - }, - }, r) - p.Timestamp = 0 - assert.EqualValues(t, &model.Pipeline{ - Author: "test-user", - Event: "push", - Commit: "29be01c073851cf0db0c6a466e396b725a670453", - Branch: "main", - Ref: "refs/heads/main", - Message: "add some text\n", - Sender: "test-user", - Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", - Email: "test@noreply.localhost", - ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/compare/6efcf5b7c98f3e7a491675164b7a2e7acac27941...29be01c073851cf0db0c6a466e396b725a670453", - ChangedFiles: []string{"aaa", "aa"}, - }, p) - } - }) - }) - - g.Describe("tag event", func() { - g.It("should handle a tag hook", func() { - buf := bytes.NewBufferString(fixtures.HookTag) - req, _ := http.NewRequest("POST", "/hook", buf) - req.Header = http.Header{} - req.Header.Set(hookEvent, hookCreated) - r, b, err := parseHook(req) - g.Assert(r).IsNotNil() - g.Assert(b).IsNotNil() - g.Assert(err).IsNil() - g.Assert(b.Event).Equal(model.EventTag) - assert.EqualValues(t, "gordon@golang.org", b.Email) - }) + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + req, _ := http.NewRequest("POST", "/api/hook", bytes.NewBufferString(tc.data)) + req.Header = http.Header{} + req.Header.Set(hookEvent, tc.event) + r, p, err := parseHook(req) + if tc.err != nil { + assert.ErrorIs(t, err, tc.err) + } else if assert.NoError(t, err) { + assert.EqualValues(t, tc.repo, r) + p.Timestamp = 0 + assert.EqualValues(t, tc.pipe, p) + } }) + } + g := goblin.Goblin(t) + g.Describe("Gitea parser", func() { g.Describe("pull-request events", func() { // g.It("should handle a PR hook when PR got created") From 2b4e136b9ab7c9a5e914d532e6295c8acbf57da2 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 22 Feb 2024 01:30:22 +0100 Subject: [PATCH 07/22] tags dont have branch info --- server/forge/gitea/helper.go | 1 - server/forge/gitea/parse_test.go | 1 - 2 files changed, 2 deletions(-) diff --git a/server/forge/gitea/helper.go b/server/forge/gitea/helper.go index d147c97f0d..3cdaca8eb3 100644 --- a/server/forge/gitea/helper.go +++ b/server/forge/gitea/helper.go @@ -133,7 +133,6 @@ func pipelineFromTag(hook *pushHook) *model.Pipeline { Commit: hook.Sha, Ref: fmt.Sprintf("refs/tags/%s", hook.Ref), ForgeURL: fmt.Sprintf("%s/src/tag/%s", hook.Repo.HTMLURL, hook.Ref), - Branch: fmt.Sprintf("refs/tags/%s", hook.Ref), Message: fmt.Sprintf("created tag %s", hook.Ref), Avatar: avatar, Author: hook.Sender.UserName, diff --git a/server/forge/gitea/parse_test.go b/server/forge/gitea/parse_test.go index 3f1025def5..ce0ee20dc8 100644 --- a/server/forge/gitea/parse_test.go +++ b/server/forge/gitea/parse_test.go @@ -175,7 +175,6 @@ func TestGiteaParser(t *testing.T) { Author: "gordon", Event: "tag", Commit: "ef98532add3b2feb7a137426bba1248724367df5", - Branch: "refs/tags/v1.0.0", Ref: "refs/tags/v1.0.0", Message: "created tag v1.0.0", Sender: "gordon", From 7165ef5bf6d901c4303a81851523be90b72e3286 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 22 Feb 2024 01:56:40 +0100 Subject: [PATCH 08/22] extend tests and finish migration --- server/forge/gitea/fixtures/hooks.go | 138 ++++++++++ server/forge/gitea/parse_test.go | 372 ++++++++++++++------------- 2 files changed, 329 insertions(+), 181 deletions(-) diff --git a/server/forge/gitea/fixtures/hooks.go b/server/forge/gitea/fixtures/hooks.go index 06104226a7..c98ac226ca 100644 --- a/server/forge/gitea/fixtures/hooks.go +++ b/server/forge/gitea/fixtures/hooks.go @@ -528,6 +528,144 @@ const HookPullRequest = `{ } }` +const HookPullRequestUpdated = `{ + "action": "synchronized", + "number": 2, + "pull_request": { + "id": 2, + "url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2", + "number": 2, + "user": { + "id": 1, + "login": "test", + "login_name": "", + "full_name": "", + "email": "test@noreply.localhost", + "avatar_url": "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2023-07-31T19:13:05+02:00", + "visibility": "public", + "username": "test" + }, + "title": "New Pull", + "body": "create an awesome pull", + "labels": [ + { + "id": 8, + "name": "Kind/Bug", + "exclusive": false, + "is_archived": false, + "color": "ee0701", + "description": "Something is not working", + "url": "http://100.106.226.9:3000/api/v1/repos/Test-CI/multi-line-secrets/labels/8" + }, + { + "id": 11, + "name": "Kind/Security", + "exclusive": false, + "is_archived": false, + "color": "9c27b0", + "description": "This is security issue", + "url": "http://100.106.226.9:3000/api/v1/repos/Test-CI/multi-line-secrets/labels/11" + } + ], + "milestone": null, + "assignees": null, + "requested_reviewers": null, + "state": "open", + "is_locked": false, + "html_url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2", + "diff_url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2.diff", + "patch_url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2.patch", + "mergeable": true, + "merged": false, + "merged_at": null, + "merge_commit_sha": null, + "merged_by": null, + "base": { + "label": "main", + "ref": "main", + "sha": "29be01c073851cf0db0c6a466e396b725a670453", + "repo_id": 6 + }, + "head": { + "label": "test-patch-1", + "ref": "test-patch-1", + "sha": "788ed8d02d3b7fcfcf6386dbcbca696aa1d4dc25", + "repo_id": 6 + }, + "merge_base": "29be01c073851cf0db0c6a466e396b725a670453", + "due_date": null, + "created_at": "2024-02-22T01:38:39+01:00", + "updated_at": "2024-02-22T01:42:03+01:00", + "closed_at": null, + "pin_order": 0 + }, + "requested_reviewer": null, + "repository": { + "id": 6, + "owner": { + "id": 2, + "login": "Test-CI", + "login_name": "", + "full_name": "", + "email": "", + "avatar_url": "http://127.0.0.1:3000/avatars/5b0a83c2185b3cb1ebceb11062d6c2eb", + "language": "", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2023-07-31T19:13:48+02:00", + "prohibit_login": false, + "visibility": "public", + "username": "Test-CI" + }, + "name": "multi-line-secrets", + "full_name": "Test-CI/multi-line-secrets", + "description": "", + "private": false, + "languages_url": "http://127.0.0.1:3000/api/v1/repos/Test-CI/multi-line-secrets/languages", + "html_url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets", + "url": "http://127.0.0.1:3000/api/v1/repos/Test-CI/multi-line-secrets", + "link": "", + "ssh_url": "ssh://git@127.0.0.1:2200/Test-CI/multi-line-secrets.git", + "clone_url": "http://127.0.0.1:3000/Test-CI/multi-line-secrets.git", + "original_url": "", + "default_branch": "main", + "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_pull_requests": true, + "avatar_url": "", + "internal": false, + "mirror_interval": "", + "object_format_name": "" + }, + "sender": { + "id": 1, + "login": "test", + "login_name": "", + "full_name": "", + "email": "test@noreply.localhost", + "avatar_url": "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", + "is_admin": false, + "last_login": "0001-01-01T00:00:00Z", + "created": "2023-07-31T19:13:05+02:00", + "visibility": "public", + "username": "test" + }, + "commit_id": "", + "review": null +}` + const HookPullRequestMerged = ` { "action": "closed", diff --git a/server/forge/gitea/parse_test.go b/server/forge/gitea/parse_test.go index ce0ee20dc8..3cabe1e558 100644 --- a/server/forge/gitea/parse_test.go +++ b/server/forge/gitea/parse_test.go @@ -20,7 +20,6 @@ import ( "net/http" "testing" - "github.com/franela/goblin" "github.com/stretchr/testify/assert" "go.woodpecker-ci.org/woodpecker/v2/server/forge/gitea/fixtures" @@ -183,6 +182,197 @@ func TestGiteaParser(t *testing.T) { ForgeURL: "http://gitea.golang.org/gordon/hello-world/src/tag/v1.0.0", }, }, + { + name: "pull-request events should handle a PR hook when PR got created", + data: fixtures.HookPullRequest, + event: "pull_request", + repo: &model.Repo{ + ForgeRemoteID: "35129377", + Owner: "gordon", + Name: "hello-world", + FullName: "gordon/hello-world", + Avatar: "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + ForgeURL: "http://gitea.golang.org/gordon/hello-world", + Clone: "https://gitea.golang.org/gordon/hello-world.git", + CloneSSH: "", + Branch: "main", + SCMKind: "git", + IsSCMPrivate: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, + pipe: &model.Pipeline{ + Author: "gordon", + Event: "pull_request", + Commit: "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c", + Branch: "main", + Ref: "refs/pull/1/head", + Refspec: "feature/changes:main", + Title: "Update the README with new information", + Message: "Update the README with new information", + Sender: "gordon", + Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + Email: "gordon@golang.org", + ForgeURL: "http://gitea.golang.org/gordon/hello-world/pull/1", + PullRequestLabels: []string{}, + }, + }, + { + name: "pull-request events should handle a PR hook when PR got updated", + data: fixtures.HookPullRequestUpdated, + event: "pull_request", + repo: &model.Repo{ + ForgeRemoteID: "6", + Owner: "Test-CI", + Name: "multi-line-secrets", + FullName: "Test-CI/multi-line-secrets", + Avatar: "http://127.0.0.1:3000/avatars/5b0a83c2185b3cb1ebceb11062d6c2eb", + ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets", + Clone: "http://127.0.0.1:3000/Test-CI/multi-line-secrets.git", + CloneSSH: "ssh://git@127.0.0.1:2200/Test-CI/multi-line-secrets.git", + Branch: "main", + SCMKind: "git", + PREnabled: true, + IsSCMPrivate: false, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, + pipe: &model.Pipeline{ + Author: "test", + Event: "pull_request", + Commit: "788ed8d02d3b7fcfcf6386dbcbca696aa1d4dc25", + Branch: "main", + Ref: "refs/pull/2/head", + Refspec: "test-patch-1:main", + Title: "New Pull", + Message: "New Pull", + Sender: "test", + Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", + Email: "test@noreply.localhost", + ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2", + PullRequestLabels: []string{ + "Kind/Bug", + "Kind/Security", + }, + }, + }, + { + name: "pull-request events should handle a PR closed hook when PR got closed", + data: fixtures.HookPullRequestClosed, + event: "pull_request", + repo: &model.Repo{ + ForgeRemoteID: "46534", + Owner: "anbraten", + Name: "test-repo", + FullName: "anbraten/test-repo", + Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", + ForgeURL: "https://gitea.com/anbraten/test-repo", + Clone: "https://gitea.com/anbraten/test-repo.git", + CloneSSH: "git@gitea.com:anbraten/test-repo.git", + Branch: "main", + SCMKind: "git", + PREnabled: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, + pipe: &model.Pipeline{ + Author: "anbraten", + Event: "pull_request_closed", + Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", + Branch: "main", + Ref: "refs/pull/1/head", + Refspec: "anbraten-patch-1:main", + Title: "Adjust file", + Message: "Adjust file", + Sender: "anbraten", + Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", + Email: "anbraten@sender.gitea.com", + ForgeURL: "https://gitea.com/anbraten/test-repo/pulls/1", + PullRequestLabels: []string{}, + }, + }, + { + name: "pull-request events should handle a PR closed hook when PR was merged", + data: fixtures.HookPullRequestMerged, + event: "pull_request", + repo: &model.Repo{ + ForgeRemoteID: "46534", + Owner: "anbraten", + Name: "test-repo", + FullName: "anbraten/test-repo", + Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", + ForgeURL: "https://gitea.com/anbraten/test-repo", + Clone: "https://gitea.com/anbraten/test-repo.git", + CloneSSH: "git@gitea.com:anbraten/test-repo.git", + Branch: "main", + SCMKind: "git", + PREnabled: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, + pipe: &model.Pipeline{ + Author: "anbraten", + Event: "pull_request_closed", + Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", + Branch: "main", + Ref: "refs/pull/1/head", + Refspec: "anbraten-patch-1:main", + Title: "Adjust file", + Message: "Adjust file", + Sender: "anbraten", + Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", + Email: "anbraten@noreply.gitea.com", + ForgeURL: "https://gitea.com/anbraten/test-repo/pulls/1", + PullRequestLabels: []string{}, + }, + }, + { + name: "release events should handle release hook", + data: fixtures.HookRelease, + event: "release", + repo: &model.Repo{ + ForgeRemoteID: "77", + Owner: "anbraten", + Name: "demo", + FullName: "anbraten/demo", + Avatar: "https://git.xxx/user/avatar/anbraten/-1", + ForgeURL: "https://git.xxx/anbraten/demo", + Clone: "https://git.xxx/anbraten/demo.git", + CloneSSH: "ssh://git@git.xxx:22/anbraten/demo.git", + Branch: "main", + SCMKind: "git", + PREnabled: true, + IsSCMPrivate: true, + Perm: &model.Perm{ + Pull: true, + Push: true, + Admin: true, + }, + }, + pipe: &model.Pipeline{ + Author: "anbraten", + Event: "release", + Branch: "main", + Ref: "refs/tags/0.0.5", + Message: "created release Version 0.0.5", + Sender: "anbraten", + Avatar: "https://git.xxx/user/avatar/anbraten/-1", + Email: "anbraten@noreply.xxx", + ForgeURL: "https://git.xxx/anbraten/demo/releases/tag/0.0.5", + }, + }, } for _, tc := range tests { @@ -200,184 +390,4 @@ func TestGiteaParser(t *testing.T) { } }) } - - g := goblin.Goblin(t) - g.Describe("Gitea parser", func() { - g.Describe("pull-request events", func() { - // g.It("should handle a PR hook when PR got created") - - g.It("should handle a PR hook when PR got updated", func() { - buf := bytes.NewBufferString(fixtures.HookPullRequest) - req, _ := http.NewRequest("POST", "/hook", buf) - req.Header = http.Header{} - req.Header.Set(hookEvent, hookPullRequest) - r, p, err := parseHook(req) - if assert.NoError(t, err) { - assert.EqualValues(t, &model.Repo{ - ForgeRemoteID: "35129377", - Owner: "gordon", - Name: "hello-world", - FullName: "gordon/hello-world", - Avatar: "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", - ForgeURL: "http://gitea.golang.org/gordon/hello-world", - Clone: "https://gitea.golang.org/gordon/hello-world.git", - CloneSSH: "", - Branch: "main", - SCMKind: "git", - IsSCMPrivate: true, - Perm: &model.Perm{ - Pull: true, - Push: true, - Admin: true, - }, - }, r) - p.Timestamp = 0 - assert.EqualValues(t, &model.Pipeline{ - Author: "gordon", - Event: "pull_request", - Commit: "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c", - Branch: "main", - Ref: "refs/pull/1/head", - Refspec: "feature/changes:main", - Title: "Update the README with new information", - Message: "Update the README with new information", - Sender: "gordon", - Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", - Email: "gordon@golang.org", - ForgeURL: "http://gitea.golang.org/gordon/hello-world/pull/1", - PullRequestLabels: []string{}, - }, p) - } - }) - - g.It("should handle a PR closed hook when PR got closed", func() { - buf := bytes.NewBufferString(fixtures.HookPullRequestClosed) - req, _ := http.NewRequest("POST", "/hook", buf) - req.Header = http.Header{} - req.Header.Set(hookEvent, hookPullRequest) - r, p, err := parseHook(req) - if assert.NoError(t, err) { - assert.EqualValues(t, &model.Repo{ - ForgeRemoteID: "46534", - Owner: "anbraten", - Name: "test-repo", - FullName: "anbraten/test-repo", - Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", - ForgeURL: "https://gitea.com/anbraten/test-repo", - Clone: "https://gitea.com/anbraten/test-repo.git", - CloneSSH: "git@gitea.com:anbraten/test-repo.git", - Branch: "main", - SCMKind: "git", - PREnabled: true, - Perm: &model.Perm{ - Pull: true, - Push: true, - Admin: true, - }, - }, r) - p.Timestamp = 0 - assert.EqualValues(t, &model.Pipeline{ - Author: "anbraten", - Event: "pull_request_closed", - Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", - Branch: "main", - Ref: "refs/pull/1/head", - Refspec: "anbraten-patch-1:main", - Title: "Adjust file", - Message: "Adjust file", - Sender: "anbraten", - Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", - Email: "anbraten@sender.gitea.com", - ForgeURL: "https://gitea.com/anbraten/test-repo/pulls/1", - PullRequestLabels: []string{}, - }, p) - } - }) - - g.It("should handle a PR closed hook when PR was merged", func() { - buf := bytes.NewBufferString(fixtures.HookPullRequestMerged) - req, _ := http.NewRequest("POST", "/hook", buf) - req.Header = http.Header{} - req.Header.Set(hookEvent, hookPullRequest) - r, p, err := parseHook(req) - if assert.NoError(t, err) { - assert.EqualValues(t, &model.Repo{ - ForgeRemoteID: "46534", - Owner: "anbraten", - Name: "test-repo", - FullName: "anbraten/test-repo", - Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", - ForgeURL: "https://gitea.com/anbraten/test-repo", - Clone: "https://gitea.com/anbraten/test-repo.git", - CloneSSH: "git@gitea.com:anbraten/test-repo.git", - Branch: "main", - SCMKind: "git", - PREnabled: true, - Perm: &model.Perm{ - Pull: true, - Push: true, - Admin: true, - }, - }, r) - p.Timestamp = 0 - assert.EqualValues(t, &model.Pipeline{ - Author: "anbraten", - Event: "pull_request_closed", - Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", - Branch: "main", - Ref: "refs/pull/1/head", - Refspec: "anbraten-patch-1:main", - Title: "Adjust file", - Message: "Adjust file", - Sender: "anbraten", - Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", - Email: "anbraten@noreply.gitea.com", - ForgeURL: "https://gitea.com/anbraten/test-repo/pulls/1", - PullRequestLabels: []string{}, - }, p) - } - }) - - g.It("should handle release hook", func() { - buf := bytes.NewBufferString(fixtures.HookRelease) - req, _ := http.NewRequest("POST", "/hook", buf) - req.Header = http.Header{} - req.Header.Set(hookEvent, hookRelease) - r, p, err := parseHook(req) - if assert.NoError(t, err) { - assert.EqualValues(t, &model.Repo{ - ForgeRemoteID: "77", - Owner: "anbraten", - Name: "demo", - FullName: "anbraten/demo", - Avatar: "https://git.xxx/user/avatar/anbraten/-1", - ForgeURL: "https://git.xxx/anbraten/demo", - Clone: "https://git.xxx/anbraten/demo.git", - CloneSSH: "ssh://git@git.xxx:22/anbraten/demo.git", - Branch: "main", - SCMKind: "git", - PREnabled: true, - IsSCMPrivate: true, - Perm: &model.Perm{ - Pull: true, - Push: true, - Admin: true, - }, - }, r) - p.Timestamp = 0 - assert.EqualValues(t, &model.Pipeline{ - Author: "anbraten", - Event: "release", - Branch: "main", - Ref: "refs/tags/0.0.5", - Message: "created release Version 0.0.5", - Sender: "anbraten", - Avatar: "https://git.xxx/user/avatar/anbraten/-1", - Email: "anbraten@noreply.xxx", - ForgeURL: "https://git.xxx/anbraten/demo/releases/tag/0.0.5", - }, p) - } - }) - }) - }) } From c691b3107d1e380750a293fa73e8f06f2c346045 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 22 Feb 2024 02:18:41 +0100 Subject: [PATCH 09/22] fix --- server/forge/gitea/helper_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/forge/gitea/helper_test.go b/server/forge/gitea/helper_test.go index 77f74091ae..f8d36f3714 100644 --- a/server/forge/gitea/helper_test.go +++ b/server/forge/gitea/helper_test.go @@ -124,7 +124,7 @@ func Test_parse(t *testing.T) { g.Assert(pipeline.Event).Equal(model.EventTag) g.Assert(pipeline.Commit).Equal(hook.Sha) g.Assert(pipeline.Ref).Equal("refs/tags/v1.0.0") - g.Assert(pipeline.Branch).Equal("refs/tags/v1.0.0") + g.Assert(pipeline.Branch).Equal("") g.Assert(pipeline.ForgeURL).Equal("http://gitea.golang.org/gordon/hello-world/src/tag/v1.0.0") g.Assert(pipeline.Message).Equal("created tag v1.0.0") }) @@ -136,7 +136,7 @@ func Test_parse(t *testing.T) { g.Assert(pipeline.Event).Equal(model.EventPull) g.Assert(pipeline.Commit).Equal(hook.PullRequest.Head.Sha) g.Assert(pipeline.Ref).Equal("refs/pull/1/head") - g.Assert(pipeline.ForgeURL).Equal(hook.PullRequest.URL) + g.Assert(pipeline.ForgeURL).Equal("http://gitea.golang.org/gordon/hello-world/pull/1") g.Assert(pipeline.Branch).Equal("main") g.Assert(pipeline.Refspec).Equal("feature/changes:main") g.Assert(pipeline.Message).Equal(hook.PullRequest.Title) From 7db9650460825139eb9b8a676e1d18e5b4f64f3d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 22 Feb 2024 02:35:22 +0100 Subject: [PATCH 10/22] actually differ between title and message and use it propperly --- server/forge/gitea/helper.go | 6 +++--- server/forge/github/parse.go | 3 +++ server/forge/github/parse_test.go | 2 ++ web/src/compositions/usePipeline.ts | 10 +++++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/server/forge/gitea/helper.go b/server/forge/gitea/helper.go index 3cdaca8eb3..5f9491a44d 100644 --- a/server/forge/gitea/helper.go +++ b/server/forge/gitea/helper.go @@ -133,7 +133,7 @@ func pipelineFromTag(hook *pushHook) *model.Pipeline { Commit: hook.Sha, Ref: fmt.Sprintf("refs/tags/%s", hook.Ref), ForgeURL: fmt.Sprintf("%s/src/tag/%s", hook.Repo.HTMLURL, hook.Ref), - Message: fmt.Sprintf("created tag %s", hook.Ref), + Message: fmt.Sprintf("created tag %s", hook.Ref), // TODO: let gitea report the actual tag message and title Avatar: avatar, Author: hook.Sender.UserName, Sender: hook.Sender.UserName, @@ -160,12 +160,12 @@ func pipelineFromPullRequest(hook *pullRequestHook) *model.Pipeline { ForgeURL: hook.PullRequest.HTMLURL, Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number), Branch: hook.PullRequest.Base.Ref, - Message: hook.PullRequest.Title, + Title: hook.PullRequest.Title, + Message: hook.PullRequest.Body, Author: hook.PullRequest.Poster.UserName, Avatar: avatar, Sender: hook.Sender.UserName, Email: hook.Sender.Email, - Title: hook.PullRequest.Title, Refspec: fmt.Sprintf("%s:%s", hook.PullRequest.Head.Ref, hook.PullRequest.Base.Ref, diff --git a/server/forge/github/parse.go b/server/forge/github/parse.go index 8337982dcd..607e044789 100644 --- a/server/forge/github/parse.go +++ b/server/forge/github/parse.go @@ -84,12 +84,15 @@ func parsePushHook(hook *github.PushEvent) (*model.Repo, *model.Pipeline) { return nil, nil } + title, _, _ := strings.Cut(hook.GetHeadCommit().GetMessage(), "\n") + pipeline := &model.Pipeline{ Event: model.EventPush, Commit: hook.GetHeadCommit().GetID(), Ref: hook.GetRef(), ForgeURL: hook.GetHeadCommit().GetURL(), Branch: strings.ReplaceAll(hook.GetRef(), "refs/heads/", ""), + Title: title, Message: hook.GetHeadCommit().GetMessage(), Email: hook.GetHeadCommit().GetAuthor().GetEmail(), Avatar: hook.GetSender().GetAvatarURL(), diff --git a/server/forge/github/parse_test.go b/server/forge/github/parse_test.go index bbd4fb57fc..f39eb4cc1c 100644 --- a/server/forge/github/parse_test.go +++ b/server/forge/github/parse_test.go @@ -75,6 +75,8 @@ func Test_parser(t *testing.T) { g.Assert(r).IsNotNil() g.Assert(b).IsNotNil() g.Assert(b.Event).Equal(model.EventPush) + assert.EqualValues(t, "Fix multiline secrets replacer (#700)", b.Title) + assert.EqualValues(t, "Fix multiline secrets replacer (#700)\n\n* Fix multiline secrets replacer\r\n\r\n* Add tests", b.Message) sort.Strings(b.ChangedFiles) g.Assert(b.ChangedFiles).Equal([]string{"pipeline/shared/replace_secrets.go", "pipeline/shared/replace_secrets_test.go"}) }) diff --git a/web/src/compositions/usePipeline.ts b/web/src/compositions/usePipeline.ts index db7d4f7362..90cb6a77d2 100644 --- a/web/src/compositions/usePipeline.ts +++ b/web/src/compositions/usePipeline.ts @@ -81,7 +81,15 @@ export default (pipeline: Ref) => { return convertEmojis(pipeline.value.message); }); - const title = computed(() => message.value.split('\n')[0]); + const title = computed(() => { + if (!pipeline.value) { + return ''; + } + if (pipeline.value.title !== '') { + return convertEmojis(pipeline.value.title); + } + return message.value.split('\n')[0]; + }); const prettyRef = computed(() => { if (pipeline.value?.event === 'push' || pipeline.value?.event === 'deployment') { From d1f49c09129a52880389977cc8792d04003eee4a Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 22 Feb 2024 03:09:34 +0100 Subject: [PATCH 11/22] refactor --- server/forge/gitea/gitea.go | 83 +++++++++++++++++++----------------- server/forge/gitea/helper.go | 15 ++++--- server/forge/github/parse.go | 17 +++++--- 3 files changed, 65 insertions(+), 50 deletions(-) diff --git a/server/forge/gitea/gitea.go b/server/forge/gitea/gitea.go index 59907e9480..d034fe1da4 100644 --- a/server/forge/gitea/gitea.go +++ b/server/forge/gitea/gitea.go @@ -512,15 +512,24 @@ func (c *Gitea) Hook(ctx context.Context, r *http.Request) (*model.Repo, *model. return nil, nil, err } + var tag *gitea.Tag + loadTag := func() error { + if tag == nil { + tagName := strings.Split(pipeline.Ref, "/")[2] + tag, err = c.getTag(ctx, repo, tagName) + return err + } + return nil + } + if pipeline != nil && pipeline.Event == model.EventRelease && pipeline.Commit == "" { - tagName := strings.Split(pipeline.Ref, "/")[2] - sha, err := c.getTagCommitSHA(ctx, repo, tagName) - if err != nil { + if err := loadTag(); err != nil { return nil, nil, err } - pipeline.Commit = sha + pipeline.Commit = tag.Commit.SHA } + // get changed files via api (and not from parsed webhook) if pipeline != nil && (pipeline.Event == model.EventPull || pipeline.Event == model.EventPullClosed) && len(pipeline.ChangedFiles) == 0 { index, err := strconv.ParseInt(strings.Split(pipeline.Ref, "/")[2], 10, 64) if err != nil { @@ -532,6 +541,15 @@ func (c *Gitea) Hook(ctx context.Context, r *http.Request) (*model.Repo, *model. } } + // get title and message via api (and not from parsed webhook) + if pipeline != nil && pipeline.Event == model.EventTag && pipeline.Title == "" { + if err := loadTag(); err != nil { + return nil, nil, err + } + pipeline.Title = fmt.Sprintf("created tag %s", tag.Name) + pipeline.Message = tag.Message + } + return repo, pipeline, nil } @@ -630,25 +648,9 @@ func getStatus(status model.StatusValue) gitea.StatusState { } func (c *Gitea) getChangedFilesForPR(ctx context.Context, repo *model.Repo, index int64) ([]string, error) { - _store, ok := store.TryFromContext(ctx) - if !ok { - log.Error().Msg("could not get store from context") - return []string{}, nil - } - - repo, err := _store.GetRepoNameFallback(repo.ForgeRemoteID, repo.FullName) - if err != nil { - return nil, err - } - - user, err := _store.GetUser(repo.UserID) - if err != nil { - return nil, err - } - - client, err := c.newClientToken(ctx, user.Token) - if err != nil { - return nil, err + client, repo, err := c.prepareHookAPIClient(ctx, repo) + if err != nil || client == nil { + return []string{}, err } return shared_utils.Paginate(func(page int) ([]string, error) { @@ -666,34 +668,39 @@ func (c *Gitea) getChangedFilesForPR(ctx context.Context, repo *model.Repo, inde }) } -func (c *Gitea) getTagCommitSHA(ctx context.Context, repo *model.Repo, tagName string) (string, error) { - _store, ok := store.TryFromContext(ctx) - if !ok { - log.Error().Msg("could not get store from context") - return "", nil +func (c *Gitea) getTag(ctx context.Context, repo *model.Repo, tagName string) (*gitea.Tag, error) { + client, repo, err := c.prepareHookAPIClient(ctx, repo) + if err != nil || client == nil { + return nil, err } - repo, err := _store.GetRepoNameFallback(repo.ForgeRemoteID, repo.FullName) + tag, _, err := client.GetTag(repo.Owner, repo.Name, tagName) if err != nil { - return "", err + return nil, err } - user, err := _store.GetUser(repo.UserID) - if err != nil { - return "", err + return tag, nil +} + +func (c *Gitea) prepareHookAPIClient(ctx context.Context, repo *model.Repo) (*gitea.Client, *model.Repo, error) { + _store, ok := store.TryFromContext(ctx) + if !ok { + log.Error().Msg("could not get store from context") + return nil, nil, nil } - client, err := c.newClientToken(ctx, user.Token) + repo, err := _store.GetRepoNameFallback(repo.ForgeRemoteID, repo.FullName) if err != nil { - return "", err + return nil, nil, err } - tag, _, err := client.GetTag(repo.Owner, repo.Name, tagName) + repoOwner, err := _store.GetUser(repo.UserID) if err != nil { - return "", err + return nil, nil, err } - return tag.Commit.SHA, nil + client, err := c.newClientToken(ctx, repoOwner.Token) + return client, repo, err } func (c *Gitea) perPage(ctx context.Context) int { diff --git a/server/forge/gitea/helper.go b/server/forge/gitea/helper.go index 5f9491a44d..0eced3cbb5 100644 --- a/server/forge/gitea/helper.go +++ b/server/forge/gitea/helper.go @@ -89,12 +89,15 @@ func pipelineFromPush(hook *pushHook) *model.Pipeline { link = hook.HeadCommit.URL } + title, _, _ := strings.Cut(message, "\n") + return &model.Pipeline{ Event: model.EventPush, Commit: hook.After, Ref: hook.Ref, ForgeURL: link, Branch: strings.TrimPrefix(hook.Ref, "refs/heads/"), + Title: title, Message: message, Avatar: avatar, Author: hook.Sender.UserName, @@ -129,11 +132,13 @@ func pipelineFromTag(hook *pushHook) *model.Pipeline { ) return &model.Pipeline{ - Event: model.EventTag, - Commit: hook.Sha, - Ref: fmt.Sprintf("refs/tags/%s", hook.Ref), - ForgeURL: fmt.Sprintf("%s/src/tag/%s", hook.Repo.HTMLURL, hook.Ref), - Message: fmt.Sprintf("created tag %s", hook.Ref), // TODO: let gitea report the actual tag message and title + Event: model.EventTag, + Commit: hook.Sha, + Ref: fmt.Sprintf("refs/tags/%s", hook.Ref), + ForgeURL: fmt.Sprintf("%s/src/tag/%s", hook.Repo.HTMLURL, hook.Ref), + // TODO: get tag message and title via webhook (gitea change needed) + Title: "", // if empty api will be asked + Message: fmt.Sprintf("created tag %s", hook.Ref), Avatar: avatar, Author: hook.Sender.UserName, Sender: hook.Sender.UserName, diff --git a/server/forge/github/parse.go b/server/forge/github/parse.go index 607e044789..5c40a95664 100644 --- a/server/forge/github/parse.go +++ b/server/forge/github/parse.go @@ -39,6 +39,9 @@ const ( stateOpen = "open" stateClose = "closed" + + branchRefPrefix = "refs/heads/" + tagRefPrefix = "refs/tags/" ) // parseHook parses a GitHub hook from an http.Request request and returns @@ -91,7 +94,7 @@ func parsePushHook(hook *github.PushEvent) (*model.Repo, *model.Pipeline) { Commit: hook.GetHeadCommit().GetID(), Ref: hook.GetRef(), ForgeURL: hook.GetHeadCommit().GetURL(), - Branch: strings.ReplaceAll(hook.GetRef(), "refs/heads/", ""), + Branch: strings.ReplaceAll(hook.GetRef(), branchRefPrefix, ""), Title: title, Message: hook.GetHeadCommit().GetMessage(), Email: hook.GetHeadCommit().GetAuthor().GetEmail(), @@ -104,15 +107,15 @@ func parsePushHook(hook *github.PushEvent) (*model.Repo, *model.Pipeline) { if len(pipeline.Author) == 0 { pipeline.Author = hook.GetHeadCommit().GetAuthor().GetLogin() } - if strings.HasPrefix(pipeline.Ref, "refs/tags/") { + if strings.HasPrefix(pipeline.Ref, tagRefPrefix) { // just kidding, this is actually a tag event. Why did this come as a push // event we'll never know! pipeline.Event = model.EventTag pipeline.ChangedFiles = nil // For tags, if the base_ref (tag's base branch) is set, we're using it // as pipeline's branch so that we can filter events base on it - if strings.HasPrefix(hook.GetBaseRef(), "refs/heads/") { - pipeline.Branch = strings.ReplaceAll(hook.GetBaseRef(), "refs/heads/", "") + if strings.HasPrefix(hook.GetBaseRef(), branchRefPrefix) { + pipeline.Branch = strings.ReplaceAll(hook.GetBaseRef(), branchRefPrefix, "") } } @@ -137,11 +140,11 @@ func parseDeployHook(hook *github.DeploymentEvent) (*model.Repo, *model.Pipeline // if the ref is a sha or short sha we need to manually construct the ref. if strings.HasPrefix(pipeline.Commit, pipeline.Ref) || pipeline.Commit == pipeline.Ref { pipeline.Branch = hook.GetRepo().GetDefaultBranch() - pipeline.Ref = fmt.Sprintf("refs/heads/%s", pipeline.Branch) + pipeline.Ref = fmt.Sprintf("%s%s", branchRefPrefix, pipeline.Branch) } // if the ref is a branch we should make sure it has refs/heads prefix if !strings.HasPrefix(pipeline.Ref, "refs/") { // branch or tag - pipeline.Ref = fmt.Sprintf("refs/heads/%s", pipeline.Branch) + pipeline.Ref = fmt.Sprintf("%s%s", branchRefPrefix, pipeline.Branch) } return convertRepo(hook.GetRepo()), pipeline @@ -198,7 +201,7 @@ func parseReleaseHook(hook *github.ReleaseEvent) (*model.Repo, *model.Pipeline) pipeline := &model.Pipeline{ Event: model.EventRelease, ForgeURL: hook.GetRelease().GetHTMLURL(), - Ref: fmt.Sprintf("refs/tags/%s", hook.GetRelease().GetTagName()), + Ref: fmt.Sprintf("%s%s", tagRefPrefix, hook.GetRelease().GetTagName()), Branch: hook.GetRelease().GetTargetCommitish(), Message: fmt.Sprintf("created release %s", name), Author: hook.GetRelease().GetAuthor().GetLogin(), From 7f23b07709285263a9aa445720f512b7f7be659b Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 22 Feb 2024 03:23:18 +0100 Subject: [PATCH 12/22] update tests etc... --- server/forge/gitea/fixtures/hooks.go | 2 +- server/forge/gitea/gitea.go | 5 ++--- server/forge/gitea/helper.go | 7 ++++--- server/forge/gitea/parse_test.go | 17 +++++++++++------ server/forge/github/parse.go | 3 ++- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/server/forge/gitea/fixtures/hooks.go b/server/forge/gitea/fixtures/hooks.go index c98ac226ca..429c7bb5fd 100644 --- a/server/forge/gitea/fixtures/hooks.go +++ b/server/forge/gitea/fixtures/hooks.go @@ -1414,7 +1414,7 @@ const HookRelease = ` "tag_name": "0.0.5", "target_commitish": "main", "name": "Version 0.0.5", - "body": "", + "body": "release notes", "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", diff --git a/server/forge/gitea/gitea.go b/server/forge/gitea/gitea.go index d034fe1da4..ea7eede0f2 100644 --- a/server/forge/gitea/gitea.go +++ b/server/forge/gitea/gitea.go @@ -541,12 +541,11 @@ func (c *Gitea) Hook(ctx context.Context, r *http.Request) (*model.Repo, *model. } } - // get title and message via api (and not from parsed webhook) - if pipeline != nil && pipeline.Event == model.EventTag && pipeline.Title == "" { + // get tag message via api if empty + if pipeline != nil && pipeline.Event == model.EventTag && pipeline.Message == "" { if err := loadTag(); err != nil { return nil, nil, err } - pipeline.Title = fmt.Sprintf("created tag %s", tag.Name) pipeline.Message = tag.Message } diff --git a/server/forge/gitea/helper.go b/server/forge/gitea/helper.go index 0eced3cbb5..6117df2036 100644 --- a/server/forge/gitea/helper.go +++ b/server/forge/gitea/helper.go @@ -136,9 +136,9 @@ func pipelineFromTag(hook *pushHook) *model.Pipeline { Commit: hook.Sha, Ref: fmt.Sprintf("refs/tags/%s", hook.Ref), ForgeURL: fmt.Sprintf("%s/src/tag/%s", hook.Repo.HTMLURL, hook.Ref), + Title: fmt.Sprintf("created tag %s", hook.Ref), // TODO: get tag message and title via webhook (gitea change needed) - Title: "", // if empty api will be asked - Message: fmt.Sprintf("created tag %s", hook.Ref), + Message: "", // if empty api will be asked Avatar: avatar, Author: hook.Sender.UserName, Sender: hook.Sender.UserName, @@ -192,7 +192,8 @@ func pipelineFromRelease(hook *releaseHook) *model.Pipeline { Ref: fmt.Sprintf("refs/tags/%s", hook.Release.TagName), ForgeURL: hook.Release.HTMLURL, Branch: hook.Release.Target, - Message: fmt.Sprintf("created release %s", hook.Release.Title), + Title: fmt.Sprintf("created release %s", hook.Release.Title), + Message: hook.Release.Note, Avatar: avatar, Author: hook.Sender.UserName, Sender: hook.Sender.UserName, diff --git a/server/forge/gitea/parse_test.go b/server/forge/gitea/parse_test.go index 3cabe1e558..d53815e835 100644 --- a/server/forge/gitea/parse_test.go +++ b/server/forge/gitea/parse_test.go @@ -70,6 +70,7 @@ func TestGiteaParser(t *testing.T) { Commit: "28c3613ae62640216bea5e7dc71aa65356e4298b", Branch: "fdsafdsa", Ref: "refs/heads/fdsafdsa", + Title: "Delete '.woodpecker/.check.yml'", Message: "Delete '.woodpecker/.check.yml'\n", Sender: "6543", Avatar: "https://codeberg.org/avatars/09a234c768cb9bca78f6b2f82d6af173", @@ -105,6 +106,7 @@ func TestGiteaParser(t *testing.T) { Commit: "ef98532add3b2feb7a137426bba1248724367df5", Branch: "main", Ref: "refs/heads/main", + Title: "bump", Message: "bump\n", Sender: "gordon", Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", @@ -140,6 +142,7 @@ func TestGiteaParser(t *testing.T) { Commit: "29be01c073851cf0db0c6a466e396b725a670453", Branch: "main", Ref: "refs/heads/main", + Title: "add some text", Message: "add some text\n", Sender: "test-user", Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", @@ -175,7 +178,8 @@ func TestGiteaParser(t *testing.T) { Event: "tag", Commit: "ef98532add3b2feb7a137426bba1248724367df5", Ref: "refs/tags/v1.0.0", - Message: "created tag v1.0.0", + Title: "created tag v1.0.0", + Message: "", Sender: "gordon", Avatar: "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", Email: "gordon@golang.org", @@ -212,7 +216,7 @@ func TestGiteaParser(t *testing.T) { Ref: "refs/pull/1/head", Refspec: "feature/changes:main", Title: "Update the README with new information", - Message: "Update the README with new information", + Message: "please merge", Sender: "gordon", Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", Email: "gordon@golang.org", @@ -251,7 +255,7 @@ func TestGiteaParser(t *testing.T) { Ref: "refs/pull/2/head", Refspec: "test-patch-1:main", Title: "New Pull", - Message: "New Pull", + Message: "create an awesome pull", Sender: "test", Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", Email: "test@noreply.localhost", @@ -292,7 +296,7 @@ func TestGiteaParser(t *testing.T) { Ref: "refs/pull/1/head", Refspec: "anbraten-patch-1:main", Title: "Adjust file", - Message: "Adjust file", + Message: "", Sender: "anbraten", Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", Email: "anbraten@sender.gitea.com", @@ -330,7 +334,7 @@ func TestGiteaParser(t *testing.T) { Ref: "refs/pull/1/head", Refspec: "anbraten-patch-1:main", Title: "Adjust file", - Message: "Adjust file", + Message: "", Sender: "anbraten", Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", Email: "anbraten@noreply.gitea.com", @@ -366,7 +370,8 @@ func TestGiteaParser(t *testing.T) { Event: "release", Branch: "main", Ref: "refs/tags/0.0.5", - Message: "created release Version 0.0.5", + Title: "created release Version 0.0.5", + Message: "release notes", Sender: "anbraten", Avatar: "https://git.xxx/user/avatar/anbraten/-1", Email: "anbraten@noreply.xxx", diff --git a/server/forge/github/parse.go b/server/forge/github/parse.go index 5c40a95664..3c2d6e7de3 100644 --- a/server/forge/github/parse.go +++ b/server/forge/github/parse.go @@ -203,7 +203,8 @@ func parseReleaseHook(hook *github.ReleaseEvent) (*model.Repo, *model.Pipeline) ForgeURL: hook.GetRelease().GetHTMLURL(), Ref: fmt.Sprintf("%s%s", tagRefPrefix, hook.GetRelease().GetTagName()), Branch: hook.GetRelease().GetTargetCommitish(), - Message: fmt.Sprintf("created release %s", name), + Title: fmt.Sprintf("created release %s", name), + Message: hook.GetRelease().GetBody(), Author: hook.GetRelease().GetAuthor().GetLogin(), Avatar: hook.GetRelease().GetAuthor().GetAvatarURL(), Sender: hook.GetSender().GetLogin(), From f25b7b0c7e97f36221986837129b5f60f8fd1bb4 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 22 Feb 2024 03:25:25 +0100 Subject: [PATCH 13/22] fix test --- server/forge/gitea/helper_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/forge/gitea/helper_test.go b/server/forge/gitea/helper_test.go index f8d36f3714..6a3110a1dc 100644 --- a/server/forge/gitea/helper_test.go +++ b/server/forge/gitea/helper_test.go @@ -27,7 +27,7 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/shared/utils" ) -func Test_parse(t *testing.T) { +func TestGiteaHelper(t *testing.T) { g := goblin.Goblin(t) g.Describe("Gitea", func() { g.It("Should parse push hook payload", func() { @@ -126,7 +126,7 @@ func Test_parse(t *testing.T) { g.Assert(pipeline.Ref).Equal("refs/tags/v1.0.0") g.Assert(pipeline.Branch).Equal("") g.Assert(pipeline.ForgeURL).Equal("http://gitea.golang.org/gordon/hello-world/src/tag/v1.0.0") - g.Assert(pipeline.Message).Equal("created tag v1.0.0") + g.Assert(pipeline.Title).Equal("created tag v1.0.0") }) g.It("Should return a Pipeline struct from a pull_request hook", func() { @@ -139,7 +139,8 @@ func Test_parse(t *testing.T) { g.Assert(pipeline.ForgeURL).Equal("http://gitea.golang.org/gordon/hello-world/pull/1") g.Assert(pipeline.Branch).Equal("main") g.Assert(pipeline.Refspec).Equal("feature/changes:main") - g.Assert(pipeline.Message).Equal(hook.PullRequest.Title) + g.Assert(pipeline.Title).Equal("Update the README with new information") + g.Assert(pipeline.Message).Equal("please merge") g.Assert(pipeline.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87") g.Assert(pipeline.Author).Equal(hook.PullRequest.Poster.UserName) }) From ada18192965585f5dad25d1231b95e9dfb4f8432 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 22 Feb 2024 03:33:30 +0100 Subject: [PATCH 14/22] dont forget the gitlab --- server/forge/gitlab/convert.go | 5 ++++- server/forge/gitlab/gitlab_test.go | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/server/forge/gitlab/convert.go b/server/forge/gitlab/convert.go index 7c8f4995bd..d75b697bd0 100644 --- a/server/forge/gitlab/convert.go +++ b/server/forge/gitlab/convert.go @@ -177,6 +177,7 @@ func convertPushHook(hook *gitlab.PushEvent) (*model.Repo, *model.Pipeline, erro if hook.After == cm.ID { pipeline.Author = cm.Author.Name pipeline.Email = cm.Author.Email + pipeline.Title = cm.Title pipeline.Message = cm.Message pipeline.Timestamp = cm.Timestamp.Unix() if len(pipeline.Email) != 0 { @@ -228,6 +229,7 @@ func convertTagHook(hook *gitlab.TagEvent) (*model.Repo, *model.Pipeline, error) if hook.After == cm.ID { pipeline.Author = cm.Author.Name pipeline.Email = cm.Author.Email + pipeline.Title = cm.Title pipeline.Message = cm.Message pipeline.Timestamp = cm.Timestamp.Unix() if len(pipeline.Email) != 0 { @@ -264,7 +266,8 @@ func convertReleaseHook(hook *gitlab.ReleaseEvent) (*model.Repo, *model.Pipeline Event: model.EventRelease, Commit: hook.Commit.ID, ForgeURL: hook.URL, - Message: fmt.Sprintf("created release %s", hook.Name), + Title: fmt.Sprintf("created release %s", hook.Name), + Message: hook.Description, Sender: hook.Commit.Author.Name, Author: hook.Commit.Author.Name, Email: hook.Commit.Author.Email, diff --git a/server/forge/gitlab/gitlab_test.go b/server/forge/gitlab/gitlab_test.go index 5197b9d012..7bd3980edb 100644 --- a/server/forge/gitlab/gitlab_test.go +++ b/server/forge/gitlab/gitlab_test.go @@ -292,7 +292,8 @@ func Test_GitLab(t *testing.T) { if assert.NotNil(t, hookRepo) && assert.NotNil(t, pipeline) { assert.Equal(t, "refs/tags/0.0.2", pipeline.Ref) assert.Equal(t, "ci", hookRepo.Name) - assert.Equal(t, "created release Awesome version 0.0.2", pipeline.Message) + assert.Equal(t, "created release Awesome version 0.0.2", pipeline.Title) + assert.Equal(t, "new version desc", pipeline.Message) assert.Equal(t, model.EventRelease, pipeline.Event) } }) From 3812c6265acd78ee8e34bbceba4d511ca14a5698 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 22 Feb 2024 03:46:36 +0100 Subject: [PATCH 15/22] bitbucket --- server/forge/bitbucket/convert.go | 2 ++ server/forge/bitbucketdatacenter/convert.go | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/server/forge/bitbucket/convert.go b/server/forge/bitbucket/convert.go index c34570d544..868ef99d85 100644 --- a/server/forge/bitbucket/convert.go +++ b/server/forge/bitbucket/convert.go @@ -178,6 +178,7 @@ func convertPullHook(from *internal.PullRequestHook) *model.Pipeline { ), ForgeURL: from.PullRequest.Links.HTML.Href, Branch: from.PullRequest.Dest.Branch.Name, + Title: from.PullRequest.Title, Message: from.PullRequest.Desc, Avatar: from.Actor.Links.Avatar.Href, Author: from.Actor.Login, @@ -199,6 +200,7 @@ func convertPushHook(hook *internal.PushHook, change *internal.Change) *model.Pi Sender: hook.Actor.Login, Timestamp: change.New.Target.Date.UTC().Unix(), } + pipeline.Title, _, _ = strings.Cut(pipeline.Message, "\n") switch change.New.Type { case "tag", "annotated_tag", "bookmark": pipeline.Event = model.EventTag diff --git a/server/forge/bitbucketdatacenter/convert.go b/server/forge/bitbucketdatacenter/convert.go index 28e974f761..83c3d6027a 100644 --- a/server/forge/bitbucketdatacenter/convert.go +++ b/server/forge/bitbucketdatacenter/convert.go @@ -79,10 +79,19 @@ func convertRepositoryPushEvent(ev *bb.RepositoryPushEvent, baseURL string) *mod return nil } + message := "" + if ev.ToCommit != nil { + message = ev.ToCommit.Message + } else if len(ev.Commits) > 0 { + message = ev.Commits[0].Message + } + title, _, _ := strings.Cut(message, "\n") + pipeline := &model.Pipeline{ Commit: change.ToHash, Branch: change.Ref.DisplayID, - Message: "", + Title: title, + Message: message, Avatar: bitbucketAvatarURL(baseURL, ev.Actor.Slug), Author: authorLabel(ev.Actor.Name), Email: ev.Actor.Email, @@ -105,7 +114,6 @@ func convertPullRequestEvent(ev *bb.PullRequestEvent, baseURL string) *model.Pip Commit: ev.PullRequest.Source.Latest, Branch: ev.PullRequest.Source.DisplayID, Title: ev.PullRequest.Title, - Message: "", Avatar: bitbucketAvatarURL(baseURL, ev.Actor.Slug), Author: authorLabel(ev.Actor.Name), Email: ev.Actor.Email, From 36cf5af6c80b90e63b89bc819a68fc39573e3f7d Mon Sep 17 00:00:00 2001 From: Anbraten <6918444+anbraten@users.noreply.github.com> Date: Tue, 25 Jun 2024 08:52:42 +0200 Subject: [PATCH 16/22] adjust pipeline item --- .../components/repo/pipeline/PipelineItem.vue | 113 +++++++++--------- web/src/compositions/usePipeline.ts | 7 +- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/web/src/components/repo/pipeline/PipelineItem.vue b/web/src/components/repo/pipeline/PipelineItem.vue index 162a55c38b..0e56ab4990 100644 --- a/web/src/components/repo/pipeline/PipelineItem.vue +++ b/web/src/components/repo/pipeline/PipelineItem.vue @@ -11,85 +11,66 @@ 'bg-wp-state-info-100': pipelineStatusColors[pipeline.status] === 'blue', }" /> -
+
-
- #{{ pipeline.number }} - {{ duration }} -
- -
+
- {{ title }} + {{ shortMessage }} -
+
+
+ + + + + + + +
-
-
- - - - - - - - {{ prettyRef }} -
- -
- {{ since }} by {{ pipeline.author }} + + + - - + pushed to + + by {{ pipeline.author }} + ({{ pipeline.title }})
- + + +
diff --git a/web/src/compositions/usePipeline.ts b/web/src/compositions/usePipeline.ts index 1c20853f34..0c49cf30a9 100644 --- a/web/src/compositions/usePipeline.ts +++ b/web/src/compositions/usePipeline.ts @@ -68,8 +68,7 @@ export default (pipeline: Ref) => { } if (durationRaw.value === 0) { - return '-'; - // return i18n.t('time.not_started'); + return i18n.t('time.not_started'); } return prettyDuration(durationElapsed.value); @@ -83,7 +82,7 @@ export default (pipeline: Ref) => { return convertEmojis(pipeline.value.message); }); - const title = computed(() => message.value.split('\n')[0]); + const shortMessage = computed(() => message.value.split('\n')[0]); const prettyRef = computed(() => { if (pipeline.value?.event === 'push' || pipeline.value?.event === 'deployment') { @@ -119,5 +118,5 @@ export default (pipeline: Ref) => { return toLocaleString(new Date(start * 1000)); }); - return { since, duration, message, title, prettyRef, created }; + return { since, duration, message, shortMessage, prettyRef, created }; }; From 39d5350ea1f18cddab2213fb3218a384c30e2313 Mon Sep 17 00:00:00 2001 From: Anbraten <6918444+anbraten@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:46:13 +0200 Subject: [PATCH 17/22] adjust pipeline message and title --- server/api/pipeline.go | 2 +- server/forge/bitbucket/convert.go | 5 +- server/forge/bitbucketdatacenter/convert.go | 5 +- server/forge/forgejo/helper.go | 35 ++++++---- server/forge/forgejo/parse_test.go | 30 ++++---- server/forge/gitea/helper.go | 47 ++++++------- server/forge/gitea/helper_test.go | 4 +- server/forge/gitea/parse_test.go | 76 ++++++++++----------- server/forge/github/convert_test.go | 2 +- server/forge/github/parse.go | 28 ++++---- server/forge/github/parse_test.go | 2 +- server/forge/gitlab/convert.go | 7 +- server/forge/gitlab/gitlab_test.go | 8 +-- server/model/pipeline.go | 2 +- 14 files changed, 127 insertions(+), 126 deletions(-) diff --git a/server/api/pipeline.go b/server/api/pipeline.go index 2f4509d906..eb5fb13f4d 100644 --- a/server/api/pipeline.go +++ b/server/api/pipeline.go @@ -84,7 +84,7 @@ func createTmpPipeline(event model.WebhookEvent, commit *model.Commit, user *mod Timestamp: time.Now().UTC().Unix(), Avatar: user.Avatar, - Message: "MANUAL PIPELINE @ " + opts.Branch, + Message: "manual pipeline @" + opts.Branch, Ref: opts.Branch, AdditionalVariables: opts.Variables, diff --git a/server/forge/bitbucket/convert.go b/server/forge/bitbucket/convert.go index b9301bf27f..09ee62cd89 100644 --- a/server/forge/bitbucket/convert.go +++ b/server/forge/bitbucket/convert.go @@ -178,8 +178,8 @@ func convertPullHook(from *internal.PullRequestHook) *model.Pipeline { ), ForgeURL: from.PullRequest.Links.HTML.Href, Branch: from.PullRequest.Dest.Branch.Name, - Title: from.PullRequest.Title, - Message: from.PullRequest.Desc, + PRContext: from.PullRequest.Title + "\n" + from.PullRequest.Desc, + Message: "", // TODO: get last commit message Avatar: from.Actor.Links.Avatar.Href, Author: from.Actor.Login, Sender: from.Actor.Login, @@ -200,7 +200,6 @@ func convertPushHook(hook *internal.PushHook, change *internal.Change) *model.Pi Sender: hook.Actor.Login, Timestamp: change.New.Target.Date.UTC().Unix(), } - pipeline.Title, _, _ = strings.Cut(pipeline.Message, "\n") switch change.New.Type { case "tag", "annotated_tag", "bookmark": pipeline.Event = model.EventTag diff --git a/server/forge/bitbucketdatacenter/convert.go b/server/forge/bitbucketdatacenter/convert.go index dcc313607d..e6e741534c 100644 --- a/server/forge/bitbucketdatacenter/convert.go +++ b/server/forge/bitbucketdatacenter/convert.go @@ -95,12 +95,10 @@ func convertRepositoryPushEvent(ev *bb.RepositoryPushEvent, baseURL string) *mod } else if len(ev.Commits) > 0 { message = ev.Commits[0].Message } - title, _, _ := strings.Cut(message, "\n") pipeline := &model.Pipeline{ Commit: change.ToHash, Branch: change.Ref.DisplayID, - Title: title, Message: message, Avatar: bitbucketAvatarURL(baseURL, ev.Actor.Slug), Author: authorLabel(ev.Actor.Name), @@ -123,7 +121,8 @@ func convertPullRequestEvent(ev *bb.PullRequestEvent, baseURL string) *model.Pip pipeline := &model.Pipeline{ Commit: ev.PullRequest.Source.Latest, Branch: ev.PullRequest.Source.DisplayID, - Title: ev.PullRequest.Title, + PRContext: ev.PullRequest.Title, + Message: "", // TODO: get message from last commit to pr Avatar: bitbucketAvatarURL(baseURL, ev.Actor.Slug), Author: authorLabel(ev.Actor.Name), Email: ev.Actor.Email, diff --git a/server/forge/forgejo/helper.go b/server/forge/forgejo/helper.go index 0ab2b24e0f..9003892464 100644 --- a/server/forge/forgejo/helper.go +++ b/server/forge/forgejo/helper.go @@ -128,12 +128,21 @@ func pipelineFromTag(hook *pushHook) *model.Pipeline { ) ref := strings.TrimPrefix(hook.Ref, "refs/tags/") + var message string + if len(hook.Commits) > 0 { + message = hook.Commits[0].Message + if len(hook.Commits) == 1 { + } + } else { + message = hook.HeadCommit.Message + } + return &model.Pipeline{ Event: model.EventTag, Commit: hook.Sha, Ref: fmt.Sprintf("refs/tags/%s", ref), ForgeURL: fmt.Sprintf("%s/src/tag/%s", hook.Repo.HTMLURL, ref), - Message: fmt.Sprintf("created tag %s", ref), + Message: message, Avatar: avatar, Author: hook.Sender.UserName, Sender: hook.Sender.UserName, @@ -155,17 +164,17 @@ func pipelineFromPullRequest(hook *pullRequestHook) *model.Pipeline { } pipeline := &model.Pipeline{ - Event: event, - Commit: hook.PullRequest.Head.Sha, - ForgeURL: hook.PullRequest.HTMLURL, - Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number), - Branch: hook.PullRequest.Base.Ref, - Message: hook.PullRequest.Title, - Author: hook.PullRequest.Poster.UserName, - Avatar: avatar, - Sender: hook.Sender.UserName, - Email: hook.Sender.Email, - Title: hook.PullRequest.Title, + Event: event, + Commit: hook.PullRequest.Head.Sha, + ForgeURL: hook.PullRequest.HTMLURL, + Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number), + Branch: hook.PullRequest.Base.Ref, + Author: hook.PullRequest.Poster.UserName, + Avatar: avatar, + Sender: hook.Sender.UserName, + Email: hook.Sender.Email, + PRContext: hook.PullRequest.Title + "\n" + hook.PullRequest.Body, + Message: "", // TODO: get message from last commit to pr Refspec: fmt.Sprintf("%s:%s", hook.PullRequest.Head.Ref, hook.PullRequest.Base.Ref, @@ -187,7 +196,7 @@ func pipelineFromRelease(hook *releaseHook) *model.Pipeline { Ref: fmt.Sprintf("refs/tags/%s", hook.Release.TagName), ForgeURL: hook.Release.HTMLURL, Branch: hook.Release.Target, - Message: fmt.Sprintf("created release %s", hook.Release.Title), + Message: hook.Release.Title + "\n" + hook.Release.Note, Avatar: avatar, Author: hook.Sender.UserName, Sender: hook.Sender.UserName, diff --git a/server/forge/forgejo/parse_test.go b/server/forge/forgejo/parse_test.go index 9415d99757..e2dbf7ec1a 100644 --- a/server/forge/forgejo/parse_test.go +++ b/server/forge/forgejo/parse_test.go @@ -210,7 +210,7 @@ func TestForgejoParser(t *testing.T) { Branch: "main", Ref: "refs/pull/1/head", Refspec: "feature/changes:main", - Title: "Update the README with new information", + PRContext: "Update the README with new information", Message: "Update the README with new information", Sender: "gordon", Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", @@ -243,18 +243,18 @@ func TestForgejoParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "test", - Event: "pull_request", - Commit: "788ed8d02d3b7fcfcf6386dbcbca696aa1d4dc25", - Branch: "main", - Ref: "refs/pull/2/head", - Refspec: "test-patch-1:main", - Title: "New Pull", - Message: "New Pull", - Sender: "test", - Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", - Email: "test@noreply.localhost", - ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2", + Author: "test", + Event: "pull_request", + Commit: "788ed8d02d3b7fcfcf6386dbcbca696aa1d4dc25", + Branch: "main", + Ref: "refs/pull/2/head", + Refspec: "test-patch-1:main", + PRContext: "New Pull", + Message: "New Pull", + Sender: "test", + Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", + Email: "test@noreply.localhost", + ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2", PullRequestLabels: []string{ "Kind/Bug", "Kind/Security", @@ -290,7 +290,7 @@ func TestForgejoParser(t *testing.T) { Branch: "main", Ref: "refs/pull/1/head", Refspec: "anbraten-patch-1:main", - Title: "Adjust file", + PRContext: "Adjust file", Message: "Adjust file", Sender: "anbraten", Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", @@ -328,7 +328,7 @@ func TestForgejoParser(t *testing.T) { Branch: "main", Ref: "refs/pull/1/head", Refspec: "anbraten-patch-1:main", - Title: "Adjust file", + PRContext: "Adjust file", Message: "Adjust file", Sender: "anbraten", Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", diff --git a/server/forge/gitea/helper.go b/server/forge/gitea/helper.go index 929e2a1443..1391e8e433 100644 --- a/server/forge/gitea/helper.go +++ b/server/forge/gitea/helper.go @@ -89,15 +89,12 @@ func pipelineFromPush(hook *pushHook) *model.Pipeline { link = hook.HeadCommit.URL } - title, _, _ := strings.Cut(message, "\n") - return &model.Pipeline{ Event: model.EventPush, Commit: hook.After, Ref: hook.Ref, ForgeURL: link, Branch: strings.TrimPrefix(hook.Ref, "refs/heads/"), - Title: title, Message: message, Avatar: avatar, Author: hook.Sender.UserName, @@ -132,14 +129,19 @@ func pipelineFromTag(hook *pushHook) *model.Pipeline { ) ref := strings.TrimPrefix(hook.Ref, "refs/tags/") + var message string + if len(hook.Commits) > 0 { + message = hook.Commits[0].Message + } else { + message = hook.HeadCommit.Message + } + return &model.Pipeline{ - Event: model.EventTag, - Commit: hook.Sha, - Ref: fmt.Sprintf("refs/tags/%s", ref), - ForgeURL: fmt.Sprintf("%s/src/tag/%s", hook.Repo.HTMLURL, ref), - Title: fmt.Sprintf("created tag %s", ref), - // TODO: get tag message and title via webhook (gitea change needed) - Message: "", // if empty api will be asked + Event: model.EventTag, + Commit: hook.Sha, + Ref: fmt.Sprintf("refs/tags/%s", ref), + ForgeURL: fmt.Sprintf("%s/src/tag/%s", hook.Repo.HTMLURL, ref), + Message: message, Avatar: avatar, Author: hook.Sender.UserName, Sender: hook.Sender.UserName, @@ -161,17 +163,17 @@ func pipelineFromPullRequest(hook *pullRequestHook) *model.Pipeline { } pipeline := &model.Pipeline{ - Event: event, - Commit: hook.PullRequest.Head.Sha, - ForgeURL: hook.PullRequest.HTMLURL, - Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number), - Branch: hook.PullRequest.Base.Ref, - Title: hook.PullRequest.Title, - Message: hook.PullRequest.Body, - Author: hook.PullRequest.Poster.UserName, - Avatar: avatar, - Sender: hook.Sender.UserName, - Email: hook.Sender.Email, + Event: event, + Commit: hook.PullRequest.Head.Sha, + ForgeURL: hook.PullRequest.HTMLURL, + Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number), + Branch: hook.PullRequest.Base.Ref, + PRContext: hook.PullRequest.Title + "\n" + hook.PullRequest.Body, + Message: "", // TODO: get commit message from last commit + Author: hook.PullRequest.Poster.UserName, + Avatar: avatar, + Sender: hook.Sender.UserName, + Email: hook.Sender.Email, Refspec: fmt.Sprintf("%s:%s", hook.PullRequest.Head.Ref, hook.PullRequest.Base.Ref, @@ -193,8 +195,7 @@ func pipelineFromRelease(hook *releaseHook) *model.Pipeline { Ref: fmt.Sprintf("refs/tags/%s", hook.Release.TagName), ForgeURL: hook.Release.HTMLURL, Branch: hook.Release.Target, - Title: fmt.Sprintf("created release %s", hook.Release.Title), - Message: hook.Release.Note, + Message: hook.Release.Title + "\n" + hook.Release.Note, Avatar: avatar, Author: hook.Sender.UserName, Sender: hook.Sender.UserName, diff --git a/server/forge/gitea/helper_test.go b/server/forge/gitea/helper_test.go index 6a3110a1dc..5ca4b49edd 100644 --- a/server/forge/gitea/helper_test.go +++ b/server/forge/gitea/helper_test.go @@ -126,7 +126,7 @@ func TestGiteaHelper(t *testing.T) { g.Assert(pipeline.Ref).Equal("refs/tags/v1.0.0") g.Assert(pipeline.Branch).Equal("") g.Assert(pipeline.ForgeURL).Equal("http://gitea.golang.org/gordon/hello-world/src/tag/v1.0.0") - g.Assert(pipeline.Title).Equal("created tag v1.0.0") + g.Assert(pipeline.PRContext).Equal("created tag v1.0.0") }) g.It("Should return a Pipeline struct from a pull_request hook", func() { @@ -139,7 +139,7 @@ func TestGiteaHelper(t *testing.T) { g.Assert(pipeline.ForgeURL).Equal("http://gitea.golang.org/gordon/hello-world/pull/1") g.Assert(pipeline.Branch).Equal("main") g.Assert(pipeline.Refspec).Equal("feature/changes:main") - g.Assert(pipeline.Title).Equal("Update the README with new information") + g.Assert(pipeline.PRContext).Equal("Update the README with new information") g.Assert(pipeline.Message).Equal("please merge") g.Assert(pipeline.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87") g.Assert(pipeline.Author).Equal(hook.PullRequest.Poster.UserName) diff --git a/server/forge/gitea/parse_test.go b/server/forge/gitea/parse_test.go index 90e5473f5b..6d07df272f 100644 --- a/server/forge/gitea/parse_test.go +++ b/server/forge/gitea/parse_test.go @@ -70,7 +70,7 @@ func TestGiteaParser(t *testing.T) { Commit: "28c3613ae62640216bea5e7dc71aa65356e4298b", Branch: "fdsafdsa", Ref: "refs/heads/fdsafdsa", - Title: "Delete '.woodpecker/.check.yml'", + PRContext: "Delete '.woodpecker/.check.yml'", Message: "Delete '.woodpecker/.check.yml'\n", Sender: "6543", Avatar: "https://codeberg.org/avatars/09a234c768cb9bca78f6b2f82d6af173", @@ -106,7 +106,7 @@ func TestGiteaParser(t *testing.T) { Commit: "ef98532add3b2feb7a137426bba1248724367df5", Branch: "main", Ref: "refs/heads/main", - Title: "bump", + PRContext: "bump", Message: "bump\n", Sender: "gordon", Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", @@ -142,7 +142,7 @@ func TestGiteaParser(t *testing.T) { Commit: "29be01c073851cf0db0c6a466e396b725a670453", Branch: "main", Ref: "refs/heads/main", - Title: "add some text", + PRContext: "add some text", Message: "add some text\n", Sender: "test-user", Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", @@ -174,16 +174,16 @@ func TestGiteaParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "gordon", - Event: "tag", - Commit: "ef98532add3b2feb7a137426bba1248724367df5", - Ref: "refs/tags/v1.0.0", - Title: "created tag v1.0.0", - Message: "", - Sender: "gordon", - Avatar: "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", - Email: "gordon@golang.org", - ForgeURL: "http://gitea.golang.org/gordon/hello-world/src/tag/v1.0.0", + Author: "gordon", + Event: "tag", + Commit: "ef98532add3b2feb7a137426bba1248724367df5", + Ref: "refs/tags/v1.0.0", + PRContext: "created tag v1.0.0", + Message: "", + Sender: "gordon", + Avatar: "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + Email: "gordon@golang.org", + ForgeURL: "http://gitea.golang.org/gordon/hello-world/src/tag/v1.0.0", }, }, { @@ -215,7 +215,7 @@ func TestGiteaParser(t *testing.T) { Branch: "main", Ref: "refs/pull/1/head", Refspec: "feature/changes:main", - Title: "Update the README with new information", + PRContext: "Update the README with new information", Message: "please merge", Sender: "gordon", Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", @@ -248,18 +248,18 @@ func TestGiteaParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "test", - Event: "pull_request", - Commit: "788ed8d02d3b7fcfcf6386dbcbca696aa1d4dc25", - Branch: "main", - Ref: "refs/pull/2/head", - Refspec: "test-patch-1:main", - Title: "New Pull", - Message: "create an awesome pull", - Sender: "test", - Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", - Email: "test@noreply.localhost", - ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2", + Author: "test", + Event: "pull_request", + Commit: "788ed8d02d3b7fcfcf6386dbcbca696aa1d4dc25", + Branch: "main", + Ref: "refs/pull/2/head", + Refspec: "test-patch-1:main", + PRContext: "New Pull", + Message: "create an awesome pull", + Sender: "test", + Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", + Email: "test@noreply.localhost", + ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2", PullRequestLabels: []string{ "Kind/Bug", "Kind/Security", @@ -295,7 +295,7 @@ func TestGiteaParser(t *testing.T) { Branch: "main", Ref: "refs/pull/1/head", Refspec: "anbraten-patch-1:main", - Title: "Adjust file", + PRContext: "Adjust file", Message: "", Sender: "anbraten", Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", @@ -333,7 +333,7 @@ func TestGiteaParser(t *testing.T) { Branch: "main", Ref: "refs/pull/1/head", Refspec: "anbraten-patch-1:main", - Title: "Adjust file", + PRContext: "Adjust file", Message: "", Sender: "anbraten", Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", @@ -366,16 +366,16 @@ func TestGiteaParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "anbraten", - Event: "release", - Branch: "main", - Ref: "refs/tags/0.0.5", - Title: "created release Version 0.0.5", - Message: "release notes", - Sender: "anbraten", - Avatar: "https://git.xxx/user/avatar/anbraten/-1", - Email: "anbraten@noreply.xxx", - ForgeURL: "https://git.xxx/anbraten/demo/releases/tag/0.0.5", + Author: "anbraten", + Event: "release", + Branch: "main", + Ref: "refs/tags/0.0.5", + PRContext: "created release Version 0.0.5", + Message: "release notes", + Sender: "anbraten", + Avatar: "https://git.xxx/user/avatar/anbraten/-1", + Email: "anbraten@noreply.xxx", + ForgeURL: "https://git.xxx/anbraten/demo/releases/tag/0.0.5", }, }, } diff --git a/server/forge/github/convert_test.go b/server/forge/github/convert_test.go index 33abce8874..7715625cf7 100644 --- a/server/forge/github/convert_test.go +++ b/server/forge/github/convert_test.go @@ -214,7 +214,7 @@ func Test_helper(t *testing.T) { g.Assert(pipeline.Refspec).Equal("changes:main") g.Assert(pipeline.Commit).Equal(*from.PullRequest.Head.SHA) g.Assert(pipeline.Message).Equal(*from.PullRequest.Title) - g.Assert(pipeline.Title).Equal(*from.PullRequest.Title) + g.Assert(pipeline.PRContext).Equal(*from.PullRequest.Title) g.Assert(pipeline.Author).Equal(*from.PullRequest.User.Login) g.Assert(pipeline.Avatar).Equal(*from.PullRequest.User.AvatarURL) g.Assert(pipeline.Sender).Equal(*from.Sender.Login) diff --git a/server/forge/github/parse.go b/server/forge/github/parse.go index 80c4b39936..da612c619a 100644 --- a/server/forge/github/parse.go +++ b/server/forge/github/parse.go @@ -87,15 +87,12 @@ func parsePushHook(hook *github.PushEvent) (*model.Repo, *model.Pipeline) { return nil, nil } - title, _, _ := strings.Cut(hook.GetHeadCommit().GetMessage(), "\n") - pipeline := &model.Pipeline{ Event: model.EventPush, Commit: hook.GetHeadCommit().GetID(), Ref: hook.GetRef(), ForgeURL: hook.GetHeadCommit().GetURL(), Branch: strings.ReplaceAll(hook.GetRef(), branchRefPrefix, ""), - Title: title, Message: hook.GetHeadCommit().GetMessage(), Email: hook.GetHeadCommit().GetAuthor().GetEmail(), Avatar: hook.GetSender().GetAvatarURL(), @@ -129,7 +126,7 @@ func parseDeployHook(hook *github.DeploymentEvent) (*model.Repo, *model.Pipeline Event: model.EventDeploy, Commit: hook.GetDeployment().GetSHA(), ForgeURL: hook.GetDeployment().GetURL(), - Message: hook.GetDeployment().GetDescription(), + Message: hook.GetDeployment().GetEnvironment() + "\n" + hook.GetDeployment().GetDescription(), Ref: hook.GetDeployment().GetRef(), Branch: hook.GetDeployment().GetRef(), Deploy: hook.GetDeployment().GetEnvironment(), @@ -164,16 +161,16 @@ func parsePullHook(hook *github.PullRequestEvent, merge bool) (*github.PullReque } pipeline := &model.Pipeline{ - Event: event, - Commit: hook.GetPullRequest().GetHead().GetSHA(), - ForgeURL: hook.GetPullRequest().GetHTMLURL(), - Ref: fmt.Sprintf(headRefs, hook.GetPullRequest().GetNumber()), - Branch: hook.GetPullRequest().GetBase().GetRef(), - Message: hook.GetPullRequest().GetTitle(), - Author: hook.GetPullRequest().GetUser().GetLogin(), - Avatar: hook.GetPullRequest().GetUser().GetAvatarURL(), - Title: hook.GetPullRequest().GetTitle(), - Sender: hook.GetSender().GetLogin(), + Event: event, + Commit: hook.GetPullRequest().GetHead().GetSHA(), + ForgeURL: hook.GetPullRequest().GetHTMLURL(), + Ref: fmt.Sprintf(headRefs, hook.GetPullRequest().GetNumber()), + Branch: hook.GetPullRequest().GetBase().GetRef(), + Message: hook.GetChanges().GetTitle().GetFrom() + "\n" + hook.GetChanges().GetBody().GetFrom(), + Author: hook.GetPullRequest().GetUser().GetLogin(), + Avatar: hook.GetPullRequest().GetUser().GetAvatarURL(), + PRContext: hook.GetPullRequest().GetTitle() + "\n" + hook.GetPullRequest().GetBody(), + Sender: hook.GetSender().GetLogin(), Refspec: fmt.Sprintf(refSpec, hook.GetPullRequest().GetHead().GetRef(), hook.GetPullRequest().GetBase().GetRef(), @@ -204,8 +201,7 @@ func parseReleaseHook(hook *github.ReleaseEvent) (*model.Repo, *model.Pipeline) ForgeURL: hook.GetRelease().GetHTMLURL(), Ref: fmt.Sprintf("%s%s", tagRefPrefix, hook.GetRelease().GetTagName()), Branch: hook.GetRelease().GetTargetCommitish(), // cspell:disable-line - Title: fmt.Sprintf("created release %s", name), - Message: hook.GetRelease().GetBody(), + Message: name + "\n" + hook.GetRelease().GetBody(), Author: hook.GetRelease().GetAuthor().GetLogin(), Avatar: hook.GetRelease().GetAuthor().GetAvatarURL(), Sender: hook.GetSender().GetLogin(), diff --git a/server/forge/github/parse_test.go b/server/forge/github/parse_test.go index ce825cb022..9b45976278 100644 --- a/server/forge/github/parse_test.go +++ b/server/forge/github/parse_test.go @@ -75,7 +75,7 @@ func Test_parser(t *testing.T) { g.Assert(r).IsNotNil() g.Assert(b).IsNotNil() g.Assert(b.Event).Equal(model.EventPush) - assert.EqualValues(t, "Fix multiline secrets replacer (#700)", b.Title) + assert.EqualValues(t, "Fix multiline secrets replacer (#700)", b.PRContext) assert.EqualValues(t, "Fix multiline secrets replacer (#700)\n\n* Fix multiline secrets replacer\r\n\r\n* Add tests", b.Message) sort.Strings(b.ChangedFiles) g.Assert(b.ChangedFiles).Equal([]string{"pipeline/shared/replace_secrets.go", "pipeline/shared/replace_secrets_test.go"}) diff --git a/server/forge/gitlab/convert.go b/server/forge/gitlab/convert.go index c94d560a56..4361bdd8f6 100644 --- a/server/forge/gitlab/convert.go +++ b/server/forge/gitlab/convert.go @@ -134,7 +134,7 @@ func convertMergeRequestHook(hook *gitlab.MergeEvent, req *http.Request) (int, * pipeline.Avatar = getUserAvatar(pipeline.Email) } - pipeline.Title = obj.Title + pipeline.PRContext = obj.Title + "\n" + obj.Description pipeline.ForgeURL = obj.URL pipeline.PullRequestLabels = convertLabels(hook.Labels) @@ -178,7 +178,6 @@ func convertPushHook(hook *gitlab.PushEvent) (*model.Repo, *model.Pipeline, erro if hook.After == cm.ID { pipeline.Author = cm.Author.Name pipeline.Email = cm.Author.Email - pipeline.Title = cm.Title pipeline.Message = cm.Message pipeline.Timestamp = cm.Timestamp.Unix() if len(pipeline.Email) != 0 { @@ -230,7 +229,6 @@ func convertTagHook(hook *gitlab.TagEvent) (*model.Repo, *model.Pipeline, error) if hook.After == cm.ID { pipeline.Author = cm.Author.Name pipeline.Email = cm.Author.Email - pipeline.Title = cm.Title pipeline.Message = cm.Message pipeline.Timestamp = cm.Timestamp.Unix() if len(pipeline.Email) != 0 { @@ -267,8 +265,7 @@ func convertReleaseHook(hook *gitlab.ReleaseEvent) (*model.Repo, *model.Pipeline Event: model.EventRelease, Commit: hook.Commit.ID, ForgeURL: hook.URL, - Title: fmt.Sprintf("created release %s", hook.Name), - Message: hook.Description, + Message: hook.Name + "\n" + hook.Description, Sender: hook.Commit.Author.Name, Author: hook.Commit.Author.Name, Email: hook.Commit.Author.Email, diff --git a/server/forge/gitlab/gitlab_test.go b/server/forge/gitlab/gitlab_test.go index 7bd3980edb..206ace36e2 100644 --- a/server/forge/gitlab/gitlab_test.go +++ b/server/forge/gitlab/gitlab_test.go @@ -201,7 +201,7 @@ func Test_GitLab(t *testing.T) { assert.Equal(t, "main", hookRepo.Branch) assert.Equal(t, "anbraten", hookRepo.Owner) assert.Equal(t, "woodpecker", hookRepo.Name) - assert.Equal(t, "Update client.go 🎉", pipeline.Title) + assert.Equal(t, "Update client.go 🎉", pipeline.PRContext) assert.Len(t, pipeline.ChangedFiles, 0) // see L217 assert.Equal(t, model.EventPull, pipeline.Event) } @@ -252,7 +252,7 @@ func Test_GitLab(t *testing.T) { assert.Equal(t, "main", hookRepo.Branch) assert.Equal(t, "anbraten", hookRepo.Owner) assert.Equal(t, "woodpecker-test", hookRepo.Name) - assert.Equal(t, "Add new file", pipeline.Title) + assert.Equal(t, "Add new file", pipeline.PRContext) assert.Len(t, pipeline.ChangedFiles, 0) // see L217 assert.Equal(t, model.EventPullClosed, pipeline.Event) } @@ -273,7 +273,7 @@ func Test_GitLab(t *testing.T) { assert.Equal(t, "main", hookRepo.Branch) assert.Equal(t, "anbraten", hookRepo.Owner) assert.Equal(t, "woodpecker-test", hookRepo.Name) - assert.Equal(t, "Add new file", pipeline.Title) + assert.Equal(t, "Add new file", pipeline.PRContext) assert.Len(t, pipeline.ChangedFiles, 0) // see L217 assert.Equal(t, model.EventPullClosed, pipeline.Event) } @@ -292,7 +292,7 @@ func Test_GitLab(t *testing.T) { if assert.NotNil(t, hookRepo) && assert.NotNil(t, pipeline) { assert.Equal(t, "refs/tags/0.0.2", pipeline.Ref) assert.Equal(t, "ci", hookRepo.Name) - assert.Equal(t, "created release Awesome version 0.0.2", pipeline.Title) + assert.Equal(t, "created release Awesome version 0.0.2", pipeline.PRContext) assert.Equal(t, "new version desc", pipeline.Message) assert.Equal(t, model.EventRelease, pipeline.Event) } diff --git a/server/model/pipeline.go b/server/model/pipeline.go index 674069cfd9..63502ee2ad 100644 --- a/server/model/pipeline.go +++ b/server/model/pipeline.go @@ -38,7 +38,7 @@ type Pipeline struct { Branch string `json:"branch" xorm:"branch"` Ref string `json:"ref" xorm:"ref"` Refspec string `json:"refspec" xorm:"refspec"` - Title string `json:"title" xorm:"title"` + PRContext string `json:"title" xorm:"title"` Message string `json:"message" xorm:"TEXT 'message'"` Timestamp int64 `json:"timestamp" xorm:"'timestamp'"` Sender string `json:"sender" xorm:"sender"` // uses reported user for webhooks and name of cron for cron pipelines From 87946fa70fdada96c861b93e3d4248c59ad6b039 Mon Sep 17 00:00:00 2001 From: Anbraten <6918444+anbraten@users.noreply.github.com> Date: Tue, 2 Jul 2024 12:04:31 +0200 Subject: [PATCH 18/22] adjust ui text --- .vscode/settings.json | 4 ---- web/src/assets/locales/en.json | 8 +++++++- web/src/components/repo/pipeline/PipelineItem.vue | 13 +++++++++---- web/src/utils/locale.ts | 8 ++++++++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f2d20c8712..4eda241432 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,10 +9,6 @@ "go.lintTool": "golangci-lint", "go.lintFlags": ["--fast"], "go.buildTags": "test", - "gopls": { - // cspell:words gopls - "buildFlags": ["-tags=test"] - }, "eslint.workingDirectories": ["./web"], "prettier.ignorePath": "./web/.prettierignore", // Auto fix diff --git a/web/src/assets/locales/en.json b/web/src/assets/locales/en.json index 646b965bce..17b58270b3 100644 --- a/web/src/assets/locales/en.json +++ b/web/src/assets/locales/en.json @@ -453,5 +453,11 @@ "internal_error": "Some internal error occurred", "registration_closed": "The registration is closed", "access_denied": "You are not allowed to access this instance", - "invalid_state": "The OAuth state is invalid" + "invalid_state": "The OAuth state is invalid", + "by_user": "by {user}", + "pushed_to": "pushed to", + "closed": "closed", + "deployed_to": "deployed to", + "created": "created", + "triggered": "triggered" } diff --git a/web/src/components/repo/pipeline/PipelineItem.vue b/web/src/components/repo/pipeline/PipelineItem.vue index 6d3e6b589c..228eebb377 100644 --- a/web/src/components/repo/pipeline/PipelineItem.vue +++ b/web/src/components/repo/pipeline/PipelineItem.vue @@ -40,10 +40,14 @@ - pushed to - - by {{ pipeline.author }} - ({{ title }}) + {{ $t('pushed_to') }} + {{ $t('closed') }} + {{ $t('deployed_to') }} + {{ $t('created') }} + {{ $t('triggered') }} + {{ $t('triggered') }} + + {{ $t('by_user', { user: pipeline.author }) }}
@@ -78,6 +82,7 @@ import PipelineRunningIcon from '~/components/repo/pipeline/PipelineRunningIcon. import PipelineStatusIcon from '~/components/repo/pipeline/PipelineStatusIcon.vue'; import usePipeline from '~/compositions/usePipeline'; import type { Pipeline } from '~/lib/api/types'; +import { truncate } from '~/utils/locale'; const props = defineProps<{ pipeline: Pipeline; diff --git a/web/src/utils/locale.ts b/web/src/utils/locale.ts index 319ec8701f..10c6f40800 100644 --- a/web/src/utils/locale.ts +++ b/web/src/utils/locale.ts @@ -6,3 +6,11 @@ export function getUserLanguage(): string { return selectedLocale; } + +export function truncate(text: string, length: number): string { + if (text.length <= length) { + return text; + } + + return text.slice(0, length) + '...'; +} From 651663c3c027dc35080a49904bba0167a5af1cf1 Mon Sep 17 00:00:00 2001 From: Anbraten <6918444+anbraten@users.noreply.github.com> Date: Tue, 2 Jul 2024 12:11:25 +0200 Subject: [PATCH 19/22] adjust to proper values --- server/forge/bitbucket/convert.go | 16 +- server/forge/bitbucketdatacenter/convert.go | 22 +- server/forge/forgejo/helper.go | 22 +- server/forge/forgejo/parse_test.go | 102 ++++----- server/forge/gitea/helper.go | 22 +- server/forge/gitea/helper_test.go | 4 +- server/forge/gitea/parse_test.go | 214 +++++++++--------- server/forge/github/convert_test.go | 2 +- server/forge/github/parse.go | 20 +- server/forge/github/parse_test.go | 2 +- server/forge/gitlab/convert.go | 2 +- server/forge/gitlab/gitlab_test.go | 8 +- server/model/pipeline.go | 2 +- .../pipeline-feed/PipelineFeedItem.vue | 4 +- .../components/repo/pipeline/PipelineItem.vue | 4 +- web/src/compositions/usePipeline.ts | 5 +- .../views/repo/pipeline/PipelineWrapper.vue | 4 +- 17 files changed, 228 insertions(+), 227 deletions(-) diff --git a/server/forge/bitbucket/convert.go b/server/forge/bitbucket/convert.go index 09ee62cd89..c0302bccca 100644 --- a/server/forge/bitbucket/convert.go +++ b/server/forge/bitbucket/convert.go @@ -176,14 +176,14 @@ func convertPullHook(from *internal.PullRequestHook) *model.Pipeline { from.PullRequest.Source.Branch.Name, from.PullRequest.Dest.Branch.Name, ), - ForgeURL: from.PullRequest.Links.HTML.Href, - Branch: from.PullRequest.Dest.Branch.Name, - PRContext: from.PullRequest.Title + "\n" + from.PullRequest.Desc, - Message: "", // TODO: get last commit message - Avatar: from.Actor.Links.Avatar.Href, - Author: from.Actor.Login, - Sender: from.Actor.Login, - Timestamp: from.PullRequest.Updated.UTC().Unix(), + ForgeURL: from.PullRequest.Links.HTML.Href, + Branch: from.PullRequest.Dest.Branch.Name, + PRTitleDescription: from.PullRequest.Title + "\n" + from.PullRequest.Desc, + Message: "", // TODO: get last commit message + Avatar: from.Actor.Links.Avatar.Href, + Author: from.Actor.Login, + Sender: from.Actor.Login, + Timestamp: from.PullRequest.Updated.UTC().Unix(), } } diff --git a/server/forge/bitbucketdatacenter/convert.go b/server/forge/bitbucketdatacenter/convert.go index e6e741534c..7d480fec6a 100644 --- a/server/forge/bitbucketdatacenter/convert.go +++ b/server/forge/bitbucketdatacenter/convert.go @@ -119,17 +119,17 @@ func convertRepositoryPushEvent(ev *bb.RepositoryPushEvent, baseURL string) *mod func convertPullRequestEvent(ev *bb.PullRequestEvent, baseURL string) *model.Pipeline { pipeline := &model.Pipeline{ - Commit: ev.PullRequest.Source.Latest, - Branch: ev.PullRequest.Source.DisplayID, - PRContext: ev.PullRequest.Title, - Message: "", // TODO: get message from last commit to pr - Avatar: bitbucketAvatarURL(baseURL, ev.Actor.Slug), - Author: authorLabel(ev.Actor.Name), - Email: ev.Actor.Email, - Timestamp: time.Time(ev.Date).UTC().Unix(), - Ref: fmt.Sprintf("refs/pull-requests/%d/from", ev.PullRequest.ID), - ForgeURL: fmt.Sprintf("%s/projects/%s/repos/%s/commits/%s", baseURL, ev.PullRequest.Source.Repository.Project.Key, ev.PullRequest.Source.Repository.Slug, ev.PullRequest.Source.Latest), - Refspec: fmt.Sprintf("%s:%s", ev.PullRequest.Source.DisplayID, ev.PullRequest.Target.DisplayID), + Commit: ev.PullRequest.Source.Latest, + Branch: ev.PullRequest.Source.DisplayID, + PRTitleDescription: ev.PullRequest.Title, + Message: "", // TODO: get message from last commit to pr + Avatar: bitbucketAvatarURL(baseURL, ev.Actor.Slug), + Author: authorLabel(ev.Actor.Name), + Email: ev.Actor.Email, + Timestamp: time.Time(ev.Date).UTC().Unix(), + Ref: fmt.Sprintf("refs/pull-requests/%d/from", ev.PullRequest.ID), + ForgeURL: fmt.Sprintf("%s/projects/%s/repos/%s/commits/%s", baseURL, ev.PullRequest.Source.Repository.Project.Key, ev.PullRequest.Source.Repository.Slug, ev.PullRequest.Source.Latest), + Refspec: fmt.Sprintf("%s:%s", ev.PullRequest.Source.DisplayID, ev.PullRequest.Target.DisplayID), } if ev.EventKey == bb.EventKeyPullRequestMerged || ev.EventKey == bb.EventKeyPullRequestDeclined || ev.EventKey == bb.EventKeyPullRequestDeleted { diff --git a/server/forge/forgejo/helper.go b/server/forge/forgejo/helper.go index 9003892464..aa8e5936df 100644 --- a/server/forge/forgejo/helper.go +++ b/server/forge/forgejo/helper.go @@ -164,17 +164,17 @@ func pipelineFromPullRequest(hook *pullRequestHook) *model.Pipeline { } pipeline := &model.Pipeline{ - Event: event, - Commit: hook.PullRequest.Head.Sha, - ForgeURL: hook.PullRequest.HTMLURL, - Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number), - Branch: hook.PullRequest.Base.Ref, - Author: hook.PullRequest.Poster.UserName, - Avatar: avatar, - Sender: hook.Sender.UserName, - Email: hook.Sender.Email, - PRContext: hook.PullRequest.Title + "\n" + hook.PullRequest.Body, - Message: "", // TODO: get message from last commit to pr + Event: event, + Commit: hook.PullRequest.Head.Sha, + ForgeURL: hook.PullRequest.HTMLURL, + Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number), + Branch: hook.PullRequest.Base.Ref, + Author: hook.PullRequest.Poster.UserName, + Avatar: avatar, + Sender: hook.Sender.UserName, + Email: hook.Sender.Email, + PRTitleDescription: hook.PullRequest.Title + "\n" + hook.PullRequest.Body, + Message: "", // TODO: get message from last commit to pr Refspec: fmt.Sprintf("%s:%s", hook.PullRequest.Head.Ref, hook.PullRequest.Base.Ref, diff --git a/server/forge/forgejo/parse_test.go b/server/forge/forgejo/parse_test.go index e2dbf7ec1a..ca0c0d7bc6 100644 --- a/server/forge/forgejo/parse_test.go +++ b/server/forge/forgejo/parse_test.go @@ -204,19 +204,19 @@ func TestForgejoParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "gordon", - Event: "pull_request", - Commit: "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c", - Branch: "main", - Ref: "refs/pull/1/head", - Refspec: "feature/changes:main", - PRContext: "Update the README with new information", - Message: "Update the README with new information", - Sender: "gordon", - Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", - Email: "gordon@golang.org", - ForgeURL: "http://forgejo.golang.org/gordon/hello-world/pull/1", - PullRequestLabels: []string{}, + Author: "gordon", + Event: "pull_request", + Commit: "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c", + Branch: "main", + Ref: "refs/pull/1/head", + Refspec: "feature/changes:main", + PRTitleDescription: "Update the README with new information", + Message: "Update the README with new information", + Sender: "gordon", + Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + Email: "gordon@golang.org", + ForgeURL: "http://forgejo.golang.org/gordon/hello-world/pull/1", + PullRequestLabels: []string{}, }, }, { @@ -243,18 +243,18 @@ func TestForgejoParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "test", - Event: "pull_request", - Commit: "788ed8d02d3b7fcfcf6386dbcbca696aa1d4dc25", - Branch: "main", - Ref: "refs/pull/2/head", - Refspec: "test-patch-1:main", - PRContext: "New Pull", - Message: "New Pull", - Sender: "test", - Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", - Email: "test@noreply.localhost", - ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2", + Author: "test", + Event: "pull_request", + Commit: "788ed8d02d3b7fcfcf6386dbcbca696aa1d4dc25", + Branch: "main", + Ref: "refs/pull/2/head", + Refspec: "test-patch-1:main", + PRTitleDescription: "New Pull", + Message: "New Pull", + Sender: "test", + Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", + Email: "test@noreply.localhost", + ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2", PullRequestLabels: []string{ "Kind/Bug", "Kind/Security", @@ -284,19 +284,19 @@ func TestForgejoParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "anbraten", - Event: "pull_request_closed", - Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", - Branch: "main", - Ref: "refs/pull/1/head", - Refspec: "anbraten-patch-1:main", - PRContext: "Adjust file", - Message: "Adjust file", - Sender: "anbraten", - Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", - Email: "anbraten@sender.forgejo.com", - ForgeURL: "https://forgejo.com/anbraten/test-repo/pulls/1", - PullRequestLabels: []string{}, + Author: "anbraten", + Event: "pull_request_closed", + Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", + Branch: "main", + Ref: "refs/pull/1/head", + Refspec: "anbraten-patch-1:main", + PRTitleDescription: "Adjust file", + Message: "Adjust file", + Sender: "anbraten", + Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", + Email: "anbraten@sender.forgejo.com", + ForgeURL: "https://forgejo.com/anbraten/test-repo/pulls/1", + PullRequestLabels: []string{}, }, }, { @@ -322,19 +322,19 @@ func TestForgejoParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "anbraten", - Event: "pull_request_closed", - Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", - Branch: "main", - Ref: "refs/pull/1/head", - Refspec: "anbraten-patch-1:main", - PRContext: "Adjust file", - Message: "Adjust file", - Sender: "anbraten", - Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", - Email: "anbraten@noreply.forgejo.com", - ForgeURL: "https://forgejo.com/anbraten/test-repo/pulls/1", - PullRequestLabels: []string{}, + Author: "anbraten", + Event: "pull_request_closed", + Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", + Branch: "main", + Ref: "refs/pull/1/head", + Refspec: "anbraten-patch-1:main", + PRTitleDescription: "Adjust file", + Message: "Adjust file", + Sender: "anbraten", + Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", + Email: "anbraten@noreply.forgejo.com", + ForgeURL: "https://forgejo.com/anbraten/test-repo/pulls/1", + PullRequestLabels: []string{}, }, }, { diff --git a/server/forge/gitea/helper.go b/server/forge/gitea/helper.go index 1391e8e433..ac896f6647 100644 --- a/server/forge/gitea/helper.go +++ b/server/forge/gitea/helper.go @@ -163,17 +163,17 @@ func pipelineFromPullRequest(hook *pullRequestHook) *model.Pipeline { } pipeline := &model.Pipeline{ - Event: event, - Commit: hook.PullRequest.Head.Sha, - ForgeURL: hook.PullRequest.HTMLURL, - Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number), - Branch: hook.PullRequest.Base.Ref, - PRContext: hook.PullRequest.Title + "\n" + hook.PullRequest.Body, - Message: "", // TODO: get commit message from last commit - Author: hook.PullRequest.Poster.UserName, - Avatar: avatar, - Sender: hook.Sender.UserName, - Email: hook.Sender.Email, + Event: event, + Commit: hook.PullRequest.Head.Sha, + ForgeURL: hook.PullRequest.HTMLURL, + Ref: fmt.Sprintf("refs/pull/%d/head", hook.Number), + Branch: hook.PullRequest.Base.Ref, + PRTitleDescription: hook.PullRequest.Title + "\n" + hook.PullRequest.Body, + Message: "", // TODO: get commit message from last commit + Author: hook.PullRequest.Poster.UserName, + Avatar: avatar, + Sender: hook.Sender.UserName, + Email: hook.Sender.Email, Refspec: fmt.Sprintf("%s:%s", hook.PullRequest.Head.Ref, hook.PullRequest.Base.Ref, diff --git a/server/forge/gitea/helper_test.go b/server/forge/gitea/helper_test.go index 5ca4b49edd..8b6f524988 100644 --- a/server/forge/gitea/helper_test.go +++ b/server/forge/gitea/helper_test.go @@ -126,7 +126,7 @@ func TestGiteaHelper(t *testing.T) { g.Assert(pipeline.Ref).Equal("refs/tags/v1.0.0") g.Assert(pipeline.Branch).Equal("") g.Assert(pipeline.ForgeURL).Equal("http://gitea.golang.org/gordon/hello-world/src/tag/v1.0.0") - g.Assert(pipeline.PRContext).Equal("created tag v1.0.0") + g.Assert(pipeline.PRTitleDescription).Equal("created tag v1.0.0") }) g.It("Should return a Pipeline struct from a pull_request hook", func() { @@ -139,7 +139,7 @@ func TestGiteaHelper(t *testing.T) { g.Assert(pipeline.ForgeURL).Equal("http://gitea.golang.org/gordon/hello-world/pull/1") g.Assert(pipeline.Branch).Equal("main") g.Assert(pipeline.Refspec).Equal("feature/changes:main") - g.Assert(pipeline.PRContext).Equal("Update the README with new information") + g.Assert(pipeline.PRTitleDescription).Equal("Update the README with new information") g.Assert(pipeline.Message).Equal("please merge") g.Assert(pipeline.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87") g.Assert(pipeline.Author).Equal(hook.PullRequest.Poster.UserName) diff --git a/server/forge/gitea/parse_test.go b/server/forge/gitea/parse_test.go index 6d07df272f..031ae31f73 100644 --- a/server/forge/gitea/parse_test.go +++ b/server/forge/gitea/parse_test.go @@ -65,18 +65,18 @@ func TestGiteaParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "6543", - Event: "push", - Commit: "28c3613ae62640216bea5e7dc71aa65356e4298b", - Branch: "fdsafdsa", - Ref: "refs/heads/fdsafdsa", - PRContext: "Delete '.woodpecker/.check.yml'", - Message: "Delete '.woodpecker/.check.yml'\n", - Sender: "6543", - Avatar: "https://codeberg.org/avatars/09a234c768cb9bca78f6b2f82d6af173", - Email: "6543@obermui.de", - ForgeURL: "https://codeberg.org/meisam/woodpecktester/commit/28c3613ae62640216bea5e7dc71aa65356e4298b", - ChangedFiles: []string{".woodpecker/.check.yml"}, + Author: "6543", + Event: "push", + Commit: "28c3613ae62640216bea5e7dc71aa65356e4298b", + Branch: "fdsafdsa", + Ref: "refs/heads/fdsafdsa", + PRTitleDescription: "Delete '.woodpecker/.check.yml'", + Message: "Delete '.woodpecker/.check.yml'\n", + Sender: "6543", + Avatar: "https://codeberg.org/avatars/09a234c768cb9bca78f6b2f82d6af173", + Email: "6543@obermui.de", + ForgeURL: "https://codeberg.org/meisam/woodpecktester/commit/28c3613ae62640216bea5e7dc71aa65356e4298b", + ChangedFiles: []string{".woodpecker/.check.yml"}, }, }, { @@ -101,18 +101,18 @@ func TestGiteaParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "gordon", - Event: "push", - Commit: "ef98532add3b2feb7a137426bba1248724367df5", - Branch: "main", - Ref: "refs/heads/main", - PRContext: "bump", - Message: "bump\n", - Sender: "gordon", - Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", - Email: "gordon@golang.org", - ForgeURL: "http://gitea.golang.org/gordon/hello-world/commit/ef98532add3b2feb7a137426bba1248724367df5", - ChangedFiles: []string{"CHANGELOG.md", "app/controller/application.rb"}, + Author: "gordon", + Event: "push", + Commit: "ef98532add3b2feb7a137426bba1248724367df5", + Branch: "main", + Ref: "refs/heads/main", + PRTitleDescription: "bump", + Message: "bump\n", + Sender: "gordon", + Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + Email: "gordon@golang.org", + ForgeURL: "http://gitea.golang.org/gordon/hello-world/commit/ef98532add3b2feb7a137426bba1248724367df5", + ChangedFiles: []string{"CHANGELOG.md", "app/controller/application.rb"}, }, }, { @@ -137,18 +137,18 @@ func TestGiteaParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "test-user", - Event: "push", - Commit: "29be01c073851cf0db0c6a466e396b725a670453", - Branch: "main", - Ref: "refs/heads/main", - PRContext: "add some text", - Message: "add some text\n", - Sender: "test-user", - Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", - Email: "test@noreply.localhost", - ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/compare/6efcf5b7c98f3e7a491675164b7a2e7acac27941...29be01c073851cf0db0c6a466e396b725a670453", - ChangedFiles: []string{"aaa", "aa"}, + Author: "test-user", + Event: "push", + Commit: "29be01c073851cf0db0c6a466e396b725a670453", + Branch: "main", + Ref: "refs/heads/main", + PRTitleDescription: "add some text", + Message: "add some text\n", + Sender: "test-user", + Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", + Email: "test@noreply.localhost", + ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/compare/6efcf5b7c98f3e7a491675164b7a2e7acac27941...29be01c073851cf0db0c6a466e396b725a670453", + ChangedFiles: []string{"aaa", "aa"}, }, }, { @@ -174,16 +174,16 @@ func TestGiteaParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "gordon", - Event: "tag", - Commit: "ef98532add3b2feb7a137426bba1248724367df5", - Ref: "refs/tags/v1.0.0", - PRContext: "created tag v1.0.0", - Message: "", - Sender: "gordon", - Avatar: "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", - Email: "gordon@golang.org", - ForgeURL: "http://gitea.golang.org/gordon/hello-world/src/tag/v1.0.0", + Author: "gordon", + Event: "tag", + Commit: "ef98532add3b2feb7a137426bba1248724367df5", + Ref: "refs/tags/v1.0.0", + PRTitleDescription: "created tag v1.0.0", + Message: "", + Sender: "gordon", + Avatar: "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + Email: "gordon@golang.org", + ForgeURL: "http://gitea.golang.org/gordon/hello-world/src/tag/v1.0.0", }, }, { @@ -209,19 +209,19 @@ func TestGiteaParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "gordon", - Event: "pull_request", - Commit: "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c", - Branch: "main", - Ref: "refs/pull/1/head", - Refspec: "feature/changes:main", - PRContext: "Update the README with new information", - Message: "please merge", - Sender: "gordon", - Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", - Email: "gordon@golang.org", - ForgeURL: "http://gitea.golang.org/gordon/hello-world/pull/1", - PullRequestLabels: []string{}, + Author: "gordon", + Event: "pull_request", + Commit: "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c", + Branch: "main", + Ref: "refs/pull/1/head", + Refspec: "feature/changes:main", + PRTitleDescription: "Update the README with new information", + Message: "please merge", + Sender: "gordon", + Avatar: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", + Email: "gordon@golang.org", + ForgeURL: "http://gitea.golang.org/gordon/hello-world/pull/1", + PullRequestLabels: []string{}, }, }, { @@ -248,18 +248,18 @@ func TestGiteaParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "test", - Event: "pull_request", - Commit: "788ed8d02d3b7fcfcf6386dbcbca696aa1d4dc25", - Branch: "main", - Ref: "refs/pull/2/head", - Refspec: "test-patch-1:main", - PRContext: "New Pull", - Message: "create an awesome pull", - Sender: "test", - Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", - Email: "test@noreply.localhost", - ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2", + Author: "test", + Event: "pull_request", + Commit: "788ed8d02d3b7fcfcf6386dbcbca696aa1d4dc25", + Branch: "main", + Ref: "refs/pull/2/head", + Refspec: "test-patch-1:main", + PRTitleDescription: "New Pull", + Message: "create an awesome pull", + Sender: "test", + Avatar: "http://127.0.0.1:3000/avatars/dd46a756faad4727fb679320751f6dea", + Email: "test@noreply.localhost", + ForgeURL: "http://127.0.0.1:3000/Test-CI/multi-line-secrets/pulls/2", PullRequestLabels: []string{ "Kind/Bug", "Kind/Security", @@ -289,19 +289,19 @@ func TestGiteaParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "anbraten", - Event: "pull_request_closed", - Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", - Branch: "main", - Ref: "refs/pull/1/head", - Refspec: "anbraten-patch-1:main", - PRContext: "Adjust file", - Message: "", - Sender: "anbraten", - Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", - Email: "anbraten@sender.gitea.com", - ForgeURL: "https://gitea.com/anbraten/test-repo/pulls/1", - PullRequestLabels: []string{}, + Author: "anbraten", + Event: "pull_request_closed", + Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", + Branch: "main", + Ref: "refs/pull/1/head", + Refspec: "anbraten-patch-1:main", + PRTitleDescription: "Adjust file", + Message: "", + Sender: "anbraten", + Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", + Email: "anbraten@sender.gitea.com", + ForgeURL: "https://gitea.com/anbraten/test-repo/pulls/1", + PullRequestLabels: []string{}, }, }, { @@ -327,19 +327,19 @@ func TestGiteaParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "anbraten", - Event: "pull_request_closed", - Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", - Branch: "main", - Ref: "refs/pull/1/head", - Refspec: "anbraten-patch-1:main", - PRContext: "Adjust file", - Message: "", - Sender: "anbraten", - Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", - Email: "anbraten@noreply.gitea.com", - ForgeURL: "https://gitea.com/anbraten/test-repo/pulls/1", - PullRequestLabels: []string{}, + Author: "anbraten", + Event: "pull_request_closed", + Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4", + Branch: "main", + Ref: "refs/pull/1/head", + Refspec: "anbraten-patch-1:main", + PRTitleDescription: "Adjust file", + Message: "", + Sender: "anbraten", + Avatar: "https://seccdn.libravatar.org/avatar/fc9b6fe77c6b732a02925a62a81f05a0?d=identicon", + Email: "anbraten@noreply.gitea.com", + ForgeURL: "https://gitea.com/anbraten/test-repo/pulls/1", + PullRequestLabels: []string{}, }, }, { @@ -366,16 +366,16 @@ func TestGiteaParser(t *testing.T) { }, }, pipe: &model.Pipeline{ - Author: "anbraten", - Event: "release", - Branch: "main", - Ref: "refs/tags/0.0.5", - PRContext: "created release Version 0.0.5", - Message: "release notes", - Sender: "anbraten", - Avatar: "https://git.xxx/user/avatar/anbraten/-1", - Email: "anbraten@noreply.xxx", - ForgeURL: "https://git.xxx/anbraten/demo/releases/tag/0.0.5", + Author: "anbraten", + Event: "release", + Branch: "main", + Ref: "refs/tags/0.0.5", + PRTitleDescription: "created release Version 0.0.5", + Message: "release notes", + Sender: "anbraten", + Avatar: "https://git.xxx/user/avatar/anbraten/-1", + Email: "anbraten@noreply.xxx", + ForgeURL: "https://git.xxx/anbraten/demo/releases/tag/0.0.5", }, }, } diff --git a/server/forge/github/convert_test.go b/server/forge/github/convert_test.go index 7715625cf7..65e5a2db8b 100644 --- a/server/forge/github/convert_test.go +++ b/server/forge/github/convert_test.go @@ -214,7 +214,7 @@ func Test_helper(t *testing.T) { g.Assert(pipeline.Refspec).Equal("changes:main") g.Assert(pipeline.Commit).Equal(*from.PullRequest.Head.SHA) g.Assert(pipeline.Message).Equal(*from.PullRequest.Title) - g.Assert(pipeline.PRContext).Equal(*from.PullRequest.Title) + g.Assert(pipeline.PRTitleDescription).Equal(*from.PullRequest.Title) g.Assert(pipeline.Author).Equal(*from.PullRequest.User.Login) g.Assert(pipeline.Avatar).Equal(*from.PullRequest.User.AvatarURL) g.Assert(pipeline.Sender).Equal(*from.Sender.Login) diff --git a/server/forge/github/parse.go b/server/forge/github/parse.go index da612c619a..1bc832cf1d 100644 --- a/server/forge/github/parse.go +++ b/server/forge/github/parse.go @@ -161,16 +161,16 @@ func parsePullHook(hook *github.PullRequestEvent, merge bool) (*github.PullReque } pipeline := &model.Pipeline{ - Event: event, - Commit: hook.GetPullRequest().GetHead().GetSHA(), - ForgeURL: hook.GetPullRequest().GetHTMLURL(), - Ref: fmt.Sprintf(headRefs, hook.GetPullRequest().GetNumber()), - Branch: hook.GetPullRequest().GetBase().GetRef(), - Message: hook.GetChanges().GetTitle().GetFrom() + "\n" + hook.GetChanges().GetBody().GetFrom(), - Author: hook.GetPullRequest().GetUser().GetLogin(), - Avatar: hook.GetPullRequest().GetUser().GetAvatarURL(), - PRContext: hook.GetPullRequest().GetTitle() + "\n" + hook.GetPullRequest().GetBody(), - Sender: hook.GetSender().GetLogin(), + Event: event, + Commit: hook.GetPullRequest().GetHead().GetSHA(), + ForgeURL: hook.GetPullRequest().GetHTMLURL(), + Ref: fmt.Sprintf(headRefs, hook.GetPullRequest().GetNumber()), + Branch: hook.GetPullRequest().GetBase().GetRef(), + Message: hook.GetChanges().GetTitle().GetFrom() + "\n" + hook.GetChanges().GetBody().GetFrom(), + Author: hook.GetPullRequest().GetUser().GetLogin(), + Avatar: hook.GetPullRequest().GetUser().GetAvatarURL(), + PRTitleDescription: hook.GetPullRequest().GetTitle() + "\n" + hook.GetPullRequest().GetBody(), + Sender: hook.GetSender().GetLogin(), Refspec: fmt.Sprintf(refSpec, hook.GetPullRequest().GetHead().GetRef(), hook.GetPullRequest().GetBase().GetRef(), diff --git a/server/forge/github/parse_test.go b/server/forge/github/parse_test.go index 9b45976278..c13b67357c 100644 --- a/server/forge/github/parse_test.go +++ b/server/forge/github/parse_test.go @@ -75,7 +75,7 @@ func Test_parser(t *testing.T) { g.Assert(r).IsNotNil() g.Assert(b).IsNotNil() g.Assert(b.Event).Equal(model.EventPush) - assert.EqualValues(t, "Fix multiline secrets replacer (#700)", b.PRContext) + assert.EqualValues(t, "Fix multiline secrets replacer (#700)", b.PRTitleDescription) assert.EqualValues(t, "Fix multiline secrets replacer (#700)\n\n* Fix multiline secrets replacer\r\n\r\n* Add tests", b.Message) sort.Strings(b.ChangedFiles) g.Assert(b.ChangedFiles).Equal([]string{"pipeline/shared/replace_secrets.go", "pipeline/shared/replace_secrets_test.go"}) diff --git a/server/forge/gitlab/convert.go b/server/forge/gitlab/convert.go index 4361bdd8f6..2a4e110454 100644 --- a/server/forge/gitlab/convert.go +++ b/server/forge/gitlab/convert.go @@ -134,7 +134,7 @@ func convertMergeRequestHook(hook *gitlab.MergeEvent, req *http.Request) (int, * pipeline.Avatar = getUserAvatar(pipeline.Email) } - pipeline.PRContext = obj.Title + "\n" + obj.Description + pipeline.PRTitleDescription = obj.Title + "\n" + obj.Description pipeline.ForgeURL = obj.URL pipeline.PullRequestLabels = convertLabels(hook.Labels) diff --git a/server/forge/gitlab/gitlab_test.go b/server/forge/gitlab/gitlab_test.go index 206ace36e2..28ea02bff2 100644 --- a/server/forge/gitlab/gitlab_test.go +++ b/server/forge/gitlab/gitlab_test.go @@ -201,7 +201,7 @@ func Test_GitLab(t *testing.T) { assert.Equal(t, "main", hookRepo.Branch) assert.Equal(t, "anbraten", hookRepo.Owner) assert.Equal(t, "woodpecker", hookRepo.Name) - assert.Equal(t, "Update client.go 🎉", pipeline.PRContext) + assert.Equal(t, "Update client.go 🎉", pipeline.PRTitleDescription) assert.Len(t, pipeline.ChangedFiles, 0) // see L217 assert.Equal(t, model.EventPull, pipeline.Event) } @@ -252,7 +252,7 @@ func Test_GitLab(t *testing.T) { assert.Equal(t, "main", hookRepo.Branch) assert.Equal(t, "anbraten", hookRepo.Owner) assert.Equal(t, "woodpecker-test", hookRepo.Name) - assert.Equal(t, "Add new file", pipeline.PRContext) + assert.Equal(t, "Add new file", pipeline.PRTitleDescription) assert.Len(t, pipeline.ChangedFiles, 0) // see L217 assert.Equal(t, model.EventPullClosed, pipeline.Event) } @@ -273,7 +273,7 @@ func Test_GitLab(t *testing.T) { assert.Equal(t, "main", hookRepo.Branch) assert.Equal(t, "anbraten", hookRepo.Owner) assert.Equal(t, "woodpecker-test", hookRepo.Name) - assert.Equal(t, "Add new file", pipeline.PRContext) + assert.Equal(t, "Add new file", pipeline.PRTitleDescription) assert.Len(t, pipeline.ChangedFiles, 0) // see L217 assert.Equal(t, model.EventPullClosed, pipeline.Event) } @@ -292,7 +292,7 @@ func Test_GitLab(t *testing.T) { if assert.NotNil(t, hookRepo) && assert.NotNil(t, pipeline) { assert.Equal(t, "refs/tags/0.0.2", pipeline.Ref) assert.Equal(t, "ci", hookRepo.Name) - assert.Equal(t, "created release Awesome version 0.0.2", pipeline.PRContext) + assert.Equal(t, "created release Awesome version 0.0.2", pipeline.PRTitleDescription) assert.Equal(t, "new version desc", pipeline.Message) assert.Equal(t, model.EventRelease, pipeline.Event) } diff --git a/server/model/pipeline.go b/server/model/pipeline.go index 63502ee2ad..1123e54e2c 100644 --- a/server/model/pipeline.go +++ b/server/model/pipeline.go @@ -38,7 +38,7 @@ type Pipeline struct { Branch string `json:"branch" xorm:"branch"` Ref string `json:"ref" xorm:"ref"` Refspec string `json:"refspec" xorm:"refspec"` - PRContext string `json:"title" xorm:"title"` + PRTitleDescription string `json:"title" xorm:"title"` Message string `json:"message" xorm:"TEXT 'message'"` Timestamp int64 `json:"timestamp" xorm:"'timestamp'"` Sender string `json:"sender" xorm:"sender"` // uses reported user for webhooks and name of cron for cron pipelines diff --git a/web/src/components/pipeline-feed/PipelineFeedItem.vue b/web/src/components/pipeline-feed/PipelineFeedItem.vue index eb5916b5ae..936831dd01 100644 --- a/web/src/components/pipeline-feed/PipelineFeedItem.vue +++ b/web/src/components/pipeline-feed/PipelineFeedItem.vue @@ -12,7 +12,7 @@ {{ repo?.owner }} / {{ repo?.name }} - {{ title }} + {{ shortMessage }}
@@ -45,5 +45,5 @@ const repoStore = useRepoStore(); const pipeline = toRef(props, 'pipeline'); const repo = repoStore.getRepo(computed(() => pipeline.value.repo_id)); -const { since, duration, message, title, created } = usePipeline(pipeline); +const { since, duration, shortMessage, message, created } = usePipeline(pipeline); diff --git a/web/src/components/repo/pipeline/PipelineItem.vue b/web/src/components/repo/pipeline/PipelineItem.vue index 228eebb377..179c522d0c 100644 --- a/web/src/components/repo/pipeline/PipelineItem.vue +++ b/web/src/components/repo/pipeline/PipelineItem.vue @@ -46,7 +46,7 @@ {{ $t('created') }} {{ $t('triggered') }} {{ $t('triggered') }} - + {{ $t('by_user', { user: pipeline.author }) }}
@@ -89,7 +89,7 @@ const props = defineProps<{ }>(); const pipeline = toRef(props, 'pipeline'); -const { since, duration, message, shortMessage, title, prettyRef, created } = usePipeline(pipeline); +const { since, duration, message, shortMessage, prTitle, prTitleWithDescription, prettyRef, created } = usePipeline(pipeline); const pipelineEventTitle = computed(() => { switch (pipeline.value.event) { diff --git a/web/src/compositions/usePipeline.ts b/web/src/compositions/usePipeline.ts index 0bd1e3beca..d02409fdbb 100644 --- a/web/src/compositions/usePipeline.ts +++ b/web/src/compositions/usePipeline.ts @@ -77,7 +77,8 @@ export default (pipeline: Ref) => { const message = computed(() => convertEmojis(pipeline.value?.message ?? '')); const shortMessage = computed(() => message.value.split('\n')[0]); - const title = computed(() => convertEmojis(pipeline.value?.title ?? '')); + const prTitleWithDescription = computed(() => convertEmojis(pipeline.value?.title ?? '')); + const prTitle = computed(() => prTitleWithDescription.value.split('\n')[0]); const prettyRef = computed(() => { if (pipeline.value?.event === 'push' || pipeline.value?.event === 'deployment') { @@ -113,5 +114,5 @@ export default (pipeline: Ref) => { return toLocaleString(new Date(start * 1000)); }); - return { since, duration, message, shortMessage, title, prettyRef, created }; + return { since, duration, message, shortMessage, prTitle, prTitleWithDescription, prettyRef, created }; }; diff --git a/web/src/views/repo/pipeline/PipelineWrapper.vue b/web/src/views/repo/pipeline/PipelineWrapper.vue index 2199f434c7..bce497656f 100644 --- a/web/src/views/repo/pipeline/PipelineWrapper.vue +++ b/web/src/views/repo/pipeline/PipelineWrapper.vue @@ -28,7 +28,7 @@ {{ $t('repo.pipeline.pipeline', { pipelineId }) }} - {{ title }} + {{ shortMessage }}