summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Lukjanov <slukjanov@mirantis.com>2013-07-18 09:54:59 +0400
committerMonty Taylor <mordred@inaugust.com>2013-08-03 12:41:54 -0400
commit44ba87493d2c3ccf9e1af541284365ea44f911ac (patch)
tree652b5ef10c035b5a986f56ad0bdb44965a7ba300
parent8eff471f60a0be2eb6ede5525e224852d5c06048 (diff)
downloadpbr-44ba87493d2c3ccf9e1af541284365ea44f911ac.tar.gz
Improve AUTHORS file generation
* remove authors/co-authors duplicates * sort all authors/co-authors * add a new line to the end of file Change-Id: I48a388e8ae2defd05ad617d5de709d0e623a5c36
-rw-r--r--pbr/packaging.py37
-rw-r--r--pbr/tests/test_packaging.py2
2 files changed, 24 insertions, 15 deletions
diff --git a/pbr/packaging.py b/pbr/packaging.py
index 366f21e..763ba45 100644
--- a/pbr/packaging.py
+++ b/pbr/packaging.py
@@ -273,27 +273,36 @@ def generate_authors(git_dir=None, dest_dir='.', option_dict=dict()):
if git_dir is None:
git_dir = _get_git_directory()
if git_dir:
+ authors = []
+
# don't include jenkins email address in AUTHORS file
git_log_cmd = ("git --git-dir=" + git_dir +
- " log --format='%aN <%aE>' | sort -u | "
- "egrep -v '" + ignore_emails + "'")
- changelog = _run_shell_command(git_log_cmd)
- signed_cmd = ("git log --git-dir=" + git_dir +
- " | grep -i Co-authored-by: | sort -u")
- signed_entries = _run_shell_command(signed_cmd)
- if signed_entries:
- new_entries = "\n".join(
- [signed.split(":", 1)[1].strip()
- for signed in signed_entries.split("\n") if signed])
- changelog = "\n".join((changelog, new_entries))
+ " log --format='%aN <%aE>'"
+ " | egrep -v '" + ignore_emails + "'")
+ authors += _run_shell_command(git_log_cmd).split('\n')
+
+ # get all co-authors from commit messages
+ co_authors_cmd = ("git log --git-dir=" + git_dir +
+ " | grep -i Co-authored-by:")
+ co_authors = _run_shell_command(co_authors_cmd)
+
+ co_authors = [signed.split(":", 1)[1].strip()
+ for signed in co_authors.split('\n') if signed]
+
+ authors += co_authors
+
+ # canonicalize emails, remove duplicates and sort
+ mailmap = read_git_mailmap(git_dir)
+ authors = canonicalize_emails('\n'.join(authors), mailmap)
+ authors = authors.split('\n')
+ authors = sorted(set(authors))
- mailmap = read_git_mailmap()
with open(new_authors, 'wb') as new_authors_fh:
if os.path.exists(old_authors):
with open(old_authors, "rb") as old_authors_fh:
new_authors_fh.write(old_authors_fh.read())
- new_authors_fh.write(canonicalize_emails(
- changelog, mailmap).encode('utf-8'))
+ new_authors_fh.write(('\n'.join(authors) + '\n')
+ .encode('utf-8'))
_rst_template = """%(heading)s
diff --git a/pbr/tests/test_packaging.py b/pbr/tests/test_packaging.py
index 7461c0f..562b10e 100644
--- a/pbr/tests/test_packaging.py
+++ b/pbr/tests/test_packaging.py
@@ -79,7 +79,7 @@ class TestPackagingInGitRepoWithoutCommit(tests.BaseTestCase):
# No commits, no authors in list
with open(os.path.join(self.package_dir, 'AUTHORS'), 'r') as f:
body = f.read()
- self.assertEqual(body, '')
+ self.assertEqual(body, '\n')
def test_changelog(self):
# No commits, nothing should be in the ChangeLog list