Mergifyio / mergify

Mergify Community Issue Tracker
https://mergify.com
Apache License 2.0
318 stars 92 forks source link

Mergify dimisses reviews when target branch of PR changes #5093

Closed jakobmerrild closed 1 year ago

jakobmerrild commented 1 year ago

Expected Behavior

Mergify should not dismiss reviews when there are no dissmiss_reviews actions configured

Actual Behavior

Mergify dismisses reviews when the base of a PR is changed by GitHub (due to the base having been merged from a different PR)

Screenshot 2023-07-13 at 15 57 49

Steps to Reproduce the Problem

  1. Branch from main
  2. Branch from branch in 1
  3. Open PR for branch from 1
  4. Open PR for branch from 2 targeting branch from 1
  5. Have mergify merge PR from 3
  6. GitHub will automatically change target of PR from 4 to main
  7. Mergify dimisses any reviews on PR from 4

Specifications

PR is in private repository, but adding our mergify config here

defaults:
  actions:
    comment:
      bot_account: OurMergifyBot
      message: "Default comment message"
    merge:
      merge_bot_account: OurMergifyBot
    rebase:
      bot_account: OurMergifyBot

queue_rules:
  - name: urgent
    conditions:
      - "status-success=main"
    checks_timeout: 40m

  - name: default
    conditions:
      - "status-success=main"
    speculative_checks: 3
    draft_bot_account: OurMergifyBot
    checks_timeout: 40m

pull_request_rules:
  - name: Urgent merge
    conditions:
      # To be merged automatically, a PR must be based off master
      - "base=master"
      # ... and have at least 2 approvals
      - "#approved-reviews-by>=2"
      # ... and all reviewers have reviewed
      - "#review-requested=0"
      # ... and all requests must be addressed
      - "#changes-requested-reviews-by=0"
      # ... and have the "Urgent" label applied. This lets us control when we want to queue the PR for merge
      - "label=Urgent"
    actions:
      queue:
        method: merge
        commit_message_template: |
          Merge pull request #{{ number }} {{ title }}

          {{ body }}
        name: urgent

  - name: Automatic merge
    conditions:
      # To be merged automatically, a PR must be based off master
      - "base=master"
      # ... and have at least 1 approval
      - "#approved-reviews-by>=1"
      # ... and all reviewers have reviewed
      - "#review-requested=0"
      # ... and all requests must be addressed
      - "#changes-requested-reviews-by=0"
      # ... and the "main" CI workflow must have completed successfully
      - "status-success=main"
      # ... and have the "Ready to merge" label applied. This lets us control when we want to queue the PR for merge
      - "label=Ready to merge"
      # ... and *not* have the "Blocked" label applied.
      - "label!=Blocked"
    actions:
      queue:
        method: merge
        commit_message_template: |
          Merge pull request #{{ number }} {{ title }}

          {{ body }}
        name: default

  - name: Delete merged branch
    conditions:
      - merged
    actions:
      delete_head_branch: {}

  # This labels PRs created by Scala Steward
  - name: Label dependency update PRs
    conditions:
      - "#label=0"
      - "base=master"
      - "head~=^update/"
      - "author=OurMergifyBot"
    actions:
      label:
        add: ["Dependency update", "Ready to merge"]

  # This automatically approves patch (semver) PRs created by
  # Scala Steward
  - name: Automatically approve patch dependency updates
    conditions:
      - "author=OurMergifyBot"
      - "label=Dependency update"
      - "body~=labels:.*semver-patch"
      - "#approved-reviews-by=0"
      - "#review-requested=0"
      - "#changes-requested-reviews-by=0"
    actions:
      review:
        type: APPROVE
        message: Automatically approving patch dependency update

  # This request reviews for dependency PRs, both the ones created by Scala
  # Steward and dependabot
  - name: Request review for dependency update PRs
    conditions:
      - "label=Dependency update"
      - "-body~=labels:.*semver-patch"
      - "#approved-reviews-by=0"
      - "#review-requested=0"
      - "#changes-requested-reviews-by=0"
    actions:
      request_reviews:
        teams: ["maintenance"]

  - name: Label & assign translation PRs
    conditions:
      - "#label=0"
      - "base=master"
      - "head~=^l10n_"
      - "author=OurMergifyBot"
    actions:
      assign:
        users: ["@backend-engineers"]
      request_reviews:
        teams: ["backend-engineers"]
      label:
        add: ["Translations", "Ready to merge"]

  - name: Label Migrations when changed files in migrations folder
    conditions:
      - "files~=^migrations"
      - "-label=Migrations"
    actions:
      label:
        add: ["Migrations"]

  - name: Automatically assign author to PR if unassigned
    conditions:
      - "author!=OurMergifyBot"
      - "#assignee=0"
    actions:
      assign:
        users: ["{{author}}"]
jd commented 1 year ago

👋 @kalanzai Could you reach out to us at support@mergify.com with the PR URL and the timestamp this happened? This would help find the root cause. Thank you!

jakobmerrild commented 1 year ago

@jd I can provide the url for the events here. Will that help?

jakobmerrild commented 1 year ago

I have sent the email 👍

jakobmerrild commented 1 year ago

I got a reply from support.

Mergify does not really dismiss reviews. GitHub does it on our behalf. When you use a stacked pull request and delete_head_branch features of Mergify. Mergify will delete the head branch when the pull request is merged. Then, when the branch is deleted, this triggers a background process on GitHub side to update the second pull request automatically. All actions taken by GitHub in the background process are associated with Mergify. GitHub changes the target branch on our behalf and dismiss the reviews on our behalf. This is why you see Mergify. But in reality, it's a GitHub behavior.

To workaround the issue, I would suggest removing delete_head_branch from Mergify configuration and using the GitHub equivalent: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-the-automatic-deletion-of-branches