Last active
August 29, 2015 13:56
-
-
Save acdha/8848218 to your computer and use it in GitHub Desktop.
Script to create Github milestones for recurring release windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Create date-based release milestones on Github | |
By default this created milestones of the form 'Public Website – DATE' | |
If your git config defines github.user / github.password settings these will be used rather than prompting | |
for credentials. For sanity, !-prefixed github.password entries are supported so you can e.g. query the | |
OS X keychain rather than hard-coding passwords in a text file. | |
""" | |
import datetime | |
import json | |
import subprocess | |
import sys | |
from getpass import getpass, getuser | |
import requests | |
def check_simple_output(*args, **kwargs): | |
return "".join(subprocess.check_output(shell=True, *args, **kwargs)).strip() | |
def get_github_credentials(): | |
github_username = getuser() | |
github_password = None | |
try: | |
github_username = check_simple_output('git config --get github.user') | |
except subprocess.CalledProcessError: | |
pass | |
if not github_password: | |
try: | |
github_password = check_simple_output('git config --get github.password') | |
except subprocess.CalledProcessError: | |
pass | |
# Support Git config entries which are shell commands which return passwords | |
# e.g. !security find-internet-password -a USERNAME -gs https://github.com -w | tr -d '\n' | |
if github_password.startswith("!"): | |
github_password = check_simple_output(github_password.lstrip('!')) | |
if not github_password: | |
getpass("Github password: ") | |
return github_username, github_password | |
def main(): | |
username, password = get_github_credentials() | |
today = datetime.date.today() | |
r = requests.get('https://api.github.com/repos/loc-rdc/wdl/milestones', | |
auth=(username, password)) | |
r.raise_for_status() | |
milestones = [i['title'] for i in r.json()] | |
for month_offset in range(12): | |
for day in (8, 22): | |
target_month = today.month + month_offset | |
if target_month > 12: | |
target_month -= 12 | |
target_year = today.year + 1 | |
else: | |
target_year = today.year | |
release_day = today.replace(year=target_year, month=target_month, day=day) | |
milestone = 'Public Website - %s' % release_day.isoformat() | |
if milestone in milestones: | |
continue | |
print 'Creating %s' % milestone | |
r = requests.post('https://api.github.com/repos/loc-rdc/wdl/milestones', | |
auth=(username, password), | |
data=json.dumps({ | |
"title": milestone, | |
"due_on": release_day.isoformat() | |
})) | |
r.raise_for_status() | |
if __name__ == "__main__": | |
try: | |
import bpdb as pdb | |
except ImportError: | |
import pdb | |
try: | |
main() | |
except Exception as e: | |
print >>sys.stderr, e | |
pdb.pm() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment