From 5b5ae43392cbef69a31f93a6c37e3a09331cc20f Mon Sep 17 00:00:00 2001
From: Major Hayden <major@mhtx.net>
Date: Wed, 20 Jul 2016 09:21:47 -0500
Subject: [PATCH] Better handling of newton branch in osa-differ

There was a bug in osa-differ where an exception would be thrown
if a new role appeared that didn't exist before. That's fixed in
this patch.

The script also skips the commit comparison if it notices that the
commit SHA matches between both OSA releases.

The RST output had broken headers before and those are fixed as
well.

Closes-bug: 1604840

Change-Id: Ifa47d64e7b79639a90871fdbf0370f8c425582ed
---
 osa-differ/osa-differ.py             | 33 ++++++++++++++++++----------
 osa-differ/templates/repo_details.j2 |  4 ++++
 2 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/osa-differ/osa-differ.py b/osa-differ/osa-differ.py
index 4f6d661b..c38377e4 100755
--- a/osa-differ/osa-differ.py
+++ b/osa-differ/osa-differ.py
@@ -125,19 +125,27 @@ def render_commit_template(user, repo, old_commit, new_commit, extra_vars={},
 
     # Compare the two commits in the project's repository to see what
     # the differences are between them.
-    logger.debug("Retrieving commits between {2} and {3} in "
-                 "{0}/{1}".format(user, repo, old_commit, new_commit))
-    comparison = gh.repos.commits.compare(
-        user=user,
-        repo=repo,
-        base=old_commit,
-        head=new_commit
-    )
+    if old_commit == new_commit:
+        logger.debug("Same starting and ending commit ({0}) for {1}/{2} - "
+                     "nothing to compare".format(short_commit(old_commit),
+                                                 user, repo))
+        commits = []
+    else:
+        logger.debug("Retrieving commits between {2} and {3} in "
+                     "{0}/{1}".format(user, repo, short_commit(old_commit),
+                                      short_commit(new_commit)))
+        comparison = gh.repos.commits.compare(
+            user=user,
+            repo=repo,
+            base=old_commit,
+            head=new_commit
+        )
+        commits = comparison.commits
 
     # Render the jinja2 template
     rendered_template = jinja_env.get_template(template_file).render(
         repo=repo,
-        commits=comparison.commits,
+        commits=commits,
         latest_sha=short_commit(new_commit),
         older_sha=short_commit(old_commit),
         extra_vars=extra_vars
@@ -288,8 +296,11 @@ if __name__ == "__main__":
 
         # Determine the older and newer SHA for this role
         latest_sha = role['version']
-        older_sha = next(x['version'] for x in old_role_yaml
-                         if x['name'] == role['name'])
+        try:
+            older_sha = next(x['version'] for x in old_role_yaml
+                             if x['name'] == role['name'])
+        except StopIteration:
+            older_sha = latest_sha
 
         # Render a template showing the commits in this role's repository.
         report += render_commit_template(
diff --git a/osa-differ/templates/repo_details.j2 b/osa-differ/templates/repo_details.j2
index d1a93447..eaba153e 100644
--- a/osa-differ/templates/repo_details.j2
+++ b/osa-differ/templates/repo_details.j2
@@ -1,6 +1,10 @@
 
 {{ repo }}
+{% if repo == 'openstack-ansible' %}
+{{ '-' * repo | length}}
+{% else %}
 {{ '~' * repo | length}}
+{% endif %}
 
 {% if commits | length < 1 %}
 No commits were found in `{{ repo }} <https://github.com/openstack/{{ repo }}>`_