-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Move some code into models/git #19879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ede97f9
Move access and repo permission to models/perm/access
lunny b99ae45
fix test
lunny af9025b
Move some git related files into sub package models/git
lunny 9fc0658
Fix build
lunny 7f9c37f
fix git test
lunny 64c409c
move lfs to sub package
lunny d58b2dd
move more git related functions to models/git
lunny c8cc3d1
Move functions sequence
lunny f6e9228
Some improvements per @KN4CK3R and @delvh
lunny e323b84
Merge branch 'main' into lunny/model_git
lunny 2297a30
Merge branch 'main' into lunny/model_git
lunny 7abf31c
Merge branch 'main' into lunny/model_git
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package models | ||
|
||
import ( | ||
"context" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
git_model "code.gitea.io/gitea/models/git" | ||
"code.gitea.io/gitea/modules/log" | ||
) | ||
|
||
// HasEnoughApprovals returns true if pr has enough granted approvals. | ||
func HasEnoughApprovals(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool { | ||
if protectBranch.RequiredApprovals == 0 { | ||
return true | ||
} | ||
return GetGrantedApprovalsCount(ctx, protectBranch, pr) >= protectBranch.RequiredApprovals | ||
} | ||
|
||
// GetGrantedApprovalsCount returns the number of granted approvals for pr. A granted approval must be authored by a user in an approval whitelist. | ||
func GetGrantedApprovalsCount(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) int64 { | ||
sess := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID). | ||
And("type = ?", ReviewTypeApprove). | ||
And("official = ?", true). | ||
And("dismissed = ?", false) | ||
if protectBranch.DismissStaleApprovals { | ||
sess = sess.And("stale = ?", false) | ||
} | ||
approvals, err := sess.Count(new(Review)) | ||
if err != nil { | ||
log.Error("GetGrantedApprovalsCount: %v", err) | ||
return 0 | ||
} | ||
|
||
return approvals | ||
} | ||
|
||
// MergeBlockedByRejectedReview returns true if merge is blocked by rejected reviews | ||
func MergeBlockedByRejectedReview(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool { | ||
if !protectBranch.BlockOnRejectedReviews { | ||
return false | ||
} | ||
rejectExist, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID). | ||
And("type = ?", ReviewTypeReject). | ||
And("official = ?", true). | ||
And("dismissed = ?", false). | ||
Exist(new(Review)) | ||
if err != nil { | ||
log.Error("MergeBlockedByRejectedReview: %v", err) | ||
return true | ||
} | ||
|
||
return rejectExist | ||
} | ||
|
||
// MergeBlockedByOfficialReviewRequests block merge because of some review request to official reviewer | ||
// of from official review | ||
func MergeBlockedByOfficialReviewRequests(ctx context.Context, protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool { | ||
if !protectBranch.BlockOnOfficialReviewRequests { | ||
return false | ||
} | ||
has, err := db.GetEngine(ctx).Where("issue_id = ?", pr.IssueID). | ||
And("type = ?", ReviewTypeRequest). | ||
And("official = ?", true). | ||
Exist(new(Review)) | ||
if err != nil { | ||
log.Error("MergeBlockedByOfficialReviewRequests: %v", err) | ||
return true | ||
} | ||
|
||
return has | ||
} | ||
|
||
// MergeBlockedByOutdatedBranch returns true if merge is blocked by an outdated head branch | ||
func MergeBlockedByOutdatedBranch(protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool { | ||
return protectBranch.BlockOnOutdatedBranch && pr.CommitsBehind > 0 | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.