#5137 Add total_commits per author to git.receive notification
Opened 2 years ago by oturpe. Modified 2 years ago

file modified
+1
@@ -20,6 +20,7 @@ 

  *.conf

  .coverage

  *~

+ __pycache__/

  

  # Ignore files generated by run_ci_tests

  pep8.out

file modified
+5 -3
@@ -10,6 +10,7 @@ 

  

  from __future__ import unicode_literals, print_function, absolute_import

  

+ from collections import defaultdict

  import logging

  

  import pygit2
@@ -170,15 +171,15 @@ 

      pushed.

      """

  

-     auths = set()

+     auths_counts = defaultdict(int)

      for rev in revs:

          email = pagure.lib.git.get_author_email(rev, repodir)

          name = pagure.lib.git.get_author(rev, repodir)

          author = pagure.lib.query.search_user(session, email=email) or name

-         auths.add(author)

+         auths_counts[author] += 1

  

      authors = []

-     for author in auths:

+     for author in auths_counts:

          if not isinstance(author, six.string_types):

              author = author.to_json(public=True)

          else:
@@ -186,6 +187,7 @@ 

                  "fullname": author,

                  "name": None,

                  "url_path": None,

+                 "total_commits": auths_counts[author]

              }

          authors.append(author)

  

@@ -38,13 +38,14 @@ 

      def init_test_repo(self):

          tests.add_content_git_repo(self.projects[0])

          repo = pygit2.Repository(self.projects[0])

-         sha = repo.references["refs/heads/master"].peel().hex

+         sha = repo.revparse_single("HEAD").hex

+         sha_parent = repo.revparse_single("HEAD^").hex

          project = pagure.lib.query.get_authorized_project(self.session, "test")

-         return project, sha

+         return project, sha, sha_parent

  

      @mock.patch("pagure.hooks.default.send_fedmsg_notifications")

      def test_send_action_notification(self, fedmsg):

-         project, sha = self.init_test_repo()

+         project, sha, _ = self.init_test_repo()

          pagure.hooks.default.send_action_notification(

              self.session,

              "tag",
@@ -63,7 +64,7 @@ 

      @mock.patch("pagure.hooks.default.send_fedmsg_notifications")

      def test_send_notifications(self, fedmsg):

          oldrev = "9e5f51c951c6cab20fe81419320ed740533e2f2f"

-         project, sha = self.init_test_repo()

+         project, sha, _ = self.init_test_repo()

          pagure.hooks.default.send_notifications(

              self.session,

              project,
@@ -80,6 +81,31 @@ 

          self.assertEqual(args[2]["start_commit"], sha)

          self.assertEqual(args[2]["forced"], False)

          self.assertEqual(args[2]["old_commit"], oldrev)

+         self.assertEqual(args[2]["authors"][0]["fullname"], "Alice Author")

+         self.assertEqual(args[2]["authors"][0]["total_commits"], 1)

+ 

+     @mock.patch("pagure.hooks.default.send_fedmsg_notifications")

+     def test_send_notifications_two_commits(self, fedmsg):

+         project, sha, sha_parent = self.init_test_repo()

+         pagure.hooks.default.send_notifications(

+             self.session,

+             project,

+             self.folder,

+             "pingou",

+             "master",

+             [sha, sha_parent],

+             False,

+             None,

+         )

+         (_, args, kwargs) = fedmsg.mock_calls[0]

+         self.assertEqual(args[1], "git.receive")

+         self.assertEqual(args[2]["repo"]["name"], "test")

+         self.assertEqual(args[2]["start_commit"], sha_parent)

+         self.assertEqual(args[2]["end_commit"], sha)

+         self.assertEqual(args[2]["forced"], False)

+         self.assertEqual(args[2]["old_commit"], None)

+         self.assertEqual(args[2]["authors"][0]["fullname"], "Alice Author")

+         self.assertEqual(args[2]["authors"][0]["total_commits"], 2)

  

  

  if __name__ == "__main__":

Currently, Fedora Badge "Long Life to Pagure" does not function correctly. The issues it has are described at https://pagure.io/fedora-badges/pull-request/806

One of the issues can be solved by simply making Pagure's git.receive notification list commit count per author. Exactly that is added here.

The notification schema is only changed by adding a new field, which should be non breaking.

Should also the USER schema at pagure-messages be updates? Which one should be done first?

Should also the [USER schema at pagure-messages][schema] be updates? Which one should be done first?

Yes the schema should be updated, we can do the change in the payload first
since we're adding to it, so it won't break the existing schemas

2 new commits added

  • Add total_commits per author to git.receive notification
  • Add __pycache__ to .gitignore
2 years ago

Should also the [USER schema at pagure-messages][schema] be updates? Which one should be done first?

Yes the schema should be updated, we can do the change in the payload first
since we're adding to it, so it won't break the existing schemas

Schema update: pagure-messages pull request 6

rebased onto f9e8ce7d51fb69ec91943106416dfddaa283953a

2 years ago

pretty please pagure-ci rebuild

2 years ago

rebased onto aaa739064b5b19e1552fb739bee9ec3f1453cf2a

2 years ago

rebased onto b608113

2 years ago