From be5513fe77903b8298098f7f3c0ba3d40a77856f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 08 2016 22:31:07 +0000 Subject: [PATCH 1/3] Send one fedmsg message per push instead of per commit --- diff --git a/pagure/hooks/files/fedmsg_hook.py b/pagure/hooks/files/fedmsg_hook.py index 57e149b..87cda19 100755 --- a/pagure/hooks/files/fedmsg_hook.py +++ b/pagure/hooks/files/fedmsg_hook.py @@ -123,7 +123,7 @@ for line in sys.stdin.readlines(): commits = map(_build_commit, revs) - print "* Publishing information for %i commits" % len(commits) + final_commits = [] for commit in reversed(commits): if commit is None: continue @@ -139,9 +139,17 @@ for line in sys.stdin.readlines(): else: commit['seen'] = False seen.append(commit['rev']) + final_commits.append(commit) + if final_commits: + print "* Publishing information for %i commits" % len(commits) pagure.lib.notify.log( project=project, topic="git.receive", - msg=dict(commit=commit), + msg=dict( + commits=final_commits, + branch=refname, + forced=forced, + agent=username, + ), ) From c84343bfe84a46981ff4c8a2d7d692286c0465b6 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 09 2016 15:20:41 +0000 Subject: [PATCH 2/3] Put the repo information at the top of the fedmsg message to reduce duplication --- diff --git a/pagure/hooks/files/fedmsg_hook.py b/pagure/hooks/files/fedmsg_hook.py index 87cda19..2b7012a 100755 --- a/pagure/hooks/files/fedmsg_hook.py +++ b/pagure/hooks/files/fedmsg_hook.py @@ -115,9 +115,6 @@ for line in sys.stdin.readlines(): rev=unicode(rev), path=abspath, username=username, - repo=project.to_json(public=True) - if not isinstance(project, basestring) else project, - branch=refname, agent=os.getlogin(), ) @@ -151,5 +148,7 @@ for line in sys.stdin.readlines(): branch=refname, forced=forced, agent=username, + repo=project.to_json(public=True) + if not isinstance(project, basestring) else project, ), ) From 95c17c1b9e9626b523e98f8401d22e3740f6eb07 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 09 2016 15:58:57 +0000 Subject: [PATCH 3/3] Drop the stats from the fedmsg message upon commit but add the start/stop commit --- diff --git a/pagure/hooks/files/fedmsg_hook.py b/pagure/hooks/files/fedmsg_hook.py index 2b7012a..043bc6c 100755 --- a/pagure/hooks/files/fedmsg_hook.py +++ b/pagure/hooks/files/fedmsg_hook.py @@ -28,43 +28,6 @@ config['endpoints']['relay_inbound'] = config['relay_inbound'] fedmsg.init(name='relay_inbound', **config) -def build_stats(commit): - cmd = ['diff-tree', '--numstat', '%s' % (commit)] - output = pagure.lib.git.read_git_lines(cmd, abspath) - - files = {} - total = {} - for line in output[1:]: - additions, deletions, path = line.split('\t') - additions, deletions = additions.strip(), deletions.strip() - - try: - additions = int(additions) - except ValueError: - additions = 0 - - try: - deletions = int(deletions) - except ValueError: - deletions = 0 - - path = path.strip() - files[path] = { - 'additions': additions, - 'deletions': deletions, - 'lines': additions + deletions, - } - - total = defaultdict(int) - for name, stats in files.items(): - total['additions'] += stats['additions'] - total['deletions'] += stats['deletions'] - total['lines'] += stats['lines'] - total['files'] += 1 - - return files, total - - seen = [] # Read in all the rev information git-receive-pack hands us. @@ -93,58 +56,16 @@ for line in sys.stdin.readlines(): if not project: project = project_name - def _build_commit(rev): - files, total = build_stats(rev) - - summary = pagure.lib.git.read_git_lines( - ['log', '-1', rev, "--pretty='%s'"], - abspath)[0].replace("'", '') - message = pagure.lib.git.read_git_lines( - ['log', '-1', rev, "--pretty='%B'"], - abspath)[0].replace("'", '') - - return dict( - name=pagure.lib.git.get_pusher(rev, abspath), - email=pagure.lib.git.get_pusher_email(rev, abspath), - summary=summary, - message=message, - stats=dict( - files=files, - total=total, - ), - rev=unicode(rev), - path=abspath, - username=username, - agent=os.getlogin(), - ) - - commits = map(_build_commit, revs) - - final_commits = [] - for commit in reversed(commits): - if commit is None: - continue - - # Keep track of whether or not we have already published this commit - # on another branch or not. It is conceivable that someone could - # make a commit to a number of branches, and push them all at the - # same time. - # Make a note in the fedmsg payload so we can try to reduce spam at - # a later stage. - if commit['rev'] in seen: - commit['seen'] = True - else: - commit['seen'] = False - seen.append(commit['rev']) - final_commits.append(commit) - - if final_commits: - print "* Publishing information for %i commits" % len(commits) + if revs: + revs.reverse() + print "* Publishing information for %i commits" % len(revs) pagure.lib.notify.log( project=project, topic="git.receive", msg=dict( - commits=final_commits, + total_commits=len(revs), + start_commit=revs[0], + end_commit=revs[-1], branch=refname, forced=forced, agent=username,