Skip to content
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

Error 500 attempting to merge PR as admin #9739

Closed
guillep2k opened this issue Jan 12, 2020 · 4 comments · Fixed by #9749
Closed

Error 500 attempting to merge PR as admin #9739

guillep2k opened this issue Jan 12, 2020 · 4 comments · Fixed by #9749
Labels
skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/bug

Comments

@guillep2k
Copy link
Member

  • Gitea version (or commit ref): 2ecf98e

Description

When I attempt to merge a PR that doesn't have enough approvals, the [Merge] button shows up in red and the message "As an administrator, you may still merge this pull request" is displayed. However, when I push the [Merge] button, a 500 Server Error page shows up with the following error:

git push: remote: Gitea: Not allowed to push to protected branch master and pr #68 is not ready to be merged: not allowed to merge [reason: Does not have enough approvals]        
To /home/giteatest/gitea-repositories/user2/miomiomio.git
 ! [remote rejected] base -> master (pre-receive hook declined)
error: failed to push some refs to '/home/giteatest/gitea-repositories/user2/miomiomio.git'

Stack trace:

2020/01/12 20:36:05 ...ters/private/hook.go:145:HookPreReceive() [W] Forbidden: User 39 is not allowed push to protected branch master in 82473
8599184:user2/miomiomio and pr #1 is not ready to be merged: not allowed to merge [reason: Does not have enough approvals]
2020/01/12 20:36:05 routers/repo/pull.go:712:MergePullRequest() [E] Merge: git push: remote: Gitea: Not allowed to push to protected branch mas
ter and pr #68 is not ready to be merged: not allowed to merge [reason: Does not have enough approvals]
    To /home/giteatest/gitea-repositories/user2/miomiomio.git
     ! [remote rejected] base -> master (pre-receive hook declined)
    error: failed to push some refs to '/home/giteatest/gitea-repositories/user2/miomiomio.git'

    /home/guillep2k/src/code.gitea.io/gitea/routers/repo/pull.go:712 (0x1471838)
        MergePullRequest: ctx.ServerError("Merge", err)
    /home/guillep2k/go/src/reflect/value.go:460 (0x49e935)
        Value.call: call(frametype, fn, args, uint32(frametype.size), uint32(retOffset))
    /home/guillep2k/go/src/reflect/value.go:321 (0x49e0f3)
        Value.Call: return v.call("Call", in)
    /home/v/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:177 (0x9bc749)
        (*injector).callInvoke: return reflect.ValueOf(f).Call(in), nil
    (etc)

User 39 is the owner of the repository and the user I'm logged in for the merge operation.

@lunny lunny added type/bug skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. labels Jan 13, 2020
@zeripath
Copy link
Contributor

zeripath commented Jan 13, 2020

if err := pull_service.CheckPRReadyToMerge(pr); err != nil {
if models.IsErrNotAllowedToMerge(err) {

The specific override would have to go here or the line below.

@zeripath
Copy link
Contributor

zeripath commented Jan 13, 2020

@davidsvantesson you did not understand that the hook always runs.

if !canPush && opts.ProtectedBranchID > 0 {
// Manual merge

This is not true. In fact if you have the protectedbranchid set it's not a manual merge!!

@davidsvantesson
Copy link
Contributor

Ohh. Is there any way to know if it was done from the UI?

@davidsvantesson
Copy link
Contributor

davidsvantesson commented Jan 13, 2020

The previous code didn't even check if status checks was ok, so it didn't prevent admins (or anyone) to merge.

@zeripath So we never allow manual merges, unless user has push rights to branch? (I.e. a user with merge rights has to use the UI or API, not trying to manual merge and push). It is a bit hard to follow the code when it makes internal requests 😕 😊

In that case this code might even be a bit double as the check is done before merge is done. Anyhow it should be an easy fix to just check if user is admin.

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants