Skip to content

Commit a501c3c

Browse files
authored
Merge branch 'main' into fix-21448
2 parents 02302a3 + cad9ade commit a501c3c

File tree

13 files changed

+74
-68
lines changed

13 files changed

+74
-68
lines changed

Diff for: modules/notification/webhook/webhook.go

+20-18
Original file line numberDiff line numberDiff line change
@@ -645,15 +645,16 @@ func (m *webhookNotifier) NotifyPushCommits(pusher *user_model.User, repo *repo_
645645
}
646646

647647
if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventPush, &api.PushPayload{
648-
Ref: opts.RefFullName,
649-
Before: opts.OldCommitID,
650-
After: opts.NewCommitID,
651-
CompareURL: setting.AppURL + commits.CompareURL,
652-
Commits: apiCommits,
653-
HeadCommit: apiHeadCommit,
654-
Repo: convert.ToRepo(repo, perm.AccessModeOwner),
655-
Pusher: apiPusher,
656-
Sender: apiPusher,
648+
Ref: opts.RefFullName,
649+
Before: opts.OldCommitID,
650+
After: opts.NewCommitID,
651+
CompareURL: setting.AppURL + commits.CompareURL,
652+
Commits: apiCommits,
653+
TotalCommits: commits.Len,
654+
HeadCommit: apiHeadCommit,
655+
Repo: convert.ToRepo(repo, perm.AccessModeOwner),
656+
Pusher: apiPusher,
657+
Sender: apiPusher,
657658
}); err != nil {
658659
log.Error("PrepareWebhooks: %v", err)
659660
}
@@ -875,15 +876,16 @@ func (m *webhookNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *r
875876
}
876877

877878
if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventPush, &api.PushPayload{
878-
Ref: opts.RefFullName,
879-
Before: opts.OldCommitID,
880-
After: opts.NewCommitID,
881-
CompareURL: setting.AppURL + commits.CompareURL,
882-
Commits: apiCommits,
883-
HeadCommit: apiHeadCommit,
884-
Repo: convert.ToRepo(repo, perm.AccessModeOwner),
885-
Pusher: apiPusher,
886-
Sender: apiPusher,
879+
Ref: opts.RefFullName,
880+
Before: opts.OldCommitID,
881+
After: opts.NewCommitID,
882+
CompareURL: setting.AppURL + commits.CompareURL,
883+
Commits: apiCommits,
884+
TotalCommits: commits.Len,
885+
HeadCommit: apiHeadCommit,
886+
Repo: convert.ToRepo(repo, perm.AccessModeOwner),
887+
Pusher: apiPusher,
888+
Sender: apiPusher,
887889
}); err != nil {
888890
log.Error("PrepareWebhooks: %v", err)
889891
}

Diff for: modules/structs/hook.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,16 @@ func (p *ReleasePayload) JSONPayload() ([]byte, error) {
267267

268268
// PushPayload represents a payload information of push event.
269269
type PushPayload struct {
270-
Ref string `json:"ref"`
271-
Before string `json:"before"`
272-
After string `json:"after"`
273-
CompareURL string `json:"compare_url"`
274-
Commits []*PayloadCommit `json:"commits"`
275-
HeadCommit *PayloadCommit `json:"head_commit"`
276-
Repo *Repository `json:"repository"`
277-
Pusher *User `json:"pusher"`
278-
Sender *User `json:"sender"`
270+
Ref string `json:"ref"`
271+
Before string `json:"before"`
272+
After string `json:"after"`
273+
CompareURL string `json:"compare_url"`
274+
Commits []*PayloadCommit `json:"commits"`
275+
TotalCommits int `json:"total_commits"`
276+
HeadCommit *PayloadCommit `json:"head_commit"`
277+
Repo *Repository `json:"repository"`
278+
Pusher *User `json:"pusher"`
279+
Sender *User `json:"sender"`
279280
}
280281

281282
// JSONPayload FIXME

Diff for: routers/api/v1/repo/hook.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,16 @@ func TestHook(ctx *context.APIContext) {
169169

170170
commitID := ctx.Repo.Commit.ID.String()
171171
if err := webhook_service.PrepareWebhook(hook, ctx.Repo.Repository, webhook.HookEventPush, &api.PushPayload{
172-
Ref: ref,
173-
Before: commitID,
174-
After: commitID,
175-
CompareURL: setting.AppURL + ctx.Repo.Repository.ComposeCompareURL(commitID, commitID),
176-
Commits: []*api.PayloadCommit{commit},
177-
HeadCommit: commit,
178-
Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone),
179-
Pusher: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone),
180-
Sender: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone),
172+
Ref: ref,
173+
Before: commitID,
174+
After: commitID,
175+
CompareURL: setting.AppURL + ctx.Repo.Repository.ComposeCompareURL(commitID, commitID),
176+
Commits: []*api.PayloadCommit{commit},
177+
TotalCommits: 1,
178+
HeadCommit: commit,
179+
Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone),
180+
Pusher: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone),
181+
Sender: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone),
181182
}); err != nil {
182183
ctx.Error(http.StatusInternalServerError, "PrepareWebhook: ", err)
183184
return

Diff for: routers/web/repo/webhook.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -668,15 +668,16 @@ func TestWebhook(ctx *context.Context) {
668668

669669
commitID := commit.ID.String()
670670
p := &api.PushPayload{
671-
Ref: git.BranchPrefix + ctx.Repo.Repository.DefaultBranch,
672-
Before: commitID,
673-
After: commitID,
674-
CompareURL: setting.AppURL + ctx.Repo.Repository.ComposeCompareURL(commitID, commitID),
675-
Commits: []*api.PayloadCommit{apiCommit},
676-
HeadCommit: apiCommit,
677-
Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone),
678-
Pusher: apiUser,
679-
Sender: apiUser,
671+
Ref: git.BranchPrefix + ctx.Repo.Repository.DefaultBranch,
672+
Before: commitID,
673+
After: commitID,
674+
CompareURL: setting.AppURL + ctx.Repo.Repository.ComposeCompareURL(commitID, commitID),
675+
Commits: []*api.PayloadCommit{apiCommit},
676+
TotalCommits: 1,
677+
HeadCommit: apiCommit,
678+
Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone),
679+
Pusher: apiUser,
680+
Sender: apiUser,
680681
}
681682
if err := webhook_service.PrepareWebhook(w, ctx.Repo.Repository, webhook.HookEventPush, p); err != nil {
682683
ctx.Flash.Error("PrepareWebhook: " + err.Error())

Diff for: services/webhook/dingtalk.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ func (d *DingtalkPayload) Push(p *api.PushPayload) (api.Payloader, error) {
6767
)
6868

6969
var titleLink, linkText string
70-
if len(p.Commits) == 1 {
70+
if p.TotalCommits == 1 {
7171
commitDesc = "1 new commit"
7272
titleLink = p.Commits[0].URL
73-
linkText = fmt.Sprintf("view commit %s", p.Commits[0].ID[:7])
73+
linkText = "view commit"
7474
} else {
75-
commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
75+
commitDesc = fmt.Sprintf("%d new commits", p.TotalCommits)
7676
titleLink = p.CompareURL
77-
linkText = fmt.Sprintf("view commit %s...%s", p.Commits[0].ID[:7], p.Commits[len(p.Commits)-1].ID[:7])
77+
linkText = "view commits"
7878
}
7979
if titleLink == "" {
8080
titleLink = p.Repo.HTMLURL + "/src/" + util.PathEscapeSegments(branchName)

Diff for: services/webhook/dingtalk_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestDingTalkPayload(t *testing.T) {
8282

8383
assert.Equal(t, "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1\r\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) commit message - user1", pl.(*DingtalkPayload).ActionCard.Text)
8484
assert.Equal(t, "[test/repo:test] 2 new commits", pl.(*DingtalkPayload).ActionCard.Title)
85-
assert.Equal(t, "view commit 2020558...2020558", pl.(*DingtalkPayload).ActionCard.SingleTitle)
85+
assert.Equal(t, "view commits", pl.(*DingtalkPayload).ActionCard.SingleTitle)
8686
assert.Equal(t, "http://localhost:3000/test/repo/src/test", parseRealSingleURL(pl.(*DingtalkPayload).ActionCard.SingleURL))
8787
})
8888

Diff for: services/webhook/discord.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ func (d *DiscordPayload) Push(p *api.PushPayload) (api.Payloader, error) {
142142
)
143143

144144
var titleLink string
145-
if len(p.Commits) == 1 {
145+
if p.TotalCommits == 1 {
146146
commitDesc = "1 new commit"
147147
titleLink = p.Commits[0].URL
148148
} else {
149-
commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
149+
commitDesc = fmt.Sprintf("%d new commits", p.TotalCommits)
150150
titleLink = p.CompareURL
151151
}
152152
if titleLink == "" {

Diff for: services/webhook/general_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ func pushTestPayload() *api.PushPayload {
8282
}
8383

8484
return &api.PushPayload{
85-
Ref: "refs/heads/test",
86-
Before: "2020558fe2e34debb818a514715839cabd25e777",
87-
After: "2020558fe2e34debb818a514715839cabd25e778",
88-
CompareURL: "",
89-
HeadCommit: commit,
90-
Commits: []*api.PayloadCommit{commit, commit},
85+
Ref: "refs/heads/test",
86+
Before: "2020558fe2e34debb818a514715839cabd25e777",
87+
After: "2020558fe2e34debb818a514715839cabd25e778",
88+
CompareURL: "",
89+
HeadCommit: commit,
90+
Commits: []*api.PayloadCommit{commit, commit},
91+
TotalCommits: 2,
9192
Repo: &api.Repository{
9293
HTMLURL: "http://localhost:3000/test/repo",
9394
Name: "repo",

Diff for: services/webhook/matrix.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ func (m *MatrixPayloadUnsafe) Release(p *api.ReleasePayload) (api.Payloader, err
161161
func (m *MatrixPayloadUnsafe) Push(p *api.PushPayload) (api.Payloader, error) {
162162
var commitDesc string
163163

164-
if len(p.Commits) == 1 {
164+
if p.TotalCommits == 1 {
165165
commitDesc = "1 commit"
166166
} else {
167-
commitDesc = fmt.Sprintf("%d commits", len(p.Commits))
167+
commitDesc = fmt.Sprintf("%d commits", p.TotalCommits)
168168
}
169169

170170
repoLink := MatrixLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName)

Diff for: services/webhook/msteams.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ func (m *MSTeamsPayload) Push(p *api.PushPayload) (api.Payloader, error) {
125125
)
126126

127127
var titleLink string
128-
if len(p.Commits) == 1 {
128+
if p.TotalCommits == 1 {
129129
commitDesc = "1 new commit"
130130
titleLink = p.Commits[0].URL
131131
} else {
132-
commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
132+
commitDesc = fmt.Sprintf("%d new commits", p.TotalCommits)
133133
titleLink = p.CompareURL
134134
}
135135
if titleLink == "" {
@@ -156,7 +156,7 @@ func (m *MSTeamsPayload) Push(p *api.PushPayload) (api.Payloader, error) {
156156
text,
157157
titleLink,
158158
greenColor,
159-
&MSTeamsFact{"Commit count:", fmt.Sprintf("%d", len(p.Commits))},
159+
&MSTeamsFact{"Commit count:", fmt.Sprintf("%d", p.TotalCommits)},
160160
), nil
161161
}
162162

Diff for: services/webhook/slack.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ func (s *SlackPayload) Push(p *api.PushPayload) (api.Payloader, error) {
179179
commitString string
180180
)
181181

182-
if len(p.Commits) == 1 {
182+
if p.TotalCommits == 1 {
183183
commitDesc = "1 new commit"
184184
} else {
185-
commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
185+
commitDesc = fmt.Sprintf("%d new commits", p.TotalCommits)
186186
}
187187
if len(p.CompareURL) > 0 {
188188
commitString = SlackLinkFormatter(p.CompareURL, commitDesc)

Diff for: services/webhook/telegram.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ func (t *TelegramPayload) Push(p *api.PushPayload) (api.Payloader, error) {
8989
)
9090

9191
var titleLink string
92-
if len(p.Commits) == 1 {
92+
if p.TotalCommits == 1 {
9393
commitDesc = "1 new commit"
9494
titleLink = p.Commits[0].URL
9595
} else {
96-
commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
96+
commitDesc = fmt.Sprintf("%d new commits", p.TotalCommits)
9797
titleLink = p.CompareURL
9898
}
9999
if titleLink == "" {

Diff for: services/webhook/wechatwork.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (f *WechatworkPayload) Push(p *api.PushPayload) (api.Payloader, error) {
9393
for i, commit := range p.Commits {
9494
var authorName string
9595
if commit.Author != nil {
96-
authorName = "Author" + commit.Author.Name
96+
authorName = "Author: " + commit.Author.Name
9797
}
9898

9999
message := strings.ReplaceAll(commit.Message, "\n\n", "\r\n")

0 commit comments

Comments
 (0)