From 938b4f81115a22391915291c801fb6f7786b75b3 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Fri, 8 Aug 2014 16:53:45 -0400 Subject: [PATCH 1/2] Handle Validation Failed for release script --- scripts/release.py | 50 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/scripts/release.py b/scripts/release.py index a65c2a149f..b247d683b4 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -149,10 +149,58 @@ def create_github_creds(): headers=headers, data=json.dumps(payload), ) if not response.ok: - raise requests.exceptions.RequestException(response.json()["message"]) + message = response.json()["message"] + if message != "Validation Failed": + raise requests.exceptions.RequestException(message) + else: + # A token called "edx-release" already exists on Github. + # Delete it, and try again. + token_id = get_github_auth_id(username, password, "edx-release") + if token_id: + delete_github_auth_token(username, password, token_id) + response = requests.post( + "https://api.github.com/authorizations", + auth=(username, password), + headers=headers, data=json.dumps(payload), + ) + if not response.ok: + message = response.json()["message"] + raise requests.exceptions.RequestException(message) + return (username, response.json()["token"]) +def get_github_auth_id(username, password, note): + """ + Return the ID associated with the Github auth token with the given note. + If no such auth token exists, return None. + """ + response = requests.get( + "https://api.github.com/authorizations", + auth=(username, password), + headers={"User-Agent": "edx-release"}, + ) + if not response.ok: + message = response.json()["message"] + raise requests.exceptions.RequestException(message) + + for auth_token in response.json(): + if auth_token["note"] == "edx-release": + return auth_token["id"] + return None + + +def delete_github_auth_token(username, password, token_id): + response = requests.delete( + "https://api.github.com/authorizations/{id}".format(id=token_id), + auth=(username, password), + headers={"User-Agent": "edx-release"}, + ) + if not response.ok: + message = response.json()["message"] + raise requests.exceptions.RequestException(message) + + def ensure_github_creds(attempts=3): """ Make sure that we have Github OAuth credentials. This will check the user's From f4bfe464e28f6bf3483a22c7c719c11abaac88bd Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Fri, 8 Aug 2014 16:56:49 -0400 Subject: [PATCH 2/2] Friendly error message if you don't have dependencies installed --- scripts/release.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/release.py b/scripts/release.py index b247d683b4..1d9e632336 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -4,19 +4,26 @@ a release-master multitool """ from __future__ import print_function, unicode_literals import sys -from path import path -from git import Repo, Commit -from git.refs.symbolic import SymbolicReference import argparse from datetime import date, timedelta -from dateutil.parser import parse as parse_datestring import re import collections import functools import textwrap -import requests import json import getpass + +try: + from path import path + from git import Repo, Commit + from git.refs.symbolic import SymbolicReference + from dateutil.parser import parse as parse_datestring + import requests +except ImportError: + print("Error: missing dependencies! Please run this command to install them:") + print("pip install path.py requests python-dateutil GitPython==0.3.2.RC1") + sys.exit(1) + try: from pygments.console import colorize except ImportError: