mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-05 09:55:20 +02:00
feat: add commit limit for webhook payload (#6797)
- Adds a new option `[webhook].PAYLOAD_COMMIT_LIMIT` that limits the amount of commits is sent for each webhook payload, this was previously done via `[ui].FEED_MAX_COMMIT_NUM` which feels incorrect. - The default is 15 for this new option, purely arbitary. - Resolves forgejo/forgejo#6780 - Added unit testing, it's quite a lot because this the notification area is not really easy to test and rather should've been a integration test but that ends up having more complicated than trying doing an unit test. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6797 Reviewed-by: Otto <otto@codeberg.org> Reviewed-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
93f84db542
commit
94845020e8
7 changed files with 268 additions and 18 deletions
|
@ -599,6 +599,10 @@ func (m *webhookNotifier) IssueChangeMilestone(ctx context.Context, doer *user_m
|
|||
}
|
||||
|
||||
func (m *webhookNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
if len(commits.Commits) > setting.Webhook.PayloadCommitLimit {
|
||||
commits.Commits = commits.Commits[:setting.Webhook.PayloadCommitLimit]
|
||||
}
|
||||
|
||||
apiPusher := convert.ToUser(ctx, pusher, nil)
|
||||
apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL())
|
||||
if err != nil {
|
||||
|
@ -840,6 +844,10 @@ func (m *webhookNotifier) DeleteRelease(ctx context.Context, doer *user_model.Us
|
|||
}
|
||||
|
||||
func (m *webhookNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
if len(commits.Commits) > setting.Webhook.PayloadCommitLimit {
|
||||
commits.Commits = commits.Commits[:setting.Webhook.PayloadCommitLimit]
|
||||
}
|
||||
|
||||
apiPusher := convert.ToUser(ctx, pusher, nil)
|
||||
apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL())
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue