From 67c8211a32cf798e757ab12473d9b047eb41012f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 23 2017 10:31:15 +0000 Subject: [PATCH 1/2] Make the pagure hook act as the person doing the push This was a small annoyance we had, if you were amending a commit from someone else, or just rewording the commit message (for example to add the ``Merges...`` line) and pushing to the main repo, pagure would show the action has being done by the author of the commit rather than the person who pushed that commit. This commit fixes this by relying on the environment variable set by gitolite if it is present, else going back to the author of the commit if we cannot know who pushed. Fixes https://pagure.io/pagure/issue/2597 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/files/pagure_hook.py b/pagure/hooks/files/pagure_hook.py old mode 100755 new mode 100644 index 94e8aa5..fbad2a8 --- a/pagure/hooks/files/pagure_hook.py +++ b/pagure/hooks/files/pagure_hook.py @@ -78,12 +78,15 @@ def relates_commit(commitid, issue, app_url=None): comment = ''' Commit [%s](%s) relates to this ticket''' % ( commitid[:8], url) + user = os.environ.get( + 'GL_USER', pagure.lib.git.get_author_email(commitid, abspath)) + try: pagure.lib.add_issue_comment( pagure.SESSION, issue=issue, comment=comment, - user=pagure.lib.git.get_author_email(commitid, abspath), + user=user, ticketfolder=pagure.APP.config['TICKETS_FOLDER'], ) pagure.SESSION.commit() @@ -110,13 +113,16 @@ def fixes_relation(commitid, relation, app_url=None): comment = ''' Commit [%s](%s) fixes this %s''' % ( commitid[:8], url, relation.isa) + user = os.environ.get( + 'GL_USER', pagure.lib.git.get_author_email(commitid, abspath)) + try: if relation.isa == 'issue': pagure.lib.add_issue_comment( pagure.SESSION, issue=relation, comment=comment, - user=pagure.lib.git.get_author_email(commitid, abspath), + user=user, ticketfolder=pagure.APP.config['TICKETS_FOLDER'], ) elif relation.isa == 'pull-request': @@ -128,7 +134,7 @@ def fixes_relation(commitid, relation, app_url=None): filename=None, row=None, comment=comment, - user=pagure.lib.git.get_author_email(commitid, abspath), + user=user, requestfolder=pagure.APP.config['REQUESTS_FOLDER'], ) pagure.SESSION.commit() @@ -144,14 +150,14 @@ def fixes_relation(commitid, relation, app_url=None): pagure.SESSION, relation, ticketfolder=pagure.APP.config['TICKETS_FOLDER'], - user=pagure.lib.git.get_author_email(commitid, abspath), + user=user, status='Closed', close_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_author_email(commitid, abspath), + user=user, merged=True) pagure.SESSION.commit() except pagure.exceptions.PagureException as err: From 9404ddcc0793a9c123fed96e8e293315ccd22e95 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 23 2017 11:56:24 +0000 Subject: [PATCH 2/2] Add a small debugging statement Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/files/pagure_hook.py b/pagure/hooks/files/pagure_hook.py old mode 100644 new mode 100755 index fbad2a8..020a9d5 --- a/pagure/hooks/files/pagure_hook.py +++ b/pagure/hooks/files/pagure_hook.py @@ -203,6 +203,7 @@ def run_as_post_receive_hook(): pagure.lib.git.get_revs_between(oldrev, newrev, abspath, refname)) if pagure.APP.config.get('HOOK_DEBUG', False): + print('ns :', pagure.lib.git.get_repo_namespace(abspath)) print('repo:', pagure.lib.git.get_repo_name(abspath)) print('user:', pagure.lib.git.get_username(abspath))