Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance pipeline message and pr title #3421

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9b85108
Update pipeline list UI
anbraten Jan 30, 2024
79df566
Merge remote-tracking branch 'upstream/main' into update-pipeline-list
anbraten Feb 10, 2024
9bfd2f3
gitea parse email too
6543 Feb 21, 2024
d07b161
example how tests should be
6543 Feb 21, 2024
fb627db
fix similar bugs
6543 Feb 22, 2024
0cf1fb6
tests tests tests
6543 Feb 22, 2024
9a9231b
Merge branch 'main' into gitea-parse-mail-too
6543 Feb 22, 2024
55441bf
move old tests to new tests
6543 Feb 22, 2024
2b4e136
tags dont have branch info
6543 Feb 22, 2024
7165ef5
extend tests and finish migration
6543 Feb 22, 2024
c691b31
fix
6543 Feb 22, 2024
7db9650
actually differ between title and message and use it propperly
6543 Feb 22, 2024
d1f49c0
refactor
6543 Feb 22, 2024
7f23b07
update tests etc...
6543 Feb 22, 2024
f25b7b0
fix test
6543 Feb 22, 2024
ada1819
dont forget the gitlab
6543 Feb 22, 2024
3812c62
bitbucket
6543 Feb 22, 2024
b0d5168
Merge branch 'main' into actually-use-title
6543 Feb 22, 2024
114ba6a
Merge branch 'main' into actually-use-title
6543 Feb 22, 2024
59086fe
Merge branch 'main' into actually-use-title
6543 Feb 23, 2024
9df94d8
Merge branch 'main' into actually-use-title2
6543 Jun 3, 2024
7344a90
Merge remote-tracking branch 'upstream/main' into update-pipeline-list
anbraten Jun 24, 2024
36cf5af
adjust pipeline item
anbraten Jun 25, 2024
a0960bb
Merge branch 'update-pipeline-list' into pr/6543/3421-1
anbraten Jun 25, 2024
f89f4e8
Merge branch 'main' into actually-use-title
anbraten Jun 25, 2024
ba83f48
Merge branch 'main' into actually-use-title
6543 Jun 26, 2024
acc52fc
Merge remote-tracking branch 'upstream/main' into pr/6543/3421
anbraten Jul 2, 2024
756f9ea
Merge branch 'actually-use-title' of github.com:6543-forks/woodpecker…
anbraten Jul 2, 2024
39d5350
adjust pipeline message and title
anbraten Jul 2, 2024
87946fa
adjust ui text
anbraten Jul 2, 2024
651663c
adjust to proper values
anbraten Jul 2, 2024
fbc586e
Merge branch 'main' into actually-use-title
6543 Jul 2, 2024
020aa18
Merge remote-tracking branch 'upstream/main' into pr/6543/3421
anbraten Jul 13, 2024
6c12da1
Merge branch 'actually-use-title' of github.com:6543-forks/woodpecker…
anbraten Jul 13, 2024
168b1eb
Merge remote-tracking branch 'upstream/main' into pr/6543/3421
anbraten Jul 13, 2024
5f9c57c
Merge branch 'main' into actually-use-title
qwerty287 Jul 15, 2024
c6a8677
Merge branch 'main' into actually-use-title
6543 Nov 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions server/forge/bitbucket/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions server/forge/bitbucketdatacenter/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,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,
Expand All @@ -115,7 +124,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,
Expand Down
2 changes: 1 addition & 1 deletion server/forge/gitea/fixtures/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
82 changes: 44 additions & 38 deletions server/forge/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,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 {
Expand All @@ -527,6 +536,14 @@ func (c *Gitea) Hook(ctx context.Context, r *http.Request) (*model.Repo, *model.
}
}

// 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.Message = tag.Message
}

return repo, pipeline, nil
}

Expand Down Expand Up @@ -625,25 +642,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) {
Expand All @@ -661,34 +662,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 {
Expand Down
22 changes: 14 additions & 8 deletions server/forge/gitea/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -130,11 +133,13 @@ func pipelineFromTag(hook *pushHook) *model.Pipeline {
ref := strings.TrimPrefix(hook.Ref, "refs/tags/")

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),
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
Avatar: avatar,
Author: hook.Sender.UserName,
Sender: hook.Sender.UserName,
Expand All @@ -161,12 +166,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,
Expand All @@ -188,7 +193,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,
Expand Down
7 changes: 4 additions & 3 deletions server/forge/gitea/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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)
})
Expand Down
17 changes: 11 additions & 6 deletions server/forge/gitea/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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: "[email protected]",
Expand Down Expand Up @@ -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: "[email protected]",
Expand Down Expand Up @@ -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: "[email protected]",
Expand Down Expand Up @@ -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: "[email protected]",
Expand Down Expand Up @@ -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: "[email protected]",
Expand Down Expand Up @@ -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: "[email protected]",
Expand Down
Loading