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

Does not close Restyled PR on merge if base branch changed #150

Closed
pbrisbin opened this issue Jul 22, 2021 · 1 comment · Fixed by #166
Closed

Does not close Restyled PR on merge if base branch changed #150

pbrisbin opened this issue Jul 22, 2021 · 1 comment · Fixed by #166
Labels

Comments

@pbrisbin
Copy link
Member

pbrisbin commented Jul 22, 2021

(Originally reported as https://github.com/restyled-io/restyled.io/issues/246)

When we handle a PR event and find it's Closed, we intend to clean up any open Restyle PRs. We do this by finding a PR where its base is the head of the originating PR. The head/base refs are the only way to search for PRs in the GitHub REST API.

GitHub recently launched a feature where if you open a PR-from-PR, then merge the first one, it adjusts the base branch of the second automatically. This breaks the above flow.

Consider the following:

  1. You open PR 1: pb/fix -> main
  2. We open Restyle PR 2: restyled/pb/fix -> pb/fix
  3. You merge pb/fix
  4. GitHub updates PR 2 to restyled/pb/fix -> main
  5. We look for a Restyle PR where base: pb/fix, finding none

(4) and (5) are a race. Sometimes it works (reverse from above), but usually we lose, which leaves the Restyle PR open.

Possible solutions

  1. We could record the Restyle PR details somewhere when we open it

    Our Backend service launches a Restyler process and records stdout/stderr. There is no structured way for Restyler to report back data like this. We would have to build that entire idea to make this possible. Something like GitHub's workflow commands in the stdout stream?

  2. We could look harder for this PR in the GitHub API

    The "List PR" endpoint only supports looking by head/base. So using that would require listing all PRs against the original base branch of the originating PR (e.g. main) and then filtering in code (e.g. by title = Restyle {title}).

    Does the GraphQL API offer more options?

@pbrisbin pbrisbin added the bug label Jul 22, 2021
@pbrisbin
Copy link
Member Author

/cc @mjgpy3

pbrisbin added a commit that referenced this issue Oct 21, 2021
Given a PR with head pb/fix, we'd locate a Restyled PR by looking for
one where:

    base == pb/fix &&
      head == restyled/pb/fix

This is a very precise search but fails if GitHub has automatically
switches the base after pb/fix was merged, as it so helpfully does.

We could update this to,

    (base == pb/fix || base == {default branch}) &&
      head == restyled/pb/fix

But that seems complicated, and would miss a case of a Restyling on a
branch-from-branch situation.

We could simplify to,

    head == restyled/pb/fix

But false-positives are scary, considering they could result in a
force-push over a user's unrelated Pull Request.

Therefore, we'll do

    head == restyled/pb/fix &&
      user =~ ^restyled-io

Having the check on user will prevent force-pushes onto users no matter
how well this works (or not).

Fixes #150.
pbrisbin added a commit that referenced this issue Oct 21, 2021
Given a PR with head pb/fix, we'd locate a Restyled PR by looking for
one where:

    base == pb/fix &&
      head == restyled/pb/fix

This is a very precise search but fails if GitHub has automatically
switches the base after pb/fix was merged, as it so helpfully does.

We could update this to,

    (base == pb/fix || base == {default branch}) &&
      head == restyled/pb/fix

But that seems complicated, and would miss a case of a Restyling on a
branch-from-branch situation.

We could simplify to,

    head == restyled/pb/fix

But false-positives are scary, considering they could result in a
force-push over a user's unrelated Pull Request.

Therefore, we'll do

    head == restyled/pb/fix &&
      user =~ ^restyled-io

Having the check on user will prevent force-pushes onto users no matter
how well this works (or not).

Fixes #150.
pbrisbin added a commit that referenced this issue Oct 22, 2021
Given a PR with head pb/fix, we'd locate a Restyled PR by looking for
one where:

    base == pb/fix &&
      head == restyled/pb/fix

This is a very precise search but fails if GitHub has automatically
switches the base after pb/fix was merged, as it so helpfully does.

We could update this to,

    (base == pb/fix || base == {default branch}) &&
      head == restyled/pb/fix

But that seems complicated, and would miss a case of a Restyling on a
branch-from-branch situation.

We could simplify to,

    head == restyled/pb/fix

But false-positives are scary, considering they could result in a
force-push over a user's unrelated Pull Request.

Therefore, we'll do

    head == restyled/pb/fix &&
      user =~ ^restyled-io

Having the check on user will prevent force-pushes onto users no matter
how well this works (or not).

Fixes #150.
@pbrisbin pbrisbin added this to Roadmap Mar 6, 2023
@pbrisbin pbrisbin moved this to Done in Roadmap Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant