diff options
Diffstat (limited to 'dev/create-release/releaseutils.py')
-rwxr-xr-x | dev/create-release/releaseutils.py | 73 |
1 files changed, 52 insertions, 21 deletions
diff --git a/dev/create-release/releaseutils.py b/dev/create-release/releaseutils.py index 5d0ac16b3b..730138195e 100755 --- a/dev/create-release/releaseutils.py +++ b/dev/create-release/releaseutils.py @@ -30,28 +30,29 @@ try: except ImportError: from jira.utils import JIRAError except ImportError: - print "This tool requires the jira-python library" - print "Install using 'sudo pip install jira'" + print("This tool requires the jira-python library") + print("Install using 'sudo pip install jira'") sys.exit(-1) try: from github import Github from github import GithubException except ImportError: - print "This tool requires the PyGithub library" - print "Install using 'sudo pip install PyGithub'" + print("This tool requires the PyGithub library") + print("Install using 'sudo pip install PyGithub'") sys.exit(-1) try: import unidecode except ImportError: - print "This tool requires the unidecode library to decode obscure github usernames" - print "Install using 'sudo pip install unidecode'" + print("This tool requires the unidecode library to decode obscure github usernames") + print("Install using 'sudo pip install unidecode'") sys.exit(-1) # Contributors list file name contributors_file_name = "contributors.txt" + # Prompt the user to answer yes or no until they do so def yesOrNoPrompt(msg): response = raw_input("%s [y/n]: " % msg) @@ -59,30 +60,50 @@ def yesOrNoPrompt(msg): return yesOrNoPrompt(msg) return response == "y" + # Utility functions run git commands (written with Git 1.8.5) -def run_cmd(cmd): return Popen(cmd, stdout=PIPE).communicate()[0] -def run_cmd_error(cmd): return Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()[1] +def run_cmd(cmd): + return Popen(cmd, stdout=PIPE).communicate()[0] + + +def run_cmd_error(cmd): + return Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()[1] + + def get_date(commit_hash): return run_cmd(["git", "show", "--quiet", "--pretty=format:%cd", commit_hash]) + + def tag_exists(tag): stderr = run_cmd_error(["git", "show", tag]) return "error" not in stderr + # A type-safe representation of a commit class Commit: - def __init__(self, _hash, author, title, pr_number = None): + def __init__(self, _hash, author, title, pr_number=None): self._hash = _hash self.author = author self.title = title self.pr_number = pr_number - def get_hash(self): return self._hash - def get_author(self): return self.author - def get_title(self): return self.title - def get_pr_number(self): return self.pr_number + + def get_hash(self): + return self._hash + + def get_author(self): + return self.author + + def get_title(self): + return self.title + + def get_pr_number(self): + return self.pr_number + def __str__(self): closes_pr = "(Closes #%s)" % self.pr_number if self.pr_number else "" return "%s %s %s %s" % (self._hash, self.author, self.title, closes_pr) + # Return all commits that belong to the specified tag. # # Under the hood, this runs a `git log` on that tag and parses the fields @@ -106,8 +127,9 @@ def get_commits(tag): raw_commits = [c for c in output.split(commit_start_marker) if c] for commit in raw_commits: if commit.count(commit_end_marker) != 1: - print "Commit end marker not found in commit: " - for line in commit.split("\n"): print line + print("Commit end marker not found in commit: ") + for line in commit.split("\n"): + print(line) sys.exit(1) # Separate commit digest from the body # From the digest we extract the hash, author and the title @@ -178,6 +200,7 @@ known_components = { "yarn": "YARN" } + # Translate issue types using a format appropriate for writing contributions # If an unknown issue type is encountered, warn the user def translate_issue_type(issue_type, issue_id, warnings): @@ -188,6 +211,7 @@ def translate_issue_type(issue_type, issue_id, warnings): warnings.append("Unknown issue type \"%s\" (see %s)" % (issue_type, issue_id)) return issue_type + # Translate component names using a format appropriate for writing contributions # If an unknown component is encountered, warn the user def translate_component(component, commit_hash, warnings): @@ -198,20 +222,22 @@ def translate_component(component, commit_hash, warnings): warnings.append("Unknown component \"%s\" (see %s)" % (component, commit_hash)) return component + # Parse components in the commit message # The returned components are already filtered and translated def find_components(commit, commit_hash): components = re.findall("\[\w*\]", commit.lower()) - components = [translate_component(c, commit_hash)\ - for c in components if c in known_components] + components = [translate_component(c, commit_hash) + for c in components if c in known_components] return components + # Join a list of strings in a human-readable manner # e.g. ["Juice"] -> "Juice" # e.g. ["Juice", "baby"] -> "Juice and baby" # e.g. ["Juice", "baby", "moon"] -> "Juice, baby, and moon" def nice_join(str_list): - str_list = list(str_list) # sometimes it's a set + str_list = list(str_list) # sometimes it's a set if not str_list: return "" elif len(str_list) == 1: @@ -221,6 +247,7 @@ def nice_join(str_list): else: return ", ".join(str_list[:-1]) + ", and " + str_list[-1] + # Return the full name of the specified user on Github # If the user doesn't exist, return None def get_github_name(author, github_client): @@ -233,6 +260,7 @@ def get_github_name(author, github_client): raise e return None + # Return the full name of the specified user on JIRA # If the user doesn't exist, return None def get_jira_name(author, jira_client): @@ -245,15 +273,18 @@ def get_jira_name(author, jira_client): raise e return None + # Return whether the given name is in the form <First Name><space><Last Name> def is_valid_author(author): - if not author: return False + if not author: + return False return " " in author and not re.findall("[0-9]", author) + # Capitalize the first letter of each word in the given author name def capitalize_author(author): - if not author: return None + if not author: + return None words = author.split(" ") words = [w[0].capitalize() + w[1:] for w in words if w] return " ".join(words) - |