<p>Benjamin Keith Ford has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7718">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">digium_commits.py: Fix parsing crashes and add error feedback.<br><br>The mkrelease.py script could crash when attempting to parse a commit message<br>that was not properly formatted. For example, opening parentheses would be<br>detected, and the script would parse until the index of a closing parentheses.<br>If there was no closing parentheses, the release script would crash.<br><br>This is a two-step fix. The first step is to ensure that when an error like<br>this occurs, the script does not fail. Try except blocks have been added to<br>parsing sections that can cause known crashes. When an error is detected, the<br>new errors list in the DigiumCommitMessageParser class will have the error<br>appended to it.<br><br>The second step will use this error message to provide feedback when a review<br>is submitted to Gerrit. A hook will be implemented that runs through some of<br>the parsing, gathers errors, and reports them back in the form of a -1 on the<br>code review, along with the error messages themselves.<br><br>Change-Id: Ibd5c86d69d32bc95d93c0cc81851083410d082a4<br>---<br>M digium_commits.py<br>1 file changed, 18 insertions(+), 13 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/repotools refs/changes/18/7718/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/digium_commits.py b/digium_commits.py<br>index 448e119..3da1a42 100644<br>--- a/digium_commits.py<br>+++ b/digium_commits.py<br>@@ -36,11 +36,15 @@<br> the commit was actually an svnmerge block commit, and not actually a<br> commit of code. The blocked attribute will be set to True if the<br> string "Blocked revisions " is found in the commit message.<br>+<br>+ Another attribute, errors, is defined to keep track of any problems<br>+ encountered while parsing the commit message.<br> '''<br> self.message = unicode(message)<br> self.author = get_user_by_username(author.strip())<br> self.raw = raw<br> self.block = False<br>+ self.errors = []<br> <br> if self.message.find("Blocked revisions ") >= 0:<br> self.block = True<br>@@ -60,14 +64,22 @@<br> <br> name = raw_user.strip()<br> if ':' in name:<br>- name.replace(':', '')<br>+ name = name.replace(':', '')<br> if '<' in name:<br>- realname = name[:name.index('<')]<br>- email = name[(name.index('<') + 1):name.index('>')]<br>+ try:<br>+ realname = name[:name.index('<')]<br>+ email = name[(name.index('<') + 1):name.index('>')]<br>+ except:<br>+ self.errors.append("Error while parsing '{0}': Is there a "<br>+ "closing '>'?".format(name))<br> if '(' in name:<br> if not realname:<br>- realname = name[:name.index('(')]<br>- license = name[(name.index('(') + 1):name.index(')')]<br>+ try:<br>+ realname = name[:name.index('(')]<br>+ license = name[(name.index('(') + 1):name.index(')')]<br>+ except:<br>+ self.errors.append("Error while parsing '{0}': Is there "<br>+ "a closing ')'?".format(name))<br> if not realname:<br> realname = name<br> if len(realname) == 0:<br>@@ -165,14 +177,7 @@<br> if 'submitted by' in token.lower():<br> name = token[token.lower().index('submitted by') + 12:]<br> if name:<br>- user = None<br>- try:<br>- user = self.extract_user(name)<br>- break<br>- except:<br>- print("INFO: Unable to parse message for users: ")<br>- print(self.message)<br>-<br>+ user = self.extract_user(name)<br> if user and user not in coders:<br> coders.append(user)<br> if len(coders) == 0:<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7718">change 7718</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7718"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: repotools </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ibd5c86d69d32bc95d93c0cc81851083410d082a4 </div>
<div style="display:none"> Gerrit-Change-Number: 7718 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.com> </div>