}
if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventPush, &api.PushPayload{
- Ref: opts.RefFullName,
- Before: opts.OldCommitID,
- After: opts.NewCommitID,
- CompareURL: setting.AppURL + commits.CompareURL,
- Commits: apiCommits,
- HeadCommit: apiHeadCommit,
- Repo: convert.ToRepo(repo, perm.AccessModeOwner),
- Pusher: apiPusher,
- Sender: apiPusher,
+ Ref: opts.RefFullName,
+ Before: opts.OldCommitID,
+ After: opts.NewCommitID,
+ CompareURL: setting.AppURL + commits.CompareURL,
+ Commits: apiCommits,
+ TotalCommits: commits.Len,
+ HeadCommit: apiHeadCommit,
+ Repo: convert.ToRepo(repo, perm.AccessModeOwner),
+ Pusher: apiPusher,
+ Sender: apiPusher,
}); err != nil {
log.Error("PrepareWebhooks: %v", err)
}
}
if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventPush, &api.PushPayload{
- Ref: opts.RefFullName,
- Before: opts.OldCommitID,
- After: opts.NewCommitID,
- CompareURL: setting.AppURL + commits.CompareURL,
- Commits: apiCommits,
- HeadCommit: apiHeadCommit,
- Repo: convert.ToRepo(repo, perm.AccessModeOwner),
- Pusher: apiPusher,
- Sender: apiPusher,
+ Ref: opts.RefFullName,
+ Before: opts.OldCommitID,
+ After: opts.NewCommitID,
+ CompareURL: setting.AppURL + commits.CompareURL,
+ Commits: apiCommits,
+ TotalCommits: commits.Len,
+ HeadCommit: apiHeadCommit,
+ Repo: convert.ToRepo(repo, perm.AccessModeOwner),
+ Pusher: apiPusher,
+ Sender: apiPusher,
}); err != nil {
log.Error("PrepareWebhooks: %v", err)
}
// PushPayload represents a payload information of push event.
type PushPayload struct {
- Ref string `json:"ref"`
- Before string `json:"before"`
- After string `json:"after"`
- CompareURL string `json:"compare_url"`
- Commits []*PayloadCommit `json:"commits"`
- HeadCommit *PayloadCommit `json:"head_commit"`
- Repo *Repository `json:"repository"`
- Pusher *User `json:"pusher"`
- Sender *User `json:"sender"`
+ Ref string `json:"ref"`
+ Before string `json:"before"`
+ After string `json:"after"`
+ CompareURL string `json:"compare_url"`
+ Commits []*PayloadCommit `json:"commits"`
+ TotalCommits int `json:"total_commits"`
+ HeadCommit *PayloadCommit `json:"head_commit"`
+ Repo *Repository `json:"repository"`
+ Pusher *User `json:"pusher"`
+ Sender *User `json:"sender"`
}
// JSONPayload FIXME
commitID := ctx.Repo.Commit.ID.String()
if err := webhook_service.PrepareWebhook(hook, ctx.Repo.Repository, webhook.HookEventPush, &api.PushPayload{
- Ref: ref,
- Before: commitID,
- After: commitID,
- CompareURL: setting.AppURL + ctx.Repo.Repository.ComposeCompareURL(commitID, commitID),
- Commits: []*api.PayloadCommit{commit},
- HeadCommit: commit,
- Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone),
- Pusher: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone),
- Sender: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone),
+ Ref: ref,
+ Before: commitID,
+ After: commitID,
+ CompareURL: setting.AppURL + ctx.Repo.Repository.ComposeCompareURL(commitID, commitID),
+ Commits: []*api.PayloadCommit{commit},
+ TotalCommits: 1,
+ HeadCommit: commit,
+ Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone),
+ Pusher: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone),
+ Sender: convert.ToUserWithAccessMode(ctx.Doer, perm.AccessModeNone),
}); err != nil {
ctx.Error(http.StatusInternalServerError, "PrepareWebhook: ", err)
return
commitID := commit.ID.String()
p := &api.PushPayload{
- Ref: git.BranchPrefix + ctx.Repo.Repository.DefaultBranch,
- Before: commitID,
- After: commitID,
- CompareURL: setting.AppURL + ctx.Repo.Repository.ComposeCompareURL(commitID, commitID),
- Commits: []*api.PayloadCommit{apiCommit},
- HeadCommit: apiCommit,
- Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone),
- Pusher: apiUser,
- Sender: apiUser,
+ Ref: git.BranchPrefix + ctx.Repo.Repository.DefaultBranch,
+ Before: commitID,
+ After: commitID,
+ CompareURL: setting.AppURL + ctx.Repo.Repository.ComposeCompareURL(commitID, commitID),
+ Commits: []*api.PayloadCommit{apiCommit},
+ TotalCommits: 1,
+ HeadCommit: apiCommit,
+ Repo: convert.ToRepo(ctx.Repo.Repository, perm.AccessModeNone),
+ Pusher: apiUser,
+ Sender: apiUser,
}
if err := webhook_service.PrepareWebhook(w, ctx.Repo.Repository, webhook.HookEventPush, p); err != nil {
ctx.Flash.Error("PrepareWebhook: " + err.Error())
)
var titleLink, linkText string
- if len(p.Commits) == 1 {
+ if p.TotalCommits == 1 {
commitDesc = "1 new commit"
titleLink = p.Commits[0].URL
- linkText = fmt.Sprintf("view commit %s", p.Commits[0].ID[:7])
+ linkText = "view commit"
} else {
- commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
+ commitDesc = fmt.Sprintf("%d new commits", p.TotalCommits)
titleLink = p.CompareURL
- linkText = fmt.Sprintf("view commit %s...%s", p.Commits[0].ID[:7], p.Commits[len(p.Commits)-1].ID[:7])
+ linkText = "view commits"
}
if titleLink == "" {
titleLink = p.Repo.HTMLURL + "/src/" + util.PathEscapeSegments(branchName)
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)
assert.Equal(t, "[test/repo:test] 2 new commits", pl.(*DingtalkPayload).ActionCard.Title)
- assert.Equal(t, "view commit 2020558...2020558", pl.(*DingtalkPayload).ActionCard.SingleTitle)
+ assert.Equal(t, "view commits", pl.(*DingtalkPayload).ActionCard.SingleTitle)
assert.Equal(t, "http://localhost:3000/test/repo/src/test", parseRealSingleURL(pl.(*DingtalkPayload).ActionCard.SingleURL))
})
)
var titleLink string
- if len(p.Commits) == 1 {
+ if p.TotalCommits == 1 {
commitDesc = "1 new commit"
titleLink = p.Commits[0].URL
} else {
- commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
+ commitDesc = fmt.Sprintf("%d new commits", p.TotalCommits)
titleLink = p.CompareURL
}
if titleLink == "" {
}
return &api.PushPayload{
- Ref: "refs/heads/test",
- Before: "2020558fe2e34debb818a514715839cabd25e777",
- After: "2020558fe2e34debb818a514715839cabd25e778",
- CompareURL: "",
- HeadCommit: commit,
- Commits: []*api.PayloadCommit{commit, commit},
+ Ref: "refs/heads/test",
+ Before: "2020558fe2e34debb818a514715839cabd25e777",
+ After: "2020558fe2e34debb818a514715839cabd25e778",
+ CompareURL: "",
+ HeadCommit: commit,
+ Commits: []*api.PayloadCommit{commit, commit},
+ TotalCommits: 2,
Repo: &api.Repository{
HTMLURL: "http://localhost:3000/test/repo",
Name: "repo",
func (m *MatrixPayloadUnsafe) Push(p *api.PushPayload) (api.Payloader, error) {
var commitDesc string
- if len(p.Commits) == 1 {
+ if p.TotalCommits == 1 {
commitDesc = "1 commit"
} else {
- commitDesc = fmt.Sprintf("%d commits", len(p.Commits))
+ commitDesc = fmt.Sprintf("%d commits", p.TotalCommits)
}
repoLink := MatrixLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName)
)
var titleLink string
- if len(p.Commits) == 1 {
+ if p.TotalCommits == 1 {
commitDesc = "1 new commit"
titleLink = p.Commits[0].URL
} else {
- commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
+ commitDesc = fmt.Sprintf("%d new commits", p.TotalCommits)
titleLink = p.CompareURL
}
if titleLink == "" {
text,
titleLink,
greenColor,
- &MSTeamsFact{"Commit count:", fmt.Sprintf("%d", len(p.Commits))},
+ &MSTeamsFact{"Commit count:", fmt.Sprintf("%d", p.TotalCommits)},
), nil
}
commitString string
)
- if len(p.Commits) == 1 {
+ if p.TotalCommits == 1 {
commitDesc = "1 new commit"
} else {
- commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
+ commitDesc = fmt.Sprintf("%d new commits", p.TotalCommits)
}
if len(p.CompareURL) > 0 {
commitString = SlackLinkFormatter(p.CompareURL, commitDesc)
)
var titleLink string
- if len(p.Commits) == 1 {
+ if p.TotalCommits == 1 {
commitDesc = "1 new commit"
titleLink = p.Commits[0].URL
} else {
- commitDesc = fmt.Sprintf("%d new commits", len(p.Commits))
+ commitDesc = fmt.Sprintf("%d new commits", p.TotalCommits)
titleLink = p.CompareURL
}
if titleLink == "" {
for i, commit := range p.Commits {
var authorName string
if commit.Author != nil {
- authorName = "Author:" + commit.Author.Name
+ authorName = "Author: " + commit.Author.Name
}
message := strings.ReplaceAll(commit.Message, "\n\n", "\r\n")