Refined-github: Auto-retry for PR merges

Created on 14 Jan 2019  路  9Comments  路  Source: sindresorhus/refined-github

I work on TypeScript, and periodically do DefinitelyTyped duty, merging in type declarations for various untyped packages on npm. This extension has helped me a ton.

Much of the time, PRs are pretty easy to merge in and I can do many at a time; however, sometimes GitHub can't keep up!

image

I'll have to wait around to hit the "try again" button and try to merge.

This ends up making the process take a lot longer, and when there are so many @sindresorhus packages for the world to type :wink:, this can really start to add up.

Much like this extension adds a "merge when tests pass" feature, it'd be useful to us if there was also an auto-retry-on-failed-merge feature.

I get that this sounds like a pretty unique case, but it very well could be useful for other similar repositories. If it's too out there, I'd understand. :slightly_smiling_face:

enhancement help wanted

Most helpful comment

A fair warning here: "Try again" button does NOT use the merge method you chose but instead always chooses regular merge. Auto-clicking it may result in unwanted merge commit when you're using squash for example. It's a GitHub issue but with that in mind I try my best to never accidentally click that button.

All 9 comments

Why do they fail though? Does the retry button work on the same page or do you have to wait for the reload and then click on merge again?

You hit merge, you wait, then it says "merge attempt failed" - likely because GitHub pre-computes the merge commit which is then invalidated after the base branch changes. The retry button usually works.

Does the retry button work on the same page or do you have to wait for the reload and then click on merge again?

This just happened to me. The Try again button works right away, so it shouldn't be hard to implement... however I didn't think of copying the HTML of the form.

Any ideas which file would be good to take inspiration from? I'd think to look at the the "merge when tests pass" feature, but I don't know which file that is.

wait-for-build - got it.

Maybe features.onNewComments will detect it. Wait-for-build looks at the build status, that feature is a bit complex.

If that doesn鈥檛 work, maybe you can listen to the Merge form submit event (or error, if that exists).

If you can reliably reproduce this, you can look into GitHub鈥檚 own code to see if they fire any events

I caught it, inside .discussion-timeline-actions:

<div id="partial-pull-merging" class="pull-merging js-pull-merging js-socket-channel js-updatable-content is-error" data-channel="repo:162643582:branch:add/co-authored-by-everyone repo:51769689:branch:master repo:51769689:commit:c982c929e61aa200798a66019061c22e4bcced45 issue:393259305:state pull_request:240337227:review_state" data-url="/sindresorhus/refined-github/pull/1677/show_partial?commit_message=Pull+Requests+aren%27t+just+built+by+the+people+who+write+the+code%2C+they%27re+also+built+by+the+people+who+design%2C+test%2C+review%2C+and+comment+on+the+PR.%0D%0A%0D%0AWhen+merging+PRs+on+open+source+projects%2C+I+like+to+credit+everyone+involved+in+the+PR%2C+and+the+%5BCo-authored-by+trailer%5D%28https%3A%2F%2Fblog.github.com%2F2018-01-29-commit-together-with-co-authors%2F%29+is+super+helpful+to+do+exactly+that.%0D%0A%0D%0AThis+PR+automatically+generates+the+Co-authored-by+trailer+from+the+people+who%27ve+commented+on+the+PR.%0D%0A%0D%0ANote%3A+In+order+to+get+the+email+addresses+from+the+API%2C+your+Refined+GitHub+Access+Token+will+need+the+%60user%3Aemail%60+scope+added.%0D%0A%0D%0ACo-authored-by%3A+Federico+Brigante+%3Cgithub%40bfred.it%3E&amp;commit_title=Add+co-authors+when+merging+PRs+with+multiple+committers+%28%231677%29&amp;merge_type=squash&amp;partial=pull_requests%2Fmerging">








<div class="branch-action branch-action-state-error pull-merging-error">
  <span class="branch-action-icon">
    <svg height="32" class="octicon octicon-git-merge" viewBox="0 0 12 16" version="1.1" width="24" aria-hidden="true"><path fill-rule="evenodd" d="M10 7c-.73 0-1.38.41-1.73 1.02V8C7.22 7.98 6 7.64 5.14 6.98c-.75-.58-1.5-1.61-1.89-2.44A1.993 1.993 0 0 0 2 .99C.89.99 0 1.89 0 3a2 2 0 0 0 1 1.72v6.56c-.59.35-1 .99-1 1.72 0 1.11.89 2 2 2a1.993 1.993 0 0 0 1-3.72V7.67c.67.7 1.44 1.27 2.3 1.69.86.42 2.03.63 2.97.64v-.02c.36.61 1 1.02 1.73 1.02 1.11 0 2-.89 2-2 0-1.11-.89-2-2-2zm-6.8 6c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm8 6c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>
  </span>
  <div class="branch-action-body p-3">
    <button class="btn float-right js-merge-box-try-again" type="button">
      <svg class="octicon octicon-sync" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M10.24 7.4a4.15 4.15 0 0 1-1.2 3.6 4.346 4.346 0 0 1-5.41.54L4.8 10.4.5 9.8l.6 4.2 1.31-1.26c2.36 1.74 5.7 1.57 7.84-.54a5.876 5.876 0 0 0 1.74-4.46l-1.75-.34zM2.96 5a4.346 4.346 0 0 1 5.41-.54L7.2 5.6l4.3.6-.6-4.2-1.31 1.26c-2.36-1.74-5.7-1.57-7.85.54C.5 5.03-.06 6.65.01 8.26l1.75.35A4.17 4.17 0 0 1 2.96 5z"></path></svg>
      Try again
    </button>
    <h4 class="merge-branch-heading">Merge attempt failed</h4>
    <p class="merge-branch-description">We couldn鈥檛 merge this pull request. Reload the page before trying again.</p>

  </div>
</div>

</div>

It happened because I merged the PR in tab and then tried again in another tab I still had open. Clicking try again over and over doesn't seem to do anything (except sending the request again) so we should probably only re-try once when online after a few seconds

This code is likely to be 90% similar to https://github.com/sindresorhus/refined-github/blob/master/source/features/pr-branch-auto-delete.tsx

The core is: when the user clicks the merge button, wait the button to show up, then press it. In both cases the MutationObserver should be disconnected when there's no button at all.

A fair warning here: "Try again" button does NOT use the merge method you chose but instead always chooses regular merge. Auto-clicking it may result in unwanted merge commit when you're using squash for example. It's a GitHub issue but with that in mind I try my best to never accidentally click that button.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MilesBHuff picture MilesBHuff  路  3Comments

mareksuscak picture mareksuscak  路  3Comments

juliocanares picture juliocanares  路  3Comments

Celthi picture Celthi  路  3Comments

hkdobrev picture hkdobrev  路  3Comments