Automerge does not work #10755

Closed
opened 2025-11-02 09:17:22 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @EndrII on GitHub (Apr 30, 2023).

Description

I added next rules for merging PR

  • All statuses of commit must be successful before merge
  • PR must have one approve review

Gitea Version

1.19.2

Can you reproduce the bug on the Gitea demo site?

I don't know (I can't check it)

Log Gist

No response

Screenshots

image
image

Git Version

git version 2.25.1

Operating System

ubuntu 20.04 (Linux beloved-pipefish 5.4.0-125-generic #141-Ubuntu SMP Wed Aug 10 13:42:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux)

How are you running Gitea?

I run Gitea from prepared binary files

Database

SQLite

Originally created by @EndrII on GitHub (Apr 30, 2023). ### Description I added next rules for merging PR * All statuses of commit must be successful before merge * PR must have one approve review ### Gitea Version 1.19.2 ### Can you reproduce the bug on the Gitea demo site? I don't know (I can't check it) ### Log Gist _No response_ ### Screenshots ![image](https://user-images.githubusercontent.com/12465465/235366919-4530467b-7ae6-4caa-a417-8b99d495473b.png) ![image](https://user-images.githubusercontent.com/12465465/235366979-a87fe3ec-71e2-447c-b190-3b0b878f2971.png) ### Git Version git version 2.25.1 ### Operating System ubuntu 20.04 (Linux beloved-pipefish 5.4.0-125-generic #141-Ubuntu SMP Wed Aug 10 13:42:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux) ### How are you running Gitea? I run Gitea from prepared binary files ### Database SQLite
GiteaMirror added the issue/criticaltype/bug labels 2025-11-02 09:17:22 -06:00
Author
Owner

@nekrondev commented on GitHub (Jul 26, 2023):

The auto-merge isn't even working on a much simpler workflow by only requesting approval.
I created a demo here https://try.gitea.io/merge_user1/automerge_problem/pulls/1.

merge_user1's repository got branched by merge_user2 (both are repository admins, merge_user2 is a collaborator). Now merge_user2 wants to PR his bugfix. The main branch is protected and needs one approval. merge_user2 submitted his PR with auto merge enabled, i.e. after approval of merge_user1 his change should be auto-merged into main.

Now merge_user1 approved his PR but the commit is not auto-merged into main branch like requested by PR owner.

image

image

image

@nekrondev commented on GitHub (Jul 26, 2023): The auto-merge isn't even working on a much simpler workflow by only requesting approval. I created a demo here https://try.gitea.io/merge_user1/automerge_problem/pulls/1. `merge_user1`'s repository got branched by `merge_user2` (both are repository admins, `merge_user2` is a collaborator). Now `merge_user2` wants to PR his bugfix. The `main` branch is protected and needs one approval. `merge_user2` submitted his PR with `auto merge` enabled, i.e. after approval of `merge_user1` his change should be auto-merged into main. Now `merge_user1` approved his PR but the commit is not auto-merged into `main` branch like requested by PR owner. ![image](https://github.com/go-gitea/gitea/assets/13854802/3ce6af1d-0ca5-4a83-9758-f7a0e99de2f2) ![image](https://github.com/go-gitea/gitea/assets/13854802/5a16e231-32c7-480d-8f4c-e1482923948e) ![image](https://github.com/go-gitea/gitea/assets/13854802/5daf9348-585d-4eb1-8cc5-25100ea24e7b)
Author
Owner

@nekrondev commented on GitHub (Jul 26, 2023):

I did some research and it looks like currently automatic merging can only be triggered via API call (GT Actions state when executed successfully aren't counting here either; approval will not trigger this, too).

0533187f28/routers/api/v1/repo/status.go (L20)

That API function will call the CreateCommitStatus() function that will trigger the automerge checks ...

79995a8194/services/repository/files/commit.go (L22)

... that will eventually end in adding a new merge message into the pr_automerge_queue.

79995a8194/services/automerge/automerge.go (L98)

In the end there are a few missing bits and pieces for actions and approvals that needs to be added.
In your case it's unclear to me why buildbot commit states didn't trigger the automerge (buildbot should use the commit state API which triggers auto merging).

@nekrondev commented on GitHub (Jul 26, 2023): I did some research and it looks like currently automatic merging can only be triggered via API call (GT Actions state when executed successfully aren't counting here either; approval will not trigger this, too). https://github.com/go-gitea/gitea/blob/0533187f28f293adaf34f58d4a285ae2b0b267ad/routers/api/v1/repo/status.go#L20 That API function will call the `CreateCommitStatus()` function that will trigger the automerge checks ... https://github.com/go-gitea/gitea/blob/79995a8194235ee994a1ce3cbe5eaa11358db885/services/repository/files/commit.go#L22 ... that will eventually end in adding a new merge message into the `pr_automerge_queue`. https://github.com/go-gitea/gitea/blob/79995a8194235ee994a1ce3cbe5eaa11358db885/services/automerge/automerge.go#L98 In the end there are a few missing bits and pieces for actions and approvals that needs to be added. In your case it's unclear to me why buildbot commit states didn't trigger the automerge (buildbot should use the commit state API which triggers auto merging).
Author
Owner

@EndrII commented on GitHub (Jul 26, 2023):

@nekrondev this is looks as a bug, because you can enable branch protection and block merge without any review. But any users can enable automerge and merge it after successful tests ...
So anyway, the automerge must work as in GitHub. But not like now

@EndrII commented on GitHub (Jul 26, 2023): @nekrondev this is looks as a bug, because you can enable branch protection and block merge without any review. But any users can enable automerge and merge it after successful tests ... So anyway, the automerge must work as in GitHub. But not like now
Author
Owner

@nekrondev commented on GitHub (Jul 27, 2023):

I did a quick test with

  • auto-merge enabled and
  • one approval missing

If I send the API request to commit a successful check the auto-merge is not executed which is fine (the PR still needs to be reviewed).

However if I submit my PR review approval then without any additional calls to the API endpoint the change wouldn't be merged automatically. I think this is the same behavior for Gitea Actions that needs to call the proper automerge function internally after a successful check had been returned from the runner.

@lunny I guess that

221b90d289/services/pull/review.go (L267)

is missing a call to MergeScheduledPullRequest() function at module automerge when an approval had been granted and origin PR owner requested an automerge.

@nekrondev commented on GitHub (Jul 27, 2023): I did a quick test with - auto-merge enabled and - one approval missing If I send the API request to commit a successful check the auto-merge is not executed which is fine (the PR still needs to be reviewed). However if I submit my PR review approval then without any additional calls to the API endpoint the change wouldn't be merged automatically. I think this is the same behavior for Gitea Actions that needs to call the proper automerge function internally after a successful check had been returned from the runner. @lunny I guess that https://github.com/go-gitea/gitea/blob/221b90d2891025b08cd083bb821d91a7f5722341/services/pull/review.go#L267 is missing a call to `MergeScheduledPullRequest()` function at module `automerge` when an approval had been granted and origin PR owner requested an automerge.
Author
Owner

@lunny commented on GitHub (Jul 27, 2023):

I think the automerge logic should have some refactor. Maybe Gitea could learn some from GH.

@lunny commented on GitHub (Jul 27, 2023): I think the automerge logic should have some refactor. Maybe Gitea could learn some from GH.
Author
Owner

@JoaoVictorLouro commented on GitHub (Nov 16, 2023):

Same issue on GitTea 1.21

Running on:
Gitea Version
1.21.0 built with GNU Make 4.4.1, go1.21.4 : bindata, timetzdata, sqlite, sqlite_unlock_notify
Database:
mysql (mariadb) 10.6.9
Act Runner:
0.2.6

All through docker (via docker-compose)

image

Any chance we can fix this? Any ideas of where to start looking?

@JoaoVictorLouro commented on GitHub (Nov 16, 2023): Same issue on GitTea 1.21 Running on: Gitea Version 1.21.0 built with GNU Make 4.4.1, go1.21.4 : bindata, timetzdata, sqlite, sqlite_unlock_notify Database: mysql (mariadb) 10.6.9 Act Runner: 0.2.6 All through docker (via docker-compose) ![image](https://github.com/go-gitea/gitea/assets/34715931/fe545aae-452e-44c5-bdc8-185e3aeef5b2) Any chance we can fix this? Any ideas of where to start looking?
Author
Owner

@henrygoodman commented on GitHub (Nov 28, 2023):

I really hope re-invigorating the auto-merge will also allow us to expose some endpoint to check PR mergeability (from more than just a git perspective, considering reviews/checks/correct merge base etc).

@henrygoodman commented on GitHub (Nov 28, 2023): I really hope re-invigorating the auto-merge will also allow us to expose some endpoint to check PR mergeability (from more than just a git perspective, considering reviews/checks/correct merge base etc).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#10755