diff options
author | zeripath <art27@cantab.net> | 2020-05-16 22:05:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-17 00:05:19 +0300 |
commit | 414c9ee76a52a5c0152c87eec096c4e5a86457b8 (patch) | |
tree | 226a91446ce59e7916814da25a64542eae7ee1cd /routers | |
parent | c86bc8e061b91d3d3778d9b97ba16e373250d8f6 (diff) | |
download | gitea-414c9ee76a52a5c0152c87eec096c4e5a86457b8.tar.gz gitea-414c9ee76a52a5c0152c87eec096c4e5a86457b8.zip |
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>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/issue.go | 29 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 28 |
2 files changed, 36 insertions, 21 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 3497fe08fe..d51e80e18c 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -17,6 +17,7 @@ import ( "code.gitea.io/gitea/modules/convert" issue_indexer "code.gitea.io/gitea/modules/indexer/issues" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" @@ -544,6 +545,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { return } + oldTitle := issue.Title if len(form.Title) > 0 { issue.Title = form.Title } @@ -598,20 +600,25 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { return } } - - if err = models.UpdateIssueByAPI(issue); err != nil { - 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 issue because it still has open dependencies") - return - } - ctx.Error(http.StatusInternalServerError, "ChangeStatus", err) + 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 issue because it still has open dependencies") return } + ctx.Error(http.StatusInternalServerError, "UpdateIssueByAPI", err) + return + } + + if titleChanged { + notification.NotifyIssueChangeTitle(ctx.User, issue, oldTitle) + } + + if statusChangeComment != nil { + notification.NotifyIssueChangeStatus(ctx.User, issue, statusChangeComment, issue.IsClosed) } // Refetch from database to assign some automatic values diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index db0b14bd70..bddf4e48f7 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -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 { - 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) + 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 titleChanged { + notification.NotifyIssueChangeTitle(ctx.User, issue, oldTitle) + } + + if statusChangeComment != nil { + notification.NotifyIssueChangeStatus(ctx.User, issue, statusChangeComment, issue.IsClosed) } // Refetch from database |