Skip to content

Instantly share code, notes, and snippets.

@Teemu
Created June 6, 2018 08:52
Show Gist options
  • Save Teemu/f10570fc3e426643407d645b5d30de97 to your computer and use it in GitHub Desktop.
Save Teemu/f10570fc3e426643407d645b5d30de97 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python3
from pycookiecheat import chrome_cookies
from requests_html import HTMLSession
import requests
import click
import time
import pync
@click.command()
@click.argument('url')
def mergewhenready(url):
cookies = chrome_cookies(url)
session = HTMLSession()
for i in range(0, 10000000):
r = session.get(url, cookies=cookies)
if 'Review required' in r.content.decode('utf-8'):
print('Note: Review is required!')
break
if 'pending check' in r.content.decode('utf-8'):
sleep_time = round(min(10 * 1.5**i, 3600))
print('Pending check... checking again in %i' % sleep_time)
time.sleep(sleep_time)
elif 'This branch is out-of-date with the base branch' in r.content.decode('utf-8'):
print('Branch is out-of-date, updating with base branch...')
input_attrs = {
x.attrs['name']: x.attrs['value']
for x in r.html.find('.branch-action-item form.js-handle-pull-merging-errors input')
}
action = 'https://github.com' + r.html.find('.branch-action-item form.js-handle-pull-merging-errors')[0].attrs['action']
assert input_attrs
post_r = session.post(action, data=input_attrs, cookies=cookies)
assert post_r.status_code == 200
elif 'Rebase and merge can be performed automatically.' in r.content.decode('utf-8'):
assert 'All checks have passed' in r.content.decode('utf-8')
input_attrs = {
x.attrs['name']: x.attrs['value']
for x in r.html.find('form.js-merge-pull-request input')
}
input_attrs['do'] = 'rebase'
input_attrs['commit_message'] = r.html.find('form.js-merge-pull-request textarea')[0].text
action = 'https://github.com' + r.html.find('form.js-merge-pull-request')[0].attrs['action']
assert input_attrs
post_r = session.post(action, data=input_attrs, cookies=cookies)
assert post_r.status_code == 200
pync.notify('Pull request was merged successfully!')
print('Pull request was merged successfully!')
break
else:
pync.notify('Some error happened regarding PR merge.')
print('Some error happened!')
click.launch(url)
break
if __name__ == '__main__':
mergewhenready()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment