Skip to content

Instantly share code, notes, and snippets.

@astrofrog
Created August 29, 2017 11:16
Show Gist options
  • Save astrofrog/f5e20c2e9e84ab97ff5433ef9b86b11a to your computer and use it in GitHub Desktop.
Save astrofrog/f5e20c2e9e84ab97ff5433ef9b86b11a to your computer and use it in GitHub Desktop.
import os
import netrc
from github import Github
from batchpr import Updater
DESCRIPTION = """
This is an automated update of the astropy-helpers submodule to {0}. This
includes both the update of the astropy-helpers sub-module, and the
``ah_bootstrap.py`` file, if needed.
*This is intended to be helpful, but if you would prefer to manage these updates
yourself, or if you notice any issues with this automated update, please let
@astrofrog know!*
"""
class AstropyHelpersUpdater(Updater):
def __init__(self, github, tag):
super(AstropyHelpersUpdater, self).__init__(github)
self.tag = tag
def process_repo(self):
if not os.path.exists('astropy_helpers'):
self.info("Repository {0} does not have an astropy_helpers "
"submodule".format(self.repo_name))
return False
os.chdir('astropy_helpers')
rev_prev = self.run_command('git rev-list HEAD').splitlines()
self.run_command('git fetch origin')
self.run_command('git checkout {0}'.format(self.tag))
rev_new = self.run_command('git rev-list HEAD').splitlines()
if len(rev_new) <= len(rev_prev):
self.warn(" Repository {0} already has an up-to-date "
"astropy-helpers".format(self.repo_name))
return False
os.chdir('..')
self.copy('astropy_helpers/ah_bootstrap.py', 'ah_bootstrap.py')
self.add('astropy_helpers')
self.add('ah_bootstrap.py')
return True
@property
def commit_message(self):
return "MNT: Update astropy-helpers to {0}".format(self.tag)
@property
def branch_name(self):
return 'astropy-helpers-{0}'.format(self.tag)
@property
def pull_request_title(self):
return self.commit_message
@property
def pull_request_body(self):
return DESCRIPTION.strip().format(self.tag)
my_netrc = netrc.netrc()
username, _, password = my_netrc.authenticators('api.github.com')[:3]
github = Github(username, password)
helper = AstropyHelpersUpdater(github=github, tag='v1.3')
helper.run('astrofrog/aplpy')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment