Co-Authored-By: edef <edef@edef.eu> Co-Authored-by: Ryan Lahfa <raito@lix.systems> Change-Id: Ica1cda177a236814de900f50a8a61d288f58f519
		
			
				
	
	
		
			79 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
| From 616ea9925fb7a28f1594694665ca89462bcbd461 Mon Sep 17 00:00:00 2001
 | |
| From: Jade Lovelace <software@lfcode.ca>
 | |
| Date: Tue, 19 Mar 2024 18:42:13 -0700
 | |
| Subject: [PATCH] Add a dont_notify option to the issue create api
 | |
| 
 | |
| yolo
 | |
| ---
 | |
|  modules/structs/issue.go     | 1 +
 | |
|  routers/api/v1/repo/issue.go | 2 +-
 | |
|  routers/web/repo/issue.go    | 2 +-
 | |
|  services/issue/issue.go      | 6 +++++-
 | |
|  4 files changed, 8 insertions(+), 3 deletions(-)
 | |
| 
 | |
| diff --git a/modules/structs/issue.go b/modules/structs/issue.go
 | |
| index e2b49e94c5..09d239cdb7 100644
 | |
| --- a/modules/structs/issue.go
 | |
| +++ b/modules/structs/issue.go
 | |
| @@ -97,6 +97,7 @@ type CreateIssueOption struct {
 | |
|  	// list of label ids
 | |
|  	Labels []int64 `json:"labels"`
 | |
|  	Closed bool    `json:"closed"`
 | |
| +	DontNotify bool `json:"dont_notify"`
 | |
|  }
 | |
|  
 | |
|  // EditIssueOption options for editing an issue
 | |
| diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
 | |
| index 0d304dd66d..d9431ef201 100644
 | |
| --- a/routers/api/v1/repo/issue.go
 | |
| +++ b/routers/api/v1/repo/issue.go
 | |
| @@ -708,7 +708,7 @@ func CreateIssue(ctx *context.APIContext) {
 | |
|  		form.Labels = make([]int64, 0)
 | |
|  	}
 | |
|  
 | |
| -	if err := issue_service.NewIssue(ctx, ctx.Repo.Repository, issue, form.Labels, nil, assigneeIDs); err != nil {
 | |
| +	if err := issue_service.NewIssue(ctx, ctx.Repo.Repository, issue, form.Labels, nil, assigneeIDs, !form.DontNotify); err != nil {
 | |
|  		if errors.Is(err, user_model.ErrBlockedByUser) {
 | |
|  			ctx.Error(http.StatusForbidden, "BlockedByUser", err)
 | |
|  			return
 | |
| diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
 | |
| index afa6160d42..dbc500819e 100644
 | |
| --- a/routers/web/repo/issue.go
 | |
| +++ b/routers/web/repo/issue.go
 | |
| @@ -1249,7 +1249,7 @@ func NewIssuePost(ctx *context.Context) {
 | |
|  		Ref:         form.Ref,
 | |
|  	}
 | |
|  
 | |
| -	if err := issue_service.NewIssue(ctx, repo, issue, labelIDs, attachments, assigneeIDs); err != nil {
 | |
| +	if err := issue_service.NewIssue(ctx, repo, issue, labelIDs, attachments, assigneeIDs, true); err != nil {
 | |
|  		if errors.Is(err, user_model.ErrBlockedByUser) {
 | |
|  			ctx.RenderWithErr(ctx.Tr("repo.issues.blocked_by_user"), tplIssueNew, form)
 | |
|  			return
 | |
| diff --git a/services/issue/issue.go b/services/issue/issue.go
 | |
| index 5e726176d0..cdb2f69828 100644
 | |
| --- a/services/issue/issue.go
 | |
| +++ b/services/issue/issue.go
 | |
| @@ -24,7 +24,7 @@ import (
 | |
|  )
 | |
|  
 | |
|  // NewIssue creates new issue with labels for repository.
 | |
| -func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *issues_model.Issue, labelIDs []int64, uuids []string, assigneeIDs []int64) error {
 | |
| +func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *issues_model.Issue, labelIDs []int64, uuids []string, assigneeIDs []int64, notify bool) error {
 | |
|  	// Check if the user is not blocked by the repo's owner.
 | |
|  	if user_model.IsBlocked(ctx, repo.OwnerID, issue.PosterID) {
 | |
|  		return user_model.ErrBlockedByUser
 | |
| @@ -45,7 +45,11 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *issues_mo
 | |
|  		return err
 | |
|  	}
 | |
|  
 | |
| +	if !notify {
 | |
| +		return nil
 | |
| +	}
 | |
|  	notify_service.NewIssue(ctx, issue, mentions)
 | |
| +
 | |
|  	if len(issue.Labels) > 0 {
 | |
|  		notify_service.IssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil)
 | |
|  	}
 | |
| -- 
 | |
| 2.44.0
 | |
| 
 |