func CompareAndPullRequestPost(ctx *middleware.Context, form auth.CreateIssueForm) { ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes") ctx.Data["PageIsComparePull"] = true ctx.Data["IsDiffCompare"] = true renderAttachmentSettings(ctx) var ( repo = ctx.Repo.Repository attachments []string ) headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx) if ctx.Written() { return } patch, err := headGitRepo.GetPatch(prInfo.MergeBase, headBranch) if err != nil { ctx.Handle(500, "GetPatch", err) return } labelIDs, milestoneID, assigneeID := ValidateRepoMetas(ctx, form) if ctx.Written() { return } if setting.AttachmentEnabled { attachments = form.Attachments } if ctx.HasError() { ctx.HTML(200, COMPARE_PULL) return } pull := &models.Issue{ RepoID: repo.ID, Index: repo.NextIssueIndex(), Name: form.Title, PosterID: ctx.User.Id, Poster: ctx.User, MilestoneID: milestoneID, AssigneeID: assigneeID, IsPull: true, Content: form.Content, } if err := models.NewPullRequest(repo, pull, labelIDs, attachments, &models.PullRequest{ HeadRepoID: headRepo.ID, BaseRepoID: repo.ID, HeadUserName: headUser.Name, HeadBranch: headBranch, BaseBranch: baseBranch, MergeBase: prInfo.MergeBase, Type: models.PULL_REQUEST_GOGS, }, patch); err != nil { ctx.Handle(500, "NewPullRequest", err) return } log.Trace("Pull request created: %d/%d", repo.ID, pull.ID) ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pull.Index)) }
func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm) { ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes") ctx.Data["PageIsComparePull"] = true ctx.Data["IsDiffCompare"] = true ctx.Data["RequireHighlightJS"] = true renderAttachmentSettings(ctx) var ( repo = ctx.Repo.Repository attachments []string ) headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch := ParseCompareInfo(ctx) if ctx.Written() { return } labelIDs, milestoneID, assigneeID := ValidateRepoMetas(ctx, form) if ctx.Written() { return } if setting.AttachmentEnabled { attachments = form.Files } if ctx.HasError() { auth.AssignForm(form, ctx.Data) // This stage is already stop creating new pull request, so it does not matter if it has // something to compare or not. PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, prInfo, baseBranch, headBranch) if ctx.Written() { return } ctx.HTML(200, COMPARE_PULL) return } patch, err := headGitRepo.GetPatch(prInfo.MergeBase, headBranch) if err != nil { ctx.Handle(500, "GetPatch", err) return } pullIssue := &models.Issue{ RepoID: repo.ID, Index: repo.NextIssueIndex(), Title: form.Title, PosterID: ctx.User.ID, Poster: ctx.User, MilestoneID: milestoneID, AssigneeID: assigneeID, IsPull: true, Content: form.Content, } pullRequest := &models.PullRequest{ HeadRepoID: headRepo.ID, BaseRepoID: repo.ID, HeadUserName: headUser.Name, HeadBranch: headBranch, BaseBranch: baseBranch, HeadRepo: headRepo, BaseRepo: repo, MergeBase: prInfo.MergeBase, Type: models.PULL_REQUEST_GOGS, } // FIXME: check error in the case two people send pull request at almost same time, give nice error prompt // instead of 500. if err := models.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, patch); err != nil { ctx.Handle(500, "NewPullRequest", err) return } else if err := pullRequest.PushToBaseRepo(); err != nil { ctx.Handle(500, "PushToBaseRepo", err) return } log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID) ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index)) }