#4609 Add revision along with tag/branch creation/deletion
Merged 4 years ago by pingou. Opened 4 years ago by fbo.
fbo/pagure event-tag-newrev  into  master

file modified
+3 -1
@@ -125,7 +125,7 @@ 

  def send_action_notification(

      session, subject, action, project, repodir, user, refname, rev

  ):

-     """ Send out-going notifications about the branch that was just deleted.

+     """ Send out-going notifications about the branch/tag.

      """

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

      name = pagure.lib.git.get_author(rev, repodir)
@@ -145,8 +145,10 @@ 

      )

      if subject == "branch":

          msg["branch"] = refname

+         msg["rev"] = rev

      elif subject == "tag":

          msg["tag"] = refname

+         msg["rev"] = rev

  

      # Send blink notification to any 3rd party plugins, if there are any

      pagure.lib.notify.blinker_publish(topic, msg)

@@ -0,0 +1,83 @@ 

+ # -*- coding: utf-8 -*-

+ 

+ """

+  (c) 2019 - Copyright Red Hat Inc

+ 

+  Authors:

+    Fabien Boucher <fboucher@redhat.com>

+ 

+ """

+ 

+ import unittest

+ import sys

+ import os

+ 

+ sys.path.insert(

+     0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")

+ )

+ 

+ import mock

+ import pygit2

+ 

+ import pagure.hooks.default

+ import tests

+ 

+ 

+ class PagureHooksDefault(tests.SimplePagureTest):

+     """ Tests for pagure.hooks.default """

+ 

+     def setUp(self):

+         """ Set up the environnment, ran before every tests. """

+         super(PagureHooksDefault, self).setUp()

+         tests.create_projects(self.session)

+         self.projects = tests.create_projects_git(

+             os.path.join(self.path, "repos"), bare=True

+         )

+         self.folder = os.path.join(self.path, "repos", "test.git")

+ 

+     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

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

+         return project, sha

+ 

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

+     def test_send_action_notification(self, fedmsg):

+         project, sha = self.init_test_repo()

+         pagure.hooks.default.send_action_notification(

+             self.session,

+             "tag",

+             "bar",

+             project,

+             self.folder,

+             "pingou",

+             "master",

+             sha,

+         )

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

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

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

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

+ 

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

+     def test_send_notifications(self, fedmsg):

+         project, sha = self.init_test_repo()

+         pagure.hooks.default.send_notifications(

+             self.session,

+             project,

+             self.folder,

+             "pingou",

+             "master",

+             [sha],

+             False,

+         )

+         (_, 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)

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

+ 

+ 

+ if __name__ == "__main__":

+     unittest.main(verbosity=2)

The git.tag.creation event does not propagate the newrev
making it difficult to be interpreted by other tools like
Zuul. This patch adds the rev info to that notification payload
but also to branch events.

The test suite is failing due to #4611 . #4612 should temporary fix it.

rebased onto ff73e84aad01a7abdea03ca52a3c7bf996d60962

4 years ago

Should we add some tests to this?

rebased onto e6748195062ee4f1876aeb13363ef77517c382dd

4 years ago

Hi, I'll be happy to add tests. Could you give me some guidance where and how to add notifications tests ?

Thanks a lot !

rebased onto 92c0a5334f5bfc7ab38315fbbf5e4a78730ccefc

4 years ago

rebased onto 3e6add191816df3d42b92a58250fd9221c387995

4 years ago

Cool, thanks! :)

Let's wait for jenkins and get this in :)

rebased onto 5fe4ac73396674a6516554bf65a6ed2ed2d686d3

4 years ago

pretty please pagure-ci rebuild

4 years ago

Try with python3 -m black -l79 tests/test_pagure_send_notification.py

1 new commit added

  • black fix
4 years ago

rebased onto 9e5f51c

4 years ago

Pull-Request has been merged by pingou

4 years ago