From 409376531f827ef865624277f0d347db9b38b578 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 10 2018 15:15:16 +0000 Subject: Include the avatar in the author's list on the project's stats Fixes https://pagure.io/pagure/issue/3717 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/query.py b/pagure/lib/query.py index fb01c1d..8a5c2b2 100644 --- a/pagure/lib/query.py +++ b/pagure/lib/query.py @@ -3608,6 +3608,8 @@ def avatar_url_from_email(email, size=64, default="retro", dns=False): """ Our own implementation since fas doesn't support this nicely yet. """ + if not email: + return if dns: # pragma: no cover # This makes an extra DNS SRV query, which can slow down our webapps. # It is necessary for libravatar federation, though. diff --git a/pagure/lib/tasks.py b/pagure/lib/tasks.py index 7a155a8..4b764a6 100644 --- a/pagure/lib/tasks.py +++ b/pagure/lib/tasks.py @@ -968,12 +968,16 @@ def commits_author_stats(self, session, repopath): # Generate a list of contributors ordered by how many commits they # authored. The list consists of tuples with number of commits and people - # with that number of commits. Each contributor is represented by a name - # and e-mail address. + # with that number of commits. Each contributor is represented by a tuple + # of name, e-mail address and avatar url. out_stats = collections.defaultdict(list) for authors, val in stats.items(): authors_email.add(authors[1]) - out_stats[val].append(authors) + out_authors = list(authors) + out_authors.append( + pagure.lib.query.avatar_url_from_email(authors[1], size=32) + ) + out_stats[val].append(tuple(out_authors)) out_list = [ (key, out_stats[key]) for key in sorted(out_stats, reverse=True) ] diff --git a/pagure/static/issues_stats.js b/pagure/static/issues_stats.js index 6cdd497..8b861f1 100644 --- a/pagure/static/issues_stats.js +++ b/pagure/static/issues_stats.js @@ -81,6 +81,7 @@ function show_commits_authors(data) { entry = data.results[1][key][1][entry]; html += ' ' + + ' ' + entry[0] + '
' + cnt + ' commits
' + '
\n'; diff --git a/tests/test_pagure_flask_internal.py b/tests/test_pagure_flask_internal.py index b2cd203..529d1a5 100644 --- a/tests/test_pagure_flask_internal.py +++ b/tests/test_pagure_flask_internal.py @@ -2146,15 +2146,37 @@ class PagureFlaskInternaltests(tests.Modeltests): js_data2 = json.loads(output.get_data(as_text=True)) self.assertTrue(js_data2['results'][3] > 1509110062) js_data2['results'][3] = 1509110062 - self.assertDictEqual( - js_data2, - {'results': [ - 2, - [[2, [['Alice Author', 'alice@authors.tld']]]], - 1, - 1509110062 + self.assertTrue( + js_data2 in [ + { + 'results': [ + 2, + [[2, [[ + 'Alice Author', + 'alice@authors.tld', + 'https://seccdn.libravatar.org/avatar/' + '96c52c78570ffc4cfefcdadf5f8e77aeebcb11e07225df11bbf2fce381cdb8bd' + '?s=32&d=retro' + ]]]], + 1, + 1509110062 + ] + }, + { + 'results': [ + 2, + [[2, [[ + 'Alice Author', + 'alice@authors.tld', + 'https://seccdn.libravatar.org/avatar/' + '96c52c78570ffc4cfefcdadf5f8e77aeebcb11e07225df11bbf2fce381cdb8bd' + '?d=retro&s=32' + ]]]], + 1, + 1509110062 + ] + } ] - } ) def test_get_stats_commits_trend_no_token(self): diff --git a/tests/test_tasks.py b/tests/test_tasks.py index 17e9071..a4b1335 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -64,7 +64,23 @@ class TestCommitsAuthorStats(unittest.TestCase): self.assertEqual(num_commits, 1) self.assertEqual(num_authors, 1) self.assertEqual(last_time, '2018-01-01 00:00') - self.assertEqual(authors, [(1, [('Alice', 'alice@example.com')])]) + self.assertIn( + authors, + [ + [(1, [( + 'Alice', 'alice@example.com', + 'https://seccdn.libravatar.org/avatar/' + 'ff8d9819fc0e12bf0d24892e45987e249a28dce836a85cad60e28eaaa8c6d976' + '?s=32&d=retro' + )])], + [(1, [( + 'Alice', 'alice@example.com', + 'https://seccdn.libravatar.org/avatar/' + 'ff8d9819fc0e12bf0d24892e45987e249a28dce836a85cad60e28eaaa8c6d976' + '?d=retro&s=32' + )])] + ] + ) def test_rename_user_and_merge(self): self.commits = [ @@ -81,7 +97,23 @@ class TestCommitsAuthorStats(unittest.TestCase): self.assertEqual(num_commits, 2) self.assertEqual(num_authors, 1) self.assertEqual(last_time, '2018-01-01 00:00') - self.assertEqual(authors, [(2, [('Alice', 'alice@example.com')])]) + self.assertIn( + authors, + [ + [(2, [( + 'Alice', 'alice@example.com', + 'https://seccdn.libravatar.org/avatar/' + 'ff8d9819fc0e12bf0d24892e45987e249a28dce836a85cad60e28eaaa8c6d976' + '?s=32&d=retro' + )])], + [(2, [( + 'Alice', 'alice@example.com', + 'https://seccdn.libravatar.org/avatar/' + 'ff8d9819fc0e12bf0d24892e45987e249a28dce836a85cad60e28eaaa8c6d976' + '?d=retro&s=32' + )])] + ] + ) def test_preserve_unknown_author(self): self.commits = [ @@ -95,7 +127,23 @@ class TestCommitsAuthorStats(unittest.TestCase): self.assertEqual(num_commits, 1) self.assertEqual(num_authors, 1) self.assertEqual(last_time, '2018-01-01 00:00') - self.assertEqual(authors, [(1, [('Alice', 'alice@example.com')])]) + self.assertIn( + authors, + [ + [(1, [( + 'Alice', 'alice@example.com', + 'https://seccdn.libravatar.org/avatar/' + 'ff8d9819fc0e12bf0d24892e45987e249a28dce836a85cad60e28eaaa8c6d976' + '?s=32&d=retro' + )])], + [(1, [( + 'Alice', 'alice@example.com', + 'https://seccdn.libravatar.org/avatar/' + 'ff8d9819fc0e12bf0d24892e45987e249a28dce836a85cad60e28eaaa8c6d976' + '?d=retro&s=32' + )])] + ] + ) def test_handle_empty_email(self): self.commits = [ @@ -112,8 +160,8 @@ class TestCommitsAuthorStats(unittest.TestCase): self.assertEqual(num_commits, 3) self.assertEqual(num_authors, 2) self.assertEqual(last_time, '2018-01-01 00:00') - self.assertEqual(authors, [(2, [('Alice', None)]), - (1, [('Bob', '')])]) + self.assertEqual(authors, [(2, [('Alice', None, None)]), + (1, [('Bob', '', None)])]) class TestGitolitePostCompileOnly(object):