<p>Kevin Harwell <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7718">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved; Approved for Submit
</div><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. Jenkins will run a job that goes through some of the<br>parsing, gathers errors with the parse_commit.py script, and reports them back<br>in the form of a -1 on the code review, along with the error messages<br>themselves.<br><br>Change-Id: Ibd5c86d69d32bc95d93c0cc81851083410d082a4<br>---<br>M digium_commits.py<br>A parse_commit.py<br>2 files changed, 39 insertions(+), 13 deletions(-)<br><br></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>diff --git a/parse_commit.py b/parse_commit.py<br>new file mode 100644<br>index 0000000..c47389c<br>--- /dev/null<br>+++ b/parse_commit.py<br>@@ -0,0 +1,21 @@<br>+#!/usr/bin/env python<br>+<br>+import sys<br>+from argparse import ArgumentParser<br>+from digium_commits import DigiumCommitMessageParser<br>+<br>+def parse_commit(commit, author):<br>+ commit_parser = DigiumCommitMessageParser(commit, author)<br>+ commit_parser.get_coders()<br>+ if len(commit_parser.errors) > 0:<br>+ for error in commit_parser.errors:<br>+ print error<br>+ sys.exit(-1)<br>+<br>+if __name__ == '__main__':<br>+ arg_parser = ArgumentParser()<br>+ arg_parser.add_argument('-c', '--commit', required=True, help='The commit message')<br>+ arg_parser.add_argument('-a', '--author', required=True, help='The author of the commit')<br>+ args = arg_parser.parse_args()<br>+ parse_commit(args.commit, args.author)<br>+ sys.exit(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: merged </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: 3 </div>
<div style="display:none"> Gerrit-Owner: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>