diff options
author | Unknwon <u@gogs.io> | 2015-10-18 19:30:39 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-10-18 19:30:39 -0400 |
commit | fc7959d3bc89b172b3e0f2d0c5fcdcbb09e2408e (patch) | |
tree | 23a861a3bccec2d8311067008ebd0771bee82858 /routers/repo/issue.go | |
parent | 4dc6285715ccd1e90cb4e437a3c2b1d0b13d47cb (diff) |
New/reopen PR checks if there is any unmerged and open PR
Diffstat (limited to 'routers/repo/issue.go')
-rw-r--r-- | routers/repo/issue.go | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 6912a2fa..5bc53b35 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -759,27 +759,56 @@ func NewComment(ctx *middleware.Context, form auth.CreateCommentForm) { return } + var comment *models.Comment defer func() { // Check if issue owner/poster changes the status of issue. if (ctx.Repo.IsOwner() || (ctx.IsSigned && issue.IsPoster(ctx.User.Id))) && (form.Status == "reopen" || form.Status == "close") && !(issue.IsPull && issue.HasMerged) { - issue.Repo = ctx.Repo.Repository - if err = issue.ChangeStatus(ctx.User, form.Status == "close"); err != nil { - log.Error(4, "ChangeStatus: %v", err) + + var pr *models.PullRequest + + if form.Status == "reopen" { + pull := issue.PullRequest + pr, err = models.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch) + if err != nil { + if !models.IsErrPullRequestNotExist(err) { + ctx.Handle(500, "GetUnmergedPullRequest", err) + return + } + } + } + + if pr != nil { + ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index)) } else { - log.Trace("Issue[%d] status changed: %v", issue.ID, !issue.IsClosed) + issue.Repo = ctx.Repo.Repository + if err = issue.ChangeStatus(ctx.User, form.Status == "close"); err != nil { + log.Error(4, "ChangeStatus: %v", err) + } else { + log.Trace("Issue[%d] status changed: %v", issue.ID, !issue.IsClosed) + } } } + + // Redirect to comment hashtag if there is any actual content. + typeName := "issues" + if issue.IsPull { + typeName = "pulls" + } + if comment != nil { + ctx.Redirect(fmt.Sprintf("%s/%s/%d#%s", ctx.Repo.RepoLink, typeName, issue.Index, comment.HashTag())) + } else { + ctx.Redirect(fmt.Sprintf("%s/%s/%d", ctx.Repo.RepoLink, typeName, issue.Index)) + } }() // Fix #321: Allow empty comments, as long as we have attachments. if len(form.Content) == 0 && len(attachments) == 0 { - ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) return } - comment, err := models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments) + comment, err = models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Content, attachments) if err != nil { ctx.Handle(500, "CreateIssueComment", err) return @@ -823,8 +852,6 @@ func NewComment(ctx *middleware.Context, form auth.CreateCommentForm) { } } log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID) - - ctx.Redirect(fmt.Sprintf("%s/issues/%d#%s", ctx.Repo.RepoLink, issue.Index, comment.HashTag())) } func UpdateCommentContent(ctx *middleware.Context) { |