From 4611feda7ccdd1bbd5d8d87e1e292826974c9686 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 09 2016 13:55:02 +0000 Subject: [PATCH 1/5] Publish the username of all the users who authored the commits pushed --- diff --git a/pagure/hooks/files/fedmsg_hook.py b/pagure/hooks/files/fedmsg_hook.py index 043bc6c..73007a1 100755 --- a/pagure/hooks/files/fedmsg_hook.py +++ b/pagure/hooks/files/fedmsg_hook.py @@ -56,6 +56,14 @@ for line in sys.stdin.readlines(): if not project: project = project_name + pushers = set() + for rev in revs: + email = pagure.lib.git.get_pusher_email(rev, abspath) + name = pagure.lib.git.get_pusher(rev, abspath) + pusher = search_user(pagure.SESSION, email=email) or name + pushers.add(pusher) + + if revs: revs.reverse() print "* Publishing information for %i commits" % len(revs) @@ -68,6 +76,7 @@ for line in sys.stdin.readlines(): end_commit=revs[-1], branch=refname, forced=forced, + users=list(pushers), agent=username, repo=project.to_json(public=True) if not isinstance(project, basestring) else project, From 9364354a4555ba17aa60f0dc844d70b74eb1aecd Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 09 2016 13:57:01 +0000 Subject: [PATCH 2/5] Small style fix --- diff --git a/pagure/hooks/files/fedmsg_hook.py b/pagure/hooks/files/fedmsg_hook.py index 73007a1..629bb7d 100755 --- a/pagure/hooks/files/fedmsg_hook.py +++ b/pagure/hooks/files/fedmsg_hook.py @@ -63,7 +63,6 @@ for line in sys.stdin.readlines(): pusher = search_user(pagure.SESSION, email=email) or name pushers.add(pusher) - if revs: revs.reverse() print "* Publishing information for %i commits" % len(revs) From 52a441666b9f75ddfe07775c9bd0cec7fc401db5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 09 2016 14:21:16 +0000 Subject: [PATCH 3/5] Name the authors as such What we retrieve is actually the name/email of the author, nothing to do with the pusher --- diff --git a/pagure/hooks/files/fedmsg_hook.py b/pagure/hooks/files/fedmsg_hook.py index 629bb7d..f6c2e6a 100755 --- a/pagure/hooks/files/fedmsg_hook.py +++ b/pagure/hooks/files/fedmsg_hook.py @@ -56,12 +56,12 @@ for line in sys.stdin.readlines(): if not project: project = project_name - pushers = set() + authors = set() for rev in revs: email = pagure.lib.git.get_pusher_email(rev, abspath) name = pagure.lib.git.get_pusher(rev, abspath) - pusher = search_user(pagure.SESSION, email=email) or name - pushers.add(pusher) + author = search_user(pagure.SESSION, email=email) or name + authors.add(author) if revs: revs.reverse() @@ -75,7 +75,7 @@ for line in sys.stdin.readlines(): end_commit=revs[-1], branch=refname, forced=forced, - users=list(pushers), + authors=list(authors), agent=username, repo=project.to_json(public=True) if not isinstance(project, basestring) else project, From 00d774558862db9ed12ab622cea0fbd4c2b7ca3e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 10 2016 17:55:43 +0000 Subject: [PATCH 4/5] Rename get_pusher and get_pusher_email to get_author and get_author_email This reflects what is actually returned, the author of the patch/commit. --- diff --git a/pagure/hooks/files/fedmsg_hook.py b/pagure/hooks/files/fedmsg_hook.py index f6c2e6a..f363c4f 100755 --- a/pagure/hooks/files/fedmsg_hook.py +++ b/pagure/hooks/files/fedmsg_hook.py @@ -58,8 +58,8 @@ for line in sys.stdin.readlines(): authors = set() for rev in revs: - email = pagure.lib.git.get_pusher_email(rev, abspath) - name = pagure.lib.git.get_pusher(rev, abspath) + email = pagure.lib.git.get_author_email(rev, abspath) + name = pagure.lib.git.get_author(rev, abspath) author = search_user(pagure.SESSION, email=email) or name authors.add(author) diff --git a/pagure/hooks/files/pagure_hook.py b/pagure/hooks/files/pagure_hook.py index d0cb008..d9d635e 100755 --- a/pagure/hooks/files/pagure_hook.py +++ b/pagure/hooks/files/pagure_hook.py @@ -74,7 +74,7 @@ def relates_commit(commitid, issue, app_url=None): pagure.SESSION, issue=issue, comment=comment, - user=pagure.lib.git.get_pusher_email(commitid, abspath), + user=pagure.lib.git.get_author_email(commitid, abspath), ticketfolder=pagure.APP.config['TICKETS_FOLDER'], ) pagure.SESSION.commit() @@ -107,7 +107,7 @@ def fixes_relation(commitid, relation, app_url=None): pagure.SESSION, issue=relation, comment=comment, - user=pagure.lib.git.get_pusher_email(commitid, abspath), + user=pagure.lib.git.get_author_email(commitid, abspath), ticketfolder=pagure.APP.config['TICKETS_FOLDER'], ) elif relation.isa == 'pull-request': @@ -119,7 +119,7 @@ def fixes_relation(commitid, relation, app_url=None): filename=None, row=None, comment=comment, - user=pagure.lib.git.get_pusher_email(commitid, abspath), + user=pagure.lib.git.get_author_email(commitid, abspath), requestfolder=pagure.APP.config['REQUESTS_FOLDER'], ) pagure.SESSION.commit() @@ -142,14 +142,14 @@ def fixes_relation(commitid, relation, app_url=None): pagure.SESSION, relation, ticketfolder=pagure.APP.config['TICKETS_FOLDER'], - user=pagure.lib.git.get_pusher_email(commitid, abspath), + user=pagure.lib.git.get_author_email(commitid, abspath), status='Fixed') elif relation.isa == 'pull-request': pagure.lib.close_pull_request( pagure.SESSION, relation, requestfolder=pagure.APP.config['REQUESTS_FOLDER'], - user=pagure.lib.git.get_pusher_email(commitid, abspath), + user=pagure.lib.git.get_author_email(commitid, abspath), merged=True) pagure.SESSION.commit() except pagure.exceptions.PagureException as err: diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 3926213..95691e0 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -887,16 +887,16 @@ def get_default_branch(abspath): return 'master' -def get_pusher(commit, abspath): - ''' Return the name of the person that pushed the commit. ''' +def get_author(commit, abspath): + ''' Return the name of the person that authored the commit. ''' user = pagure.lib.git.read_git_lines( ['log', '-1', '--pretty=format:"%an"', commit], abspath)[0].replace('"', '') return user -def get_pusher_email(commit, abspath): - ''' Return the email of the person that pushed the commit. ''' +def get_author_email(commit, abspath): + ''' Return the email of the person that authored the commit. ''' user = pagure.lib.git.read_git_lines( ['log', '-1', '--pretty=format:"%ae"', commit], abspath)[0].replace('"', '') From ad3d68b3618167b18c272caea816327ab888dacc Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 10 2016 17:56:12 +0000 Subject: [PATCH 5/5] Adjust the unit-tests for the rename of get_pusher and get_pusher_email --- diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py index d3d7e31..bb90894 100644 --- a/tests/test_pagure_lib_git.py +++ b/tests/test_pagure_lib_git.py @@ -1260,8 +1260,8 @@ index 0000000..60f7480 from_hash, to_hash, gitrepo) self.assertEqual(output2, [to_hash]) - def test_get_pusher(self): - """ Test the get_pusher method of pagure.lib.git. """ + def test_get_author(self): + """ Test the get_author method of pagure.lib.git. """ self.test_update_git() @@ -1271,11 +1271,11 @@ index 0000000..60f7480 self.assertEqual(len(output), 2) for githash in output: githash = githash.replace("'", '') - output = pagure.lib.git.get_pusher(githash, gitrepo) + output = pagure.lib.git.get_author(githash, gitrepo) self.assertEqual(output, 'pagure') - def test_get_pusher_email(self): - """ Test the get_pusher_email method of pagure.lib.git. """ + def get_author_email(self): + """ Test the get_author_email method of pagure.lib.git. """ self.test_update_git() @@ -1285,7 +1285,7 @@ index 0000000..60f7480 self.assertEqual(len(output), 2) for githash in output: githash = githash.replace("'", '') - output = pagure.lib.git.get_pusher_email(githash, gitrepo) + output = pagure.lib.git.get_author_email(githash, gitrepo) self.assertEqual(output, 'pagure') def test_get_repo_name(self):