def make_rpc_report(repo_dir, old_commit, new_commit, args): """Create initial RST report header for OpenStack-Ansible.""" rpc_repo_url = "https://github.com/rcbops/rpc-openstack" osa_differ.update_repo(repo_dir, rpc_repo_url, args.update) # Are these commits valid? osa_differ.validate_commits(repo_dir, [old_commit, new_commit]) # Do we have a valid commit range? osa_differ.validate_commit_range(repo_dir, old_commit, new_commit) # Get the commits in the range commits = osa_differ.get_commits(repo_dir, old_commit, new_commit) # Start off our report with a header and our OpenStack-Ansible commits. template_vars = { 'args': args, 'repo': 'rpc-openstack', 'commits': commits, 'commit_base_url': osa_differ.get_commit_url(rpc_repo_url), 'old_sha': old_commit, 'new_sha': new_commit } return render_template('offline-header.j2', template_vars)
def test_render_template(self, tmpdir): """Verify that we can render a jinja template.""" p = tmpdir.mkdir('test') path = str(p) repo = Repo.init(path) for x in range(0, 10): file = p / "test{0}.txt".format(x) file.write_text(u"Test", encoding='utf-8') repo.index.add(['test{0}.txt'.format(x)]) repo.index.commit("Commit #{0}".format(x)) commits = osa_differ.get_commits(path, 'HEAD~2', 'HEAD') template_vars = { 'repo': 'openstack-ansible', 'commits': commits, 'commit_base_url': 'http://example.com', 'old_sha': 'HEAD~10', 'new_sha': 'HEAD~1' } template_filename = "offline-repo-changes.j2" rst = osa_differ.render_template(template_filename, template_vars) assert "openstack-ansible" in rst assert "2 commits were found" in rst assert "http://example.com" in rst assert "HEAD~10" in rst assert "HEAD~1" in rst
def make_rpc_report(repo_dir, old_commit, new_commit, args): """Create initial RST report header for OpenStack-Ansible.""" # Do we have a valid commit range? # NOTE: # An exception is thrown by osa_differ if these two commits # are the the same, but it is sometimes necessary to compare # two RPC tags that have the same OSA SHA. For example, # comparing two tags that only have differences between the # two RPCO commit, but no differences between the OSA SHAs # that correspond to those two commits. # To handle this case, the exception will be caught and flow # of execution will continue normally. try: osa_differ.validate_commit_range(repo_dir, old_commit, new_commit) except exceptions.InvalidCommitRangeException: pass # Get the commits in the range commits = osa_differ.get_commits(repo_dir, old_commit, new_commit) # Start off our report with a header and our OpenStack-Ansible commits. template_vars = { 'args': args, 'repo': 'rpc-openstack', 'commits': commits, 'commit_base_url': osa_differ.get_commit_url(args.rpc_repo_url), 'old_sha': old_commit, 'new_sha': new_commit } return render_template('offline-header.j2', template_vars)
def test_get_commits(self, tmpdir): """Verify that we can get commits for a repo.""" p = tmpdir.mkdir('test') path = str(p) repo = Repo.init(path) for x in range(0, 10): file = p / "test{0}.txt".format(x) file.write_text(u"Test", encoding='utf-8') repo.index.add(['test{0}.txt'.format(x)]) repo.index.commit("Commit #{0}".format(x)) commits = osa_differ.get_commits(path, 'HEAD~2', 'HEAD') assert len(list(commits)) == 2