@@ -121,27 +121,28 @@ func IsUserAllowedToUpdate(ctx context.Context, pull *issues_model.PullRequest,
121121 return false , false , err
122122 }
123123
124- // 1. check base repository's AllowRebaseUpdate configuration, this should be
125- // the setting of base repository not head repository
126- prUnit , err := pull .BaseRepo .GetUnit (ctx , unit .TypePullRequests )
127- if err != nil {
128- if repo_model . IsErrUnitTypeNotExist ( err ) {
129- return false , false , nil
130- }
131- log . Error ( "pr.BaseRepo.GetUnit(unit.TypePullRequests): %v" , err )
132- return false , false , err
124+ // 1. check base repository's AllowRebaseUpdate configuration
125+ // it is a config in base repo but controls the head (fork) repo's "Update" behavior
126+ prBaseUnit , err := pull .BaseRepo .GetUnit (ctx , unit .TypePullRequests )
127+ if repo_model . IsErrUnitTypeNotExist ( err ) {
128+ return false , false , nil // the PR unit is disabled in base repo
129+ } else if err != nil {
130+ return false , false , fmt . Errorf ( "get base repo unit: %v" , err )
131+ } else {
132+ rebaseAllowed = prBaseUnit . PullRequestsConfig (). AllowRebaseUpdate
133133 }
134- rebaseAllowed = prUnit .PullRequestsConfig ().AllowRebaseUpdate
135134
136135 // 2. check head branch protection whether rebase is allowed, if pb not found then rebase depends on the above setting
137- pb , err := git_model .GetFirstMatchProtectedBranchRule (ctx , pull .HeadRepoID , pull .HeadBranch )
138- if err != nil {
139- return false , false , err
140- }
141- // If branch protected, disable rebase unless user is whitelisted to force push (which extends regular push)
142- if pb != nil {
143- pb .Repo = pull .HeadRepo
144- rebaseAllowed = rebaseAllowed && pb .CanUserForcePush (ctx , user )
136+ {
137+ pb , err := git_model .GetFirstMatchProtectedBranchRule (ctx , pull .HeadRepoID , pull .HeadBranch )
138+ if err != nil {
139+ return false , false , err
140+ }
141+ // If branch protected, disable rebase unless user is whitelisted to force push (which extends regular push)
142+ if pb != nil {
143+ pb .Repo = pull .HeadRepo
144+ rebaseAllowed = rebaseAllowed && pb .CanUserForcePush (ctx , user )
145+ }
145146 }
146147
147148 // 3. check whether user has write access to head branch
@@ -150,15 +151,15 @@ func IsUserAllowedToUpdate(ctx context.Context, pull *issues_model.PullRequest,
150151 return false , false , err
151152 }
152153
153- mergeAllowed , err = isUserAllowedToMergeRepoBranch (ctx , pull .HeadRepoID , pull .HeadBranch , headRepoPerm , user )
154+ mergeAllowed , err = isUserAllowedToMergeInRepoBranch (ctx , pull .HeadRepoID , pull .HeadBranch , headRepoPerm , user )
154155 if err != nil {
155156 return false , false , err
156157 }
157158
158159 // 4. if the pull creator allows maintainer to edit, it means the write permissions of the head branch has been
159160 // granted to the user with write permission of the base repository
160161 if pull .AllowMaintainerEdit {
161- mergeAllowedMaintainer , err := isUserAllowedToMergeRepoBranch (ctx , pull .BaseRepoID , pull .BaseBranch , baseRepoPerm , user )
162+ mergeAllowedMaintainer , err := isUserAllowedToMergeInRepoBranch (ctx , pull .BaseRepoID , pull .BaseBranch , baseRepoPerm , user )
162163 if err != nil {
163164 return false , false , err
164165 }
0 commit comments