Skip to content

Commit

Permalink
Fix release URL in webhooks (#27182) (#27185)
Browse files Browse the repository at this point in the history
Backport #27182 by @jolheiser

Resolves #27180

`URL` points to the API URL, `HTMLURL` points to the web page.

Notably, however, for PRs they are the same URL. I switched them to use
HTMLURL to match the rest of the codebase terminology.

Co-authored-by: John Olheiser <john.olheiser@gmail.com>
  • Loading branch information
GiteaBot and jolheiser authored Sep 21, 2023
1 parent 81ae35a commit 7750a73
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion services/webhook/dingtalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (d *DingtalkPayload) Repository(p *api.RepositoryPayload) (api.Payloader, e
func (d *DingtalkPayload) Release(p *api.ReleasePayload) (api.Payloader, error) {
text, _ := getReleasePayloadInfo(p, noneLinkFormatter, true)

return createDingtalkPayload(text, text, "view release", p.Release.URL), nil
return createDingtalkPayload(text, text, "view release", p.Release.HTMLURL), nil
}

func createDingtalkPayload(title, text, singleTitle, singleURL string) *DingtalkPayload {
Expand Down
2 changes: 1 addition & 1 deletion services/webhook/dingtalk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func TestDingTalkPayload(t *testing.T) {
assert.Equal(t, "[test/repo] Release created: v1.0 by user1", pl.(*DingtalkPayload).ActionCard.Text)
assert.Equal(t, "[test/repo] Release created: v1.0 by user1", pl.(*DingtalkPayload).ActionCard.Title)
assert.Equal(t, "view release", pl.(*DingtalkPayload).ActionCard.SingleTitle)
assert.Equal(t, "http://localhost:3000/api/v1/repos/test/repo/releases/2", parseRealSingleURL(pl.(*DingtalkPayload).ActionCard.SingleURL))
assert.Equal(t, "http://localhost:3000/test/repo/releases/tag/v1.0", parseRealSingleURL(pl.(*DingtalkPayload).ActionCard.SingleURL))
})
}

Expand Down
2 changes: 1 addition & 1 deletion services/webhook/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (d *DiscordPayload) Wiki(p *api.WikiPayload) (api.Payloader, error) {
func (d *DiscordPayload) Release(p *api.ReleasePayload) (api.Payloader, error) {
text, color := getReleasePayloadInfo(p, noneLinkFormatter, false)

return d.createPayload(p.Sender, text, p.Release.Note, p.Release.URL, color), nil
return d.createPayload(p.Sender, text, p.Release.Note, p.Release.HTMLURL, color), nil
}

// GetDiscordPayload converts a discord webhook into a DiscordPayload
Expand Down
2 changes: 1 addition & 1 deletion services/webhook/discord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func TestDiscordPayload(t *testing.T) {
assert.Len(t, pl.(*DiscordPayload).Embeds, 1)
assert.Equal(t, "[test/repo] Release created: v1.0", pl.(*DiscordPayload).Embeds[0].Title)
assert.Equal(t, "Note of first stable release", pl.(*DiscordPayload).Embeds[0].Description)
assert.Equal(t, "http://localhost:3000/api/v1/repos/test/repo/releases/2", pl.(*DiscordPayload).Embeds[0].URL)
assert.Equal(t, "http://localhost:3000/test/repo/releases/tag/v1.0", pl.(*DiscordPayload).Embeds[0].URL)
assert.Equal(t, p.Sender.UserName, pl.(*DiscordPayload).Embeds[0].Author.Name)
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.(*DiscordPayload).Embeds[0].Author.URL)
assert.Equal(t, p.Sender.AvatarURL, pl.(*DiscordPayload).Embeds[0].Author.IconURL)
Expand Down
2 changes: 1 addition & 1 deletion services/webhook/general_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func pullReleaseTestPayload() *api.ReleasePayload {
Target: "master",
Title: "First stable release",
Note: "Note of first stable release",
URL: "http://localhost:3000/api/v1/repos/test/repo/releases/2",
HTMLURL: "http://localhost:3000/test/repo/releases/tag/v1.0",
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion services/webhook/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (m *MatrixPayload) PullRequest(p *api.PullRequestPayload) (api.Payloader, e
func (m *MatrixPayload) Review(p *api.PullRequestPayload, event webhook_module.HookEventType) (api.Payloader, error) {
senderLink := MatrixLinkFormatter(setting.AppURL+url.PathEscape(p.Sender.UserName), p.Sender.UserName)
title := fmt.Sprintf("#%d %s", p.Index, p.PullRequest.Title)
titleLink := MatrixLinkFormatter(p.PullRequest.URL, title)
titleLink := MatrixLinkFormatter(p.PullRequest.HTMLURL, title)
repoLink := MatrixLinkFormatter(p.Repository.HTMLURL, p.Repository.FullName)
var text string

Expand Down
2 changes: 1 addition & 1 deletion services/webhook/msteams.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (m *MSTeamsPayload) Release(p *api.ReleasePayload) (api.Payloader, error) {
p.Sender,
title,
"",
p.Release.URL,
p.Release.HTMLURL,
color,
&MSTeamsFact{"Tag:", p.Release.TagName},
), nil
Expand Down
2 changes: 1 addition & 1 deletion services/webhook/msteams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func TestMSTeamsPayload(t *testing.T) {
}
assert.Len(t, pl.(*MSTeamsPayload).PotentialAction, 1)
assert.Len(t, pl.(*MSTeamsPayload).PotentialAction[0].Targets, 1)
assert.Equal(t, "http://localhost:3000/api/v1/repos/test/repo/releases/2", pl.(*MSTeamsPayload).PotentialAction[0].Targets[0].URI)
assert.Equal(t, "http://localhost:3000/test/repo/releases/tag/v1.0", pl.(*MSTeamsPayload).PotentialAction[0].Targets[0].URI)
})
}

Expand Down
2 changes: 1 addition & 1 deletion services/webhook/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (s *SlackPayload) PullRequest(p *api.PullRequestPayload) (api.Payloader, er
attachments = append(attachments, SlackAttachment{
Color: fmt.Sprintf("%x", color),
Title: issueTitle,
TitleLink: p.PullRequest.URL,
TitleLink: p.PullRequest.HTMLURL,
Text: attachmentText,
})
}
Expand Down

0 comments on commit 7750a73

Please sign in to comment.