Browse Source

fix#5252, double click to submit pull request will make 2 same pr.

pull/5254/head^2
张梦金 7 years ago
parent
commit
47aa553279
  1. 14
      models/error.go
  2. 14
      models/pull.go
  3. 8
      routes/repo/pull.go

14
models/error.go

@ -414,6 +414,20 @@ func (err ErrPullRequestNotExist) Error() string {
err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBarcnh, err.BaseBranch) err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBarcnh, err.BaseBranch)
} }
type ErrPullRequestExist struct {
ID int64
IssueID int64
HeadRepoID int64
BaseRepoID int64
HeadBarcnh string
BaseBranch string
}
func (err ErrPullRequestExist) Error() string {
return fmt.Sprintf("pull request already exist [id: %d, issue_id: %d, head_repo_id: %d, base_repo_id: %d, head_branch: %s, base_branch: %s]",
err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBarcnh, err.BaseBranch)
}
// _________ __ // _________ __
// \_ ___ \ ____ _____ _____ ____ _____/ |_ // \_ ___ \ ____ _____ _____ ____ _____/ |_
// / \ \/ / _ \ / \ / \_/ __ \ / \ __\ // / \ \/ / _ \ / \ / \_/ __ \ / \ __\

14
models/pull.go

@ -525,6 +525,20 @@ func GetUnmergedPullRequest(headRepoID, baseRepoID int64, headBranch, baseBranch
return pr, nil return pr, nil
} }
// CheckPullRequestExist returns if the pull request has been create before create a new pull request
func CheckPullRequestExist(headRepoID, baseRepoID int64, headBranch, baseBranch string) (bool, error) {
pr := new(PullRequest)
has, err := x.Where("head_repo_id=? AND head_branch=? AND base_repo_id=? AND base_branch=? AND has_merged=? AND issue.is_closed=?",
headRepoID, headBranch, baseRepoID, baseBranch, false, false).
Join("INNER", "issue", "issue.id=pull_request.issue_id").Get(pr)
if err != nil {
return false, err
} else if has {
return true, ErrPullRequestExist{pr.ID, pr.IssueID, headRepoID, baseRepoID, headBranch, baseBranch}
}
return false, nil
}
// GetUnmergedPullRequestsByHeadInfo returnss all pull requests that are open and has not been merged // GetUnmergedPullRequestsByHeadInfo returnss all pull requests that are open and has not been merged
// by given head information (repo and branch). // by given head information (repo and branch).
func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string) ([]*PullRequest, error) { func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string) ([]*PullRequest, error) {

8
routes/repo/pull.go

@ -655,6 +655,14 @@ func CompareAndPullRequestPost(c *context.Context, f form.NewIssue) {
return return
} }
// check one people send the pr at the same time
has , err := models.CheckPullRequestExist(headRepo.ID, c.Repo.Repository.ID, headBranch, baseBranch)
if has || err != nil {
c.ServerError("CheckPullRequestExist",err)
return
}
labelIDs, milestoneID, assigneeID := ValidateRepoMetas(c, f) labelIDs, milestoneID, assigneeID := ValidateRepoMetas(c, f)
if c.Written() { if c.Written() {
return return

Loading…
Cancel
Save