mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Make API EditIssue and EditPullRequest issue notifications (#11123)
* Make API EditIssue and EditPullRequest issue notifications Restructure models.UpdateIssueByAPI and EditIssue/EditPullRequest to issue notifications Fix #10014 Signed-off-by: Andrew Thornton <art27@cantab.net> * As per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> * update status! Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: John Olheiser <john.olheiser@gmail.com> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
		@@ -16,6 +16,7 @@ import (
 | 
			
		||||
	"code.gitea.io/gitea/modules/convert"
 | 
			
		||||
	"code.gitea.io/gitea/modules/git"
 | 
			
		||||
	"code.gitea.io/gitea/modules/log"
 | 
			
		||||
	"code.gitea.io/gitea/modules/notification"
 | 
			
		||||
	api "code.gitea.io/gitea/modules/structs"
 | 
			
		||||
	"code.gitea.io/gitea/modules/timeutil"
 | 
			
		||||
	"code.gitea.io/gitea/routers/api/v1/utils"
 | 
			
		||||
@@ -409,6 +410,7 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	oldTitle := issue.Title
 | 
			
		||||
	if len(form.Title) > 0 {
 | 
			
		||||
		issue.Title = form.Title
 | 
			
		||||
	}
 | 
			
		||||
@@ -485,19 +487,25 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err = models.UpdateIssueByAPI(issue); err != nil {
 | 
			
		||||
	if form.State != nil {
 | 
			
		||||
		issue.IsClosed = (api.StateClosed == api.StateType(*form.State))
 | 
			
		||||
	}
 | 
			
		||||
	statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.User)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if models.IsErrDependenciesLeft(err) {
 | 
			
		||||
			ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "UpdateIssueByAPI", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if form.State != nil {
 | 
			
		||||
		if err = issue_service.ChangeStatus(issue, ctx.User, api.StateClosed == api.StateType(*form.State)); err != nil {
 | 
			
		||||
			if models.IsErrDependenciesLeft(err) {
 | 
			
		||||
				ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "ChangeStatus", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	if titleChanged {
 | 
			
		||||
		notification.NotifyIssueChangeTitle(ctx.User, issue, oldTitle)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if statusChangeComment != nil {
 | 
			
		||||
		notification.NotifyIssueChangeStatus(ctx.User, issue, statusChangeComment, issue.IsClosed)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Refetch from database
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user