[asterisk-commits] digium commits: Make module more tolerant to input data; add... (repotools[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 24 06:03:55 CDT 2015


Joshua Colp has submitted this change and it was merged.

Change subject: digium_commits: Make module more tolerant to input data; add some enhancements
......................................................................


digium_commits: Make module more tolerant to input data; add some enhancements

While it would be nice if all commit messages were always formatted
identically, this is rarely the case. There are often subtle differences
in the key fields of a commit message. When parsed, these differences
can cause authors to be misreported, or altogether missed. This patch
makes the DigiumCommitMessageParser class more tolerant in the following
ways:

 * The parser is a bit more paranoid about what data is passed into it,
   and will now strip the username string before passing it into an
   instance of AsteriskUser
 * The parser will now be tolerant of hyphens in the "Reported By" (or
   "Reported-By") and "Tested By" (or "Tested-By") fields.
 * Open issues were previously missed due to the parser looking for the
   keyword "[Ii]ssue" prior to the JIRA issue key. This was the old
   nomenclature, prior to moving to JIRA smart commits. The "[Ii]ssue"
   field has been removed from the regex.

In addition to those cleanups, there are several times when it is
necessary to get at the raw commit message that the
DigiumCommitMessageParser has parsed. The class now supports storing the
raw commit message object.

digium_git: Pass the raw commit message down into the message parser

The release-summary script in particular needs portion of the raw Git
commit object in its generation of SHA1 links. This patch passes the raw
Git commit object down to the DigiumCommitMessageParser.

digium_jira_user: Be more paranoid of input data; fix License reporting

This patch fixes two issues:
 * We are now more paranoid with input data, stripping it of
   leading/trailing whitespace. This helps to prevent misreporting of
   authors.
 * The 'License' prefix was being reported twice, as we do not strip the
   'license' tag from the delineated license number.

REP-13
Reported by: Matt Jordan

Change-Id: I05a3d667b9d56465232eb293682a66fe97c3aaef
---
M digium_commits.py
M digium_git.py
M digium_jira_user.py
3 files changed, 24 insertions(+), 22 deletions(-)

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



diff --git a/digium_commits.py b/digium_commits.py
index ff6df91..f4508fa 100644
--- a/digium_commits.py
+++ b/digium_commits.py
@@ -19,18 +19,16 @@
     source projects.  The commit message guidelines can be found here:
 
     http://www.asterisk.org/doxygen/trunk/CommitMessages.html
-
-    See pysvn for a convenient interface for looking up svn logs for use along
-    with this interface.
     '''
 
-    def __init__(self, message, author):
-        '''
-        Initialize a commit message parser.
+    def __init__(self, message, author, raw=None):
+        '''Initialize a commit message parser.
 
-        The constructor takes two arguments:
-         - message: The text of the commit message as a string
-         - author: The name of the person who made the commit
+        Keyword Arguments:
+        message - The text of the commit message as a string
+        author  - The name of the person who made the commit
+        raw     - The raw commit message from the source control system.
+                  Optional.
 
         An attribute, block, will also be defined that indicates whether or not
         the commit was actually an svnmerge block commit, and not actually a
@@ -38,7 +36,8 @@
         string "Blocked revisions " is found in the commit message.
         '''
         self.message = unicode(message).encode('utf-8')
-        self.author = AsteriskUser(author)
+        self.author = AsteriskUser(author.strip())
+        self.raw = raw
         self.block = False
 
         if self.message.find("Blocked revisions ") >= 0:
@@ -70,13 +69,12 @@
             if i and i not in issues:
                 issues.append(i)
         for key in PROJECT_KEYS:
-            for match in re.finditer(closes + "[Ii]ssue %s-(\d+(?![-.]))[\D]" % key,
-                                     self.message, re.IGNORECASE):
-                i = {"type": "JIRA", "id": "%s-%s" % (key, match.group(1))}
-                if i and i not in issues:
-                    issues.append(i)
-        for key in PROJECT_KEYS:
-            for match in re.finditer("%s-(\d+(?![-.])) #close" % key, self.message, re.IGNORECASE):
+            regex = "(\d+(?![-.]))[\D]"
+            if closed:
+                regex = "{0}\s+#close".format(regex)
+            for match in re.finditer("{0}-{1}".format(key, regex),
+                                     self.message,
+                                     re.IGNORECASE):
                 i = {"type": "JIRA", "id": "%s-%s" % (key, match.group(1))}
                 if i and i not in issues:
                     issues.append(i)
@@ -93,7 +91,7 @@
         The return value is a list of strings.
         '''
         all_testers = []
-        for match in re.finditer("[Tt]ested [Bb]y:?(.*)", self.message):
+        for match in re.finditer("[Tt]ested(\s*|-)[Bb]y:?(.*)", self.message):
             testers = match.group(1).split(",")
             for t in testers:
                 user = AsteriskUser(t)
@@ -131,6 +129,7 @@
             if 'submitted by' in token.lower():
                 name = token[token.lower().index('submitted by') + 12:]
             if name:
+                name = name.strip()
                 if ':' in name:
                     name.replace(':', '')
                 if '<' in name:
@@ -165,8 +164,8 @@
         the issue that this commit was against.  It searches for the string
         "Reported by: ", then returns the name found after that.
         '''
-        reporter = ""
-        match = re.search("[Rr]eported [Bb]y:?(.*)", self.message)
+        reporter = None
+        match = re.search("[Rr]eported(\s*|-)[Bb]y:?(.*)", self.message)
         if match is not None:
             reporter = AsteriskUser(match.group(1))
         return reporter
diff --git a/digium_git.py b/digium_git.py
index d49b991..07a6272 100644
--- a/digium_git.py
+++ b/digium_git.py
@@ -190,7 +190,8 @@
 
         digium_commit = DigiumCommitMessageParser(
                             git_commit.message,
-                            unicode(git_commit.author.name).encode('utf-8'))
+                            unicode(git_commit.author.name).encode('utf-8'),
+                            git_commit)
         digium_commit.author.email = unicode(
                 git_commit.author.email).encode('utf-8')
         return digium_commit
diff --git a/digium_jira_user.py b/digium_jira_user.py
index 47a69fe..0b2e1f4 100644
--- a/digium_jira_user.py
+++ b/digium_jira_user.py
@@ -79,6 +79,8 @@
     def username(self, val):
         """Set accessor for username"""
         self._username = name_mappings.get(val) or val
+        if self._username:
+            self._username = self._username.strip()
         self.update_organization()
 
     def update_organization(self):
@@ -119,7 +121,7 @@
         if self.email:
             name = "{0} <{1}>".format(name, self.email)
         if self.license:
-            name = "{0} (License {1})".format(name, self.license)
+            name = "{0} ({1})".format(name, self.license)
         return name
 
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I05a3d667b9d56465232eb293682a66fe97c3aaef
Gerrit-PatchSet: 3
Gerrit-Project: repotools
Gerrit-Branch: master
Gerrit-Owner: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp 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