diff options
author | Jonas Franz <info@jonasfranz.software> | 2018-12-11 12:28:37 +0100 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2018-12-11 19:28:37 +0800 |
commit | 9681c8373426e8364760f033b9935b81b9276351 (patch) | |
tree | d9308c33809fdfa7859fd9a1057432a74a28c92f /models/pull.go | |
parent | 64680b72bd1b0a0fc164296ff0cc7319ae7dc4ca (diff) | |
download | gitea-9681c8373426e8364760f033b9935b81b9276351.tar.gz gitea-9681c8373426e8364760f033b9935b81b9276351.zip |
Approvals at Branch Protection (#5350)
* Add branch protection for approvals
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add required approvals
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add missing comments and fmt
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add type = approval and group by reviewer_id to review
* Prevent users from adding negative review limits
* Add migration for approval whitelists
Signed-off-by: Jonas Franz <info@jonasfranz.software>
Diffstat (limited to 'models/pull.go')
-rw-r--r-- | models/pull.go | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/models/pull.go b/models/pull.go index e97faa8f51..0041f83dc8 100644 --- a/models/pull.go +++ b/models/pull.go @@ -60,14 +60,15 @@ type PullRequest struct { Issue *Issue `xorm:"-"` Index int64 - HeadRepoID int64 `xorm:"INDEX"` - HeadRepo *Repository `xorm:"-"` - BaseRepoID int64 `xorm:"INDEX"` - BaseRepo *Repository `xorm:"-"` - HeadUserName string - HeadBranch string - BaseBranch string - MergeBase string `xorm:"VARCHAR(40)"` + HeadRepoID int64 `xorm:"INDEX"` + HeadRepo *Repository `xorm:"-"` + BaseRepoID int64 `xorm:"INDEX"` + BaseRepo *Repository `xorm:"-"` + HeadUserName string + HeadBranch string + BaseBranch string + ProtectedBranch *ProtectedBranch `xorm:"-"` + MergeBase string `xorm:"VARCHAR(40)"` HasMerged bool `xorm:"INDEX"` MergedCommitID string `xorm:"VARCHAR(40)"` @@ -110,6 +111,12 @@ func (pr *PullRequest) loadIssue(e Engine) (err error) { return err } +// LoadProtectedBranch loads the protected branch of the base branch +func (pr *PullRequest) LoadProtectedBranch() (err error) { + pr.ProtectedBranch, err = GetProtectedBranchBy(pr.BaseRepo.ID, pr.BaseBranch) + return +} + // GetDefaultMergeMessage returns default message used when merging pull request func (pr *PullRequest) GetDefaultMergeMessage() string { if pr.HeadRepo == nil { @@ -288,7 +295,7 @@ func (pr *PullRequest) CheckUserAllowedToMerge(doer *User) (err error) { } } - if protected, err := pr.BaseRepo.IsProtectedBranchForMerging(pr.BaseBranch, doer); err != nil { + if protected, err := pr.BaseRepo.IsProtectedBranchForMerging(pr, pr.BaseBranch, doer); err != nil { return fmt.Errorf("IsProtectedBranch: %v", err) } else if protected { return ErrNotAllowedToMerge{ |