[asterisk-commits] jira-release-update: Update script to support Git (repotools[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 24 12:45:31 CDT 2015


Matt Jordan has submitted this change and it was merged.

Change subject: jira-release-update: Update script to support Git
......................................................................


jira-release-update: Update script to support Git

This patch updates the jira-release-update script to pull its commit
messages from a local Repo. The script now looks for two tags in the Git
history, extracts the JIRA issues from all commits between those two
tags, and then updates the fixVersion in the JIRA issues accordingly.

REP-14 #close
Reported by: Matt Jordan

Change-Id: I82091b9213f607cdf4e78ffc580508a00c405ca4
---
M jira-release-update.py
1 file changed, 65 insertions(+), 129 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, but someone else must approve
  Matt Jordan: Looks good to me, approved; Verified



diff --git a/jira-release-update.py b/jira-release-update.py
index 0996bea..e5e6735 100755
--- a/jira-release-update.py
+++ b/jira-release-update.py
@@ -1,87 +1,44 @@
 #!/usr/bin/env python
 """Update JIRA issues with the version they were closed in
 
-Copyright (C) 2013, Digium, Inc.
+Copyright (C) 2013-2015, Digium, Inc.
 Matt Jordan <mjordan at digium.com>
 
 """
 
 import sys
-import pysvn
-import getpass
+import os
 
-from optparse import OptionParser
-from jira.client import JIRA
 from progressbar import ProgressBar
-from digium_commits import DigiumCommitMessageParser
-from digium_commits import convert_name
+from optparse import OptionParser
 
-class Issue:
-    def __init__(self, issue, rev, parser, jira):
-        self.rev = rev
-        self.issue_id = issue["id"]
-        if issue["type"] != "JIRA":
-            self.jira_issue = None
-            return
-        self.jira_issue = jira.issue(self.issue_id)
-        self.reporter_name = self.jira_issue.fields.reporter.name
-        self.testers = parser.get_testers()
-        self.coders = parser.get_coders()
+from digium_git import DigiumGitRepo
+from digium_jira import get_jira_client
 
-def get_jira_auth():
-    """Get JIRA credentials"""
+# The upstream Gerrit repo
+GERRIT = 'https://gerrit.asterisk.org'
 
-    try:
-        jira_cache = open(os.path.expanduser('~') + "/.jira_login", "r")
-        jira_user = jira_cache.readline().strip()
-        jira_pw = jira_cache.readline().strip()
-        jira_cache.close()
-        return (jira_user, jira_pw)
-    except:
-        pass
+def update_issues(options):
+    """Update the fixVersion field in the JIRA issues
 
-    # Didn't get auth deatils from file, try interactive instead.
-    print "Please enter your username and pw for JIRA."
-    jira_user = raw_input("Username: ")
-    jira_pw = getpass.getpass("Password: ")
+    This will find all JIRA issues between two tags and update the
+    fixVersion field with the specified version.
 
-    return (jira_user, jira_pw)
-
-def collect_data(options):
+    Keyword Arguments:
+    options - Parsed command line parameters
+    """
     print "Update JIRA for %s-%s ..." % \
-        (options.svn_project, options.version)
+        (options.project, options.version)
 
-    # contributors = Contributors()
+    jira = get_jira_client()
 
-    (jira_user, jira_password) = get_jira_auth()
+    path = os.path.join(options.local_root, options.project)
+    gerrit_repo = '{0}/{1}'.format(GERRIT, options.project)
+    repo = DigiumGitRepo(path, gerrit_repo, show_progress=True)
 
-    jira_options = {
-        'server': 'https://issues.asterisk.org/jira/'
-    }
-
-    jira = JIRA(options=jira_options, basic_auth=(jira_user, jira_password))
-
-    client = pysvn.Client()
-    path = "%s/%s/branches/%s" % (options.svn_path,
-                                  options.svn_project,
-                                  options.svn_branch)
-    client.update(path)
-
-    start_rev = pysvn.Revision(pysvn.opt_revision_kind.number,
-                               options.start_rev)
-    if options.end_rev == "HEAD":
-        end_rev = pysvn.Revision(pysvn.opt_revision_kind.head)
-    else:
-        end_rev = pysvn.Revision(pysvn.opt_revision_kind.number,
-                                 options.end_rev)
-    log_messages = client.log(path, start_rev, end_rev)
-
-    jira_issues = {}
+    log_messages = repo.get_commits_by_tags(options.start_tag, options.end_tag)
 
     num_log_msgs = len(log_messages)
-
-    print "Processing revisions %s through %s of %s ..." % \
-        (options.start_rev, options.end_rev, path)
 
     pbar = ProgressBar()
     pbar.maxval = num_log_msgs
@@ -89,114 +46,93 @@
 
     jira_versions = {}
 
-    for i in range(0, num_log_msgs):
-        log_message = log_messages[i]
-        try:
-            parser = DigiumCommitMessageParser(log_message.message,
-                                               log_message.author)
-        except:
-            print "Failed to create message parser for %s" % str(log_message)
-            pbar.update(i + 1)
-            continue
+    for i, log_message in enumerate(log_messages):
 
-        if parser.block:
-            # Don't process the log message if it was actually a block
-            pbar.update(i + 1)
-            continue
-
-        issues = parser.get_issues(closed=True)
+        issues = log_message.get_issues(closed=True)
 
         if len(issues) == 0:
             pbar.update(i + 1)
             continue
 
-        for issue_id in issues:
-            issue = Issue(issue_id, log_message.revision.number, parser, jira)
-            if issue.jira_issue is None:
-                print "Could not get issue %s" % issue.issue_id
+        for issue_obj in issues:
+            issue_id = issue_obj.get('id')
+            try:
+                issue = jira.issue(issue_id)
+            except Exception:
+                print "Could not get issue {0}".format(issue_id)
                 continue
 
-            project = issue.jira_issue.fields.project
+            # Get the actual version object for the project. This
+            # is what must be passed to JIRA to update the fixVersion
+            # field for the issue.
+            project = issue.fields.project
             if project.name not in jira_versions:
                 project_versions = jira.project_versions(project)
                 try:
-                    version, = [ver.id for ver in project_versions if ver.name == options.version]
-                except:
+                    version, = [ver.id for ver in project_versions
+                                    if ver.name == options.version]
+                except Exception:
+                    print "Could not handle versions for {0}".format(issue_id)
                     continue
                 jira_versions[project.name] = version
 
-            matches = [match
-                       for match in issue.jira_issue.fields.fixVersions
+            # Make sure we don't update the fixVersion more than once for
+            # a particular issue
+            matches = [match for match in issue.fields.fixVersions
                             if match.name == options.version]
             if len(matches) == 0:
-                version_array = [{'id': u'%s' % ver.id} for ver in issue.jira_issue.fields.fixVersions]
-                version_array.append({'id': u'%s' % jira_versions[project.name]})
-                update_dict = {'fixVersions': version_array}
-                issue.jira_issue.update(fields={'fixVersions': version_array})
+                version_array = [{'id': u'{0}'.format(ver.id)} for ver in
+                                 issue.fields.fixVersions]
+                version_array.append({'id': u'{0}'.format(
+                                     jira_versions[project.name])})
+                issue.update(fields={'fixVersions': version_array})
 
         pbar.update(i + 1)
     pbar.finish()
 
     return
 
-    print "Generating diffstat ..."
-    diff_list = get_diff_stat(options)
-
-    contributors.sort_lists()
-
-    jira_category_list = []
-
-    for category, issues in jira_issues.items():
-        issues.sort(key=lambda x:x.issue_id)
-        jira_category_list.append((category, issues))
-    jira_category_list.sort(key=lambda x:x[0])
-
-    print "Generating output files ..."
-    html_print_out(options, contributors, jira_category_list, misc_commits,
-                   diff_list)
-
-    print "Done!"
-
 
 
 def main(argv=None):
+    """Main entry point
 
+    Keyword Arguments:
+    argv - Command line parameters
+    """
     if argv is None:
         argv = sys.argv
 
     parser = OptionParser()
 
-    parser.add_option("-u", "--svn-url", action="store", type="string",
-        dest="svn_path", default="https://origsvn.digium.com/svn",
-        help="SVN URL to use")
-    parser.add_option("-b", "--branch", action="store", type="string",
-        dest="svn_branch", default="", help="SVN branch for the release")
-    parser.add_option("-s", "--start-rev", action="store", type="string",
-        dest="start_rev", default="", help="Starting SVN Revision")
-    parser.add_option("-e", "--end-rev", action="store", type="string",
-        dest="end_rev", default="", help="Ending SVN Revision")
+    parser.add_option("-l", "--local-root", action="store", type="string",
+        dest="local_root", default="/tmp",
+        help="Root location on disk to store Git repositories")
+    parser.add_option("-s", "--start-tag", action="store", type="string",
+        dest="start_tag", default="", help="Tag to start from")
+    parser.add_option("-e", "--end-tag", action="store", type="string",
+        dest="end_tag", default="", help="Tag to end on")
     parser.add_option("-p", "--project", action="store", type="string",
-        dest="svn_project", default="asterisk",
-        help="Name of the SVN project (such as asterisk)")
+        dest="project", default="asterisk",
+        help="Name of the project (such as asterisk)")
     parser.add_option("-v", "--version", action="store", type="string",
         dest="version", default="",
-        help="Version ID (the SVN tag)")
+        help="Version ID.")
 
     (options, args) = parser.parse_args(argv)
 
-    if len(options.svn_branch) == 0:
-        parser.error("An SVN branch is required.")
+    if len(options.start_tag) == 0:
+        parser.error("A start tag is required.")
 
-    if len(options.start_rev) == 0:
-        parser.error("A beginning SVN revision is required.")
-
-    if len(options.end_rev) == 0:
-        parser.error("An ending SVN revision is required.")
+    if len(options.end_tag) == 0:
+        parser.error("An end tag is required.")
 
     if len(options.version) == 0:
         parser.error("A version ID is required.")
 
-    collect_data(options)
+    update_issues(options)
+
+    print "Done!"
 
 if __name__ == "__main__":
     main(sys.argv)

-- 
To view, visit https://gerrit.asterisk.org/180
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I82091b9213f607cdf4e78ffc580508a00c405ca4
Gerrit-PatchSet: 3
Gerrit-Project: repotools
Gerrit-Branch: master
Gerrit-Owner: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list