1
0
Fork 0
forked from forgejo/forgejo

Add notification interface and refactor UI notifications (#5085)

* add notification interface and refactor UI notifications

* add missing methods on notification interface and notifiy only issue status really changed

* implement NotifyPullRequestReview for ui notification
This commit is contained in:
Lunny Xiao 2018-10-18 19:23:05 +08:00 committed by GitHub
parent dd62ca7ba9
commit ea619b39b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 378 additions and 44 deletions

View file

@ -490,7 +490,7 @@ func NewIssuePost(ctx *context.Context, form auth.CreateIssueForm) {
return
}
notification.Service.NotifyIssue(issue, ctx.User.ID)
notification.NotifyNewIssue(issue)
log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + com.ToStr(issue.Index))
@ -1004,15 +1004,19 @@ func UpdateIssueStatus(ctx *context.Context) {
return
}
for _, issue := range issues {
if err := issue.ChangeStatus(ctx.User, issue.Repo, isClosed); err != nil {
if models.IsErrDependenciesLeft(err) {
ctx.JSON(http.StatusPreconditionFailed, map[string]interface{}{
"error": "cannot close this issue because it still has open dependencies",
})
if issue.IsClosed != isClosed {
if err := issue.ChangeStatus(ctx.User, issue.Repo, isClosed); err != nil {
if models.IsErrDependenciesLeft(err) {
ctx.JSON(http.StatusPreconditionFailed, map[string]interface{}{
"error": "cannot close this issue because it still has open dependencies",
})
return
}
ctx.ServerError("ChangeStatus", err)
return
}
ctx.ServerError("ChangeStatus", err)
return
notification.NotifyIssueChangeStatus(ctx.User, issue, isClosed)
}
}
ctx.JSON(200, map[string]interface{}{
@ -1072,7 +1076,8 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
if pr != nil {
ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index))
} else {
if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, form.Status == "close"); err != nil {
isClosed := form.Status == "close"
if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, isClosed); err != nil {
log.Error(4, "ChangeStatus: %v", err)
if models.IsErrDependenciesLeft(err) {
@ -1088,7 +1093,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
} else {
log.Trace("Issue [%d] status changed to closed: %v", issue.ID, issue.IsClosed)
notification.Service.NotifyIssue(issue, ctx.User.ID)
notification.NotifyIssueChangeStatus(ctx.User, issue, isClosed)
}
}
}
@ -1116,7 +1121,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
return
}
notification.Service.NotifyIssue(issue, ctx.User.ID)
notification.NotifyCreateIssueComment(ctx.User, ctx.Repo.Repository, issue, comment)
log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
}