You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by eo...@apache.org on 2017/06/16 07:23:55 UTC

bookkeeper git commit: ISSUE #184: Support GitHub issues in bk-merge script

Repository: bookkeeper
Updated Branches:
  refs/heads/master 07852d358 -> 164c44bb9


ISSUE #184: Support GitHub issues in bk-merge script

- Recoganize the issue title and normalize it
- Close the corresponding issue when closing the pr

Author: Sijie Guo <si...@apache.org>

Reviewers: Enrico Olivelli <eo...@apache.org>

This closes #194 from sijie/support_github_issues, closes #184


Project: http://git-wip-us.apache.org/repos/asf/bookkeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/bookkeeper/commit/164c44bb
Tree: http://git-wip-us.apache.org/repos/asf/bookkeeper/tree/164c44bb
Diff: http://git-wip-us.apache.org/repos/asf/bookkeeper/diff/164c44bb

Branch: refs/heads/master
Commit: 164c44bb97e5b3ea8c658f5f376390b787061125
Parents: 07852d3
Author: Sijie Guo <si...@apache.org>
Authored: Fri Jun 16 09:23:31 2017 +0200
Committer: Enrico Olivelli <eo...@apache.org>
Committed: Fri Jun 16 09:23:31 2017 +0200

----------------------------------------------------------------------
 dev/bk-merge-pr.py | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/164c44bb/dev/bk-merge-pr.py
----------------------------------------------------------------------
diff --git a/dev/bk-merge-pr.py b/dev/bk-merge-pr.py
index cb5bd43..ddeb9b4 100755
--- a/dev/bk-merge-pr.py
+++ b/dev/bk-merge-pr.py
@@ -43,6 +43,7 @@ except ImportError:
 PROJECT_NAME = "bookkeeper"
 
 CAPITALIZED_PROJECT_NAME = "bookkeeper".upper()
+GITHUB_ISSUES_NAME = "issue".upper()
 
 # Location of the local git repository
 REPO_HOME = os.environ.get("%s_HOME" % CAPITALIZED_PROJECT_NAME, os.getcwd())
@@ -210,7 +211,14 @@ def merge_pr(pr_num, target_ref, title, body, default_pr_reviewers, pr_repo_desc
         merge_message_flags += ["-m", message]
 
     # The string "Closes #%s" string is required for GitHub to correctly close the PR
-    close_line = "Closes #%s from %s" % (pr_num, pr_repo_desc)
+    close_line = "This closes #%s from %s" % (pr_num, pr_repo_desc)
+    # Find the github issues to close
+    github_issues = re.findall("#[0-9]{3,6}", title)
+
+    if len(github_issues) != 0:
+        for issue_id in github_issues:
+            close_line += ", closes %s" % (issue_id)
+
     if should_list_commits:
         close_line += " and squashes the following commits:"
     merge_message_flags += ["-m", close_line]
@@ -360,6 +368,7 @@ def standardize_jira_ref(text):
     'BOOKKEEPER-877: Script for generating patch for reviews'
     """
     jira_refs = []
+    github_issue_refs = []
     components = []
 
     # Extract JIRA ref(s):
@@ -369,6 +378,13 @@ def standardize_jira_ref(text):
         jira_refs.append(re.sub(r'\s+', '-', ref.upper()))
         text = text.replace(ref, '')
 
+    # Extract Github Issue ref(s)
+    pattern = re.compile(r'(%s[-\s]*[0-9]{3,6})+' % GITHUB_ISSUES_NAME, re.IGNORECASE)
+    for ref in pattern.findall(text):
+        # Add brackets, replace spaces or a dash with ' #', & convert to uppercase
+        github_issue_refs.append(re.sub(r'[-\s]+', ' #', ref.upper()))
+        text = text.replace(ref, '')
+
     # Extract project name component(s):
     # Look for alphanumeric chars, spaces, dashes, periods, and/or commas
     pattern = re.compile(r'(\[[\w\s,-\.]+\])', re.IGNORECASE)
@@ -382,10 +398,14 @@ def standardize_jira_ref(text):
         text = pattern.search(text).groups()[0]
 
     # Assemble full text (JIRA ref(s), module(s), remaining text)
+    prefix = ''
     jira_prefix = ' '.join(jira_refs).strip()
     if jira_prefix:
-        jira_prefix = jira_prefix + ": "
-    clean_text = jira_prefix + ' '.join(components).strip() + " " + text.strip()
+        prefix = jira_prefix + ": "
+    github_prefix = ' '.join(github_issue_refs).strip()
+    if github_prefix:
+        prefix = github_prefix + ": "
+    clean_text = prefix + ' '.join(components).strip() + " " + text.strip()
 
     # Replace multiple spaces with a single space, e.g. if no jira refs and/or components were included
     clean_text = re.sub(r'\s+', ' ', clean_text.strip())