smarkets / marge-bot

A merge-bot for GitLab
BSD 3-Clause "New" or "Revised" License
700 stars 136 forks source link

marge-bot does not wait for CI to pass #281

Closed Hi-Angel closed 3 years ago

Hi-Angel commented 3 years ago

As far as I read README and the linked blog-post, no additional configuration is required for the bot to only merge an MR after pipeline passes. However, for us the bot always merges an MR immediately

Here's a screenshot:

Screenshot_20201215_175205

You can see the pipeline haven't even been started, but the bot already merged MR. The .gitlab-ci.yml I have used for this test is:

build_merge_request:
  only: [merge_requests]
  script:
    - sleep 5m

Bot configuration file:

gitlab-url: "http://gitlab.domainname.ru"
auth-token: "xxxxxxxxxxxxxxxxxxxx"
ci-timeout: 1h

# ideally the variable below should be "updated_at". However it's possible that
# bot will consider as last update time the time MR was updated by the bot
# rather than by actual devs. So use created_at for now.
merge-order: "created_at"
ssh-key: |
    -----BEGIN RSA PRIVATE KEY-----
    […]
    -----END RSA PRIVATE KEY-----

Relevant logs by the bot (I have changed project and domain names):

Dec 15 17:50:59 localhost podman[22814]: 2020-12-15 14:50:59,424 INFO Running git clone --origin=origin git@gitlab.domainname.ru:K.Kharlamov/projectname.git /tmp44x3jvf_/tmp3lex52wo
Dec 15 17:51:47 localhost podman[22814]: 2020-12-15 14:51:47,668 INFO Running git -C /tmp44x3jvf_/tmp3lex52wo config user.email bot-username@domain.ru
Dec 15 17:51:47 localhost podman[22814]: 2020-12-15 14:51:47,674 INFO Running git -C /tmp44x3jvf_/tmp3lex52wo config user.name Putin
Dec 15 17:51:47 localhost podman[22814]: 2020-12-15 14:51:47,679 INFO Got 1 requests to merge;
Dec 15 17:51:47 localhost podman[22814]: 2020-12-15 14:51:47,679 INFO Attempting to merge the oldest MR...
Dec 15 17:51:47 localhost podman[22814]: 2020-12-15 14:51:47,679 INFO Processing !19 - '.gitlab-ci.yml:  #9892'
Dec 15 17:51:47 localhost podman[22814]: 2020-12-15 14:51:47,910 INFO Ensuring MR !19 is mergeable
Dec 15 17:51:48 localhost podman[22814]: 2020-12-15 14:51:48,121 INFO Running git -C /tmp44x3jvf_/tmp3lex52wo fetch --prune origin
Dec 15 17:51:49 localhost podman[22814]: 2020-12-15 14:51:49,593 INFO Running git -C /tmp44x3jvf_/tmp3lex52wo checkout -B test-marge-bot origin/test-marge-bot --
Dec 15 17:51:50 localhost podman[22814]: 2020-12-15 14:51:50,619 INFO Running git -C /tmp44x3jvf_/tmp3lex52wo rebase origin/test
Dec 15 17:51:50 localhost podman[22814]: 2020-12-15 14:51:50,731 INFO Running git -C /tmp44x3jvf_/tmp3lex52wo rev-parse HEAD
Dec 15 17:51:50 localhost podman[22814]: 2020-12-15 14:51:50,737 INFO Running git -C /tmp44x3jvf_/tmp3lex52wo rev-parse origin/test
Dec 15 17:51:50 localhost podman[22814]: 2020-12-15 14:51:50,742 INFO Adding trailers for MR !19
Dec 15 17:51:50 localhost podman[22814]: 2020-12-15 14:51:50,742 INFO Running git -C /tmp44x3jvf_/tmp3lex52wo checkout test-marge-bot --
Dec 15 17:51:50 localhost podman[22814]: 2020-12-15 14:51:50,790 INFO Running git -C /tmp44x3jvf_/tmp3lex52wo diff-index --quiet HEAD
Dec 15 17:51:50 localhost podman[22814]: 2020-12-15 14:51:50,806 INFO Running git -C /tmp44x3jvf_/tmp3lex52wo ls-files --others
Dec 15 17:51:50 localhost podman[22814]: 2020-12-15 14:51:50,826 INFO Running git -C /tmp44x3jvf_/tmp3lex52wo push --force origin test-marge-bot:test-marge-bot
Dec 15 17:51:51 localhost podman[22814]: 2020-12-15 14:51:51,513 INFO Commit id to merge '17e717b610499c4e9460215e80dfb48d34ad9a87' (into: 'fe90a18cad6221ebb0fcc537bc5e92bed93a6fde')
Dec 15 17:51:56 localhost podman[22814]: 2020-12-15 14:51:56,895 INFO Ensuring MR !19 is mergeable
Dec 15 17:51:58 localhost podman[22814]: 2020-12-15 14:51:58,378 INFO merge_request.accept result: {'id': 471, 'iid': 19, 'project_id': 14, 'title': '.gitlab-ci.yml:  #9892', 'description': '', 'state': 'merged', 'created_at': '2020-12-15T14:48:57.445Z', 'updated_at': '2020-12-15T14:50:24.015Z', 'merged_by': {'id': 20, 'name': 'Putin', 'username': 'marge-bot', 'state': 'active', 'avatar_url': 'https://www.gravatar.com/avatar/e20a65b7c095f620e8a714e7fb492e86?s=80&d=identicon', 'web_url': 'http://gitlab.domainname.ru/marge-bot'}, 'merged_at': '2020-12-15T14:50:24.070Z', 'closed_by': None, 'closed_at': None, 'target_branch': 'test', 'source_branch': 'test-marge-bot', 'user_notes_count': 0, 'upvotes': 0, 'downvotes': 0, 'author': {'id': 3, 'name': 'K.Kharlamov', 'username': 'K.Kharlamov', 'state': 'active', 'avatar_url': 'https://www.gravatar.com/avatar/b439ce4e5ef2cd0930ce216fdb843ed8?s=80&d=identicon', 'web_url': 'http://gitlab.domainname.ru/K.Kharlamov'}, 'assignees': [{'id': 20, 'name': 'Putin', 'username': 'marge-bot', 'state': 'active', 'avatar_url': 'https://www.gravatar.com/avatar/e20a65b7c095f620e8a714e7fb492e86?s=80&d=identicon', 'web_url': 'http://gitlab.domainname.ru/marge-bot'}], 'assignee': {'id': 20, 'name': 'Putin', 'username': 'marge-bot', 'state': 'active', 'avatar_url': 'https://www.gravatar.com/avatar/e20a65b7c095f620e8a714e7fb492e86?s=80&d=identicon', 'web_url': 'http://gitlab.domainname.ru/marge-bot'}, 'source_project_id': 14, 'target_project_id': 14, 'labels': [], 'work_in_progress': False, 'milestone': None, 'merge_when_pipeline_succeeds': False, 'merge_status': 'can_be_merged', 'sha': '17e717b610499c4e9460215e80dfb48d34ad9a87', 'merge_commit_sha': None, 'squash_commit_sha': None, 'discussion_locked': None, 'should_remove_source_branch': None, 'force_remove_source_branch': True, 'reference': '!19', 'references': {'short': '!19', 'relative': '!19', 'full': 'K.Kharlamov/projectname!19'}, 'web_url': 'http://gitlab.domainname.ru/K.Kharlamov/projectname/-/merge_requests/19', 'time_stats': {'time_estimate': 0, 'total_time_spent': 0, 'human_time_estimate': None, 'human_total_time_spent': None}, 'squash': False, 'task_completion_status': {'count': 0, 'completed_count': 0}, 'has_conflicts': False, 'blocking_discussions_resolved': True, 'subscribed': True, 'changes_count': '1', 'latest_build_started_at': None, 'latest_build_finished_at': None, 'first_deployed_to_production_at': None, 'pipeline': None, 'head_pipeline': {'id': 2853, 'sha': '17e717b610499c4e9460215e80dfb48d34ad9a87', 'ref': 'refs/merge-requests/19/head', 'status': 'pending', 'created_at': '2020-12-15T14:48:58.416Z', 'updated_at': '2020-12-15T14:48:58.784Z', 'web_url': 'http://gitlab.domainname.ru/K.Kharlamov/projectname/-/pipelines/2853', 'before_sha': '0000000000000000000000000000000000000000', 'tag': False, 'yaml_errors': None, 'user': {'id': 3, 'name': 'K.Kharlamov', 'username': 'K.Kharlamov', 'state': 'active', 'avatar_url': 'https://www.gravatar.com/avatar/b439ce4e5ef2cd0930ce216fdb843ed8?s=80&d=identicon', 'web_url': 'http://gitlab.domainname.ru/K.Kharlamov'}, 'started_at': None, 'finished_at': None, 'committed_at': None, 'duration': None, 'coverage': None, 'detailed_status': {'icon': 'status_pending', 'text': 'pending', 'label': 'pending', 'group': 'pending', 'tooltip': 'pending', 'has_details': True, 'details_path': '/K.Kharlamov/projectname/-/pipelines/2853', 'illustration': None, 'favicon': '/assets/ci_favicons/favicon_status_pending-5bdf338420e5221ca24353b6bff1c9367189588750632e9a871b7af09ff6a2ae.png'}}, 'diff_refs': {'base_sha': 'fe90a18cad6221ebb0fcc537bc5e92bed93a6fde', 'head_sha': '17e717b610499c4e9460215e80dfb48d34ad9a87', 'start_sha': 'fe90a18cad6221ebb0fcc537bc5e92bed93a6fde'}, 'merge_error': None, 'user': {'can_merge': True}}
Dec 15 17:51:58 localhost podman[22814]: 2020-12-15 14:51:58,593 INFO Successfully merged !19.

Version the bot refuses to tell (apparently there's no way to request it its version), but the podman/docker container smarkets/marge-bot is by 14 December 2020 (yesterday as of writing the words)

Hi-Angel commented 3 years ago

Alright, so, after debugging marge-bot for a bit I figured, the reason it does not wait is completely valid: it checks gitlab variable only_allow_merge_if_pipeline_succeeds, and uses its value.

The reason we had not this set is because I was pretty sure it is an enterprise-only feature. I dunno, maybe it was, but later then they changed they mind… Anyway, as of gitlab 13.6.1 this is available in community edition as well. Changing it can be done at Settings → General → Merge requests → ✓ Pipelines must succeed.

Hi-Angel commented 3 years ago

Actually, I think I'll reopen this. I'm gonna send a PR with docs on that matter, which then would close the issue.