Skip to content

Commit f6e9228

Browse files
committed
Some improvements per @KN4CK3R and @delvh
1 parent c8cc3d1 commit f6e9228

File tree

6 files changed

+9
-23
lines changed

6 files changed

+9
-23
lines changed

models/branch.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ func MergeBlockedByOfficialReviewRequests(ctx context.Context, protectBranch *gi
7373

7474
return has
7575
}
76+
77+
// MergeBlockedByOutdatedBranch returns true if merge is blocked by an outdated head branch
78+
func MergeBlockedByOutdatedBranch(protectBranch *git_model.ProtectedBranch, pr *PullRequest) bool {
79+
return protectBranch.BlockOnOutdatedBranch && pr.CommitsBehind > 0
80+
}

models/git/branches.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ func IsUserOfficialReviewerCtx(ctx context.Context, protectBranch *ProtectedBran
160160
return inTeam, nil
161161
}
162162

163-
// MergeBlockedByOutdatedBranch returns true if merge is blocked by an outdated head branch
164-
func (protectBranch *ProtectedBranch) MergeBlockedByOutdatedBranch(commitsBehind int) bool {
165-
return protectBranch.BlockOnOutdatedBranch && commitsBehind > 0
166-
}
167-
168163
// GetProtectedFilePatterns parses a semicolon separated list of protected file patterns and returns a glob.Glob slice
169164
func (protectBranch *ProtectedBranch) GetProtectedFilePatterns() []glob.Glob {
170165
return getFilePatterns(protectBranch.ProtectedFilePatterns)
@@ -191,13 +186,13 @@ func getFilePatterns(filePatterns string) []glob.Glob {
191186
}
192187

193188
// MergeBlockedByProtectedFiles returns true if merge is blocked by protected files change
194-
func (protectBranch *ProtectedBranch) MergeBlockedByProtectedFiles(changedProtecedFiles []string) bool {
189+
func (protectBranch *ProtectedBranch) MergeBlockedByProtectedFiles(changedProtectedFiles []string) bool {
195190
glob := protectBranch.GetProtectedFilePatterns()
196191
if len(glob) == 0 {
197192
return false
198193
}
199194

200-
return len(changedProtecedFiles) > 0
195+
return len(changedProtectedFiles) > 0
201196
}
202197

203198
// IsProtectedFile return if path is protected

models/git/lfs.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ import (
2020
"xorm.io/builder"
2121
)
2222

23-
//.____ ____________________
24-
//| | \_ _____/ _____/
25-
//| | | __) \_____ \
26-
//| |___| \ / \
27-
//|_______ \___ / /_______ /
28-
// \/ \/ \/
29-
3023
// ErrLFSLockNotExist represents a "LFSLockNotExist" kind of error.
3124
type ErrLFSLockNotExist struct {
3225
ID int64

routers/web/repo/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ func ViewIssue(ctx *context.Context) {
16241624
ctx.Data["IsBlockedByApprovals"] = !models.HasEnoughApprovals(ctx, pull.ProtectedBranch, pull)
16251625
ctx.Data["IsBlockedByRejection"] = models.MergeBlockedByRejectedReview(ctx, pull.ProtectedBranch, pull)
16261626
ctx.Data["IsBlockedByOfficialReviewRequests"] = models.MergeBlockedByOfficialReviewRequests(ctx, pull.ProtectedBranch, pull)
1627-
ctx.Data["IsBlockedByOutdatedBranch"] = pull.ProtectedBranch.MergeBlockedByOutdatedBranch(pull.CommitsBehind)
1627+
ctx.Data["IsBlockedByOutdatedBranch"] = models.MergeBlockedByOutdatedBranch(pull.ProtectedBranch, pull)
16281628
ctx.Data["GrantedApprovals"] = models.GetGrantedApprovalsCount(ctx, pull.ProtectedBranch, pull)
16291629
ctx.Data["RequireSigned"] = pull.ProtectedBranch.RequireSignedCommits
16301630
ctx.Data["ChangedProtectedFiles"] = pull.ChangedProtectedFiles

routers/web/repo/repo.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,6 @@ func SearchRepo(ctx *context.Context) {
599599

600600
results := make([]*api.Repository, len(repos))
601601
for i, repo := range repos {
602-
if err = repo.GetOwner(ctx); err != nil {
603-
ctx.JSON(http.StatusInternalServerError, api.SearchError{
604-
OK: false,
605-
Error: err.Error(),
606-
})
607-
return
608-
}
609602
results[i] = &api.Repository{
610603
ID: repo.ID,
611604
FullName: repo.FullName(),

services/pull/merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ func CheckPullBranchProtections(ctx context.Context, pr *models.PullRequest, ski
803803
}
804804
}
805805

806-
if pr.ProtectedBranch.MergeBlockedByOutdatedBranch(pr.CommitsBehind) {
806+
if models.MergeBlockedByOutdatedBranch(pr.ProtectedBranch, pr) {
807807
return models.ErrDisallowedToMerge{
808808
Reason: "The head branch is behind the base branch",
809809
}

0 commit comments

Comments
 (0)