#4441 Send a notification upon editing the initial comment of a PR
Merged 2 years ago by pingou. Opened 2 years ago by pingou.

file modified
+12
@@ -491,6 +491,18 @@ 

          request.title = form.title.data.strip()

          request.initial_comment = form.initial_comment.data.strip()

          flask.g.session.add(request)

+         if not request.private and not request.project.private:

+             pagure.lib.notify.log(

+                 request.project,

+                 topic="pull-request.initial_comment.edited",

+                 msg={

+                     "pullrequest": request.to_json(

+                         public=True, with_comments=False

+                     ),

+                     "project": request.project.to_json(public=True),

+                     "agent": flask.g.fas_user.username,

+                 },

+             )

          try:

              # Link the PR to issue(s) if there is such link

              pagure.lib.query.link_pr_to_issue_on_description(

file modified
+89 -6
@@ -28,6 +28,9 @@ 

  _log = logging.getLogger(__name__)

  

  

+ FEDMSG_INIT = False

+ 

+ 

  def send_fedmsg_notifications(project, topic, msg):

      """ If the user or admin asked for fedmsg notifications on commit, this will

      do it.
@@ -43,13 +46,16 @@ 

      if always_fedmsg or (project.fedmsg_hook and project.fedmsg_hook.active):

          if _config.get("FEDMSG_NOTIFICATIONS", True):

              try:

+                 global FEDMSG_INIT

                  print("  - to fedmsg")

                  import fedmsg

  

                  config = fedmsg.config.load_config([], None)

                  config["active"] = True

                  config["endpoints"]["relay_inbound"] = config["relay_inbound"]

-                 fedmsg.init(name="relay_inbound", **config)

+                 if not FEDMSG_INIT:

+                     fedmsg.init(name="relay_inbound", **config)

+                     FEDMSG_INIT = True

  

                  pagure.lib.notify.fedmsg_publish(topic=topic, msg=msg)

              except Exception:
@@ -116,6 +122,42 @@ 

              )

  

  

+ def send_action_notification(

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

+ ):

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

+     """

+     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)

+     if author:

+         author = author.to_json(public=True)

+     else:

+         author = name

+ 

+     topic = "git.%s.%s" % (subject, action)

+     msg = dict(

+         authors=[author],

+         agent=user,

+         repo=project.to_json(public=True)

+         if not isinstance(project, six.string_types)

+         else project,

+     )

+     if subject == "branch":

+         msg["branch"] = refname

+     elif subject == "tag":

+         msg["tag"] = refname

+ 

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

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

+ 

+     if not project.private:

+         send_fedmsg_notifications(project, topic, msg)

+         send_stomp_notifications(project, topic, msg)

+         send_mqtt_notifications(project, topic, msg)

+         send_webhook_notifications(project, topic, msg)

+ 

+ 

  def send_notifications(session, project, repodir, user, refname, revs, forced):

      """ Send out-going notifications about the commits that have just been

      pushed.
@@ -271,13 +313,54 @@ 

  

              forced = False

              if set(newrev) == set(["0"]):

-                 print(

-                     "Deleting a reference/branch, so we won't run the "

-                     "pagure hook"

-                 )

-                 return

+                 if refname.startswith("refs/tags"):

+                     refname = refname.replace("refs/tags/", "")

+                     send_action_notification(

+                         session,

+                         "tag",

+                         "deletion",

+                         project,

+                         repodir,

+                         username,

+                         refname,

+                         oldrev,

+                     )

+                     print("Deleting a tag, so we won't run the " "pagure hook")

+                 elif refname.startswith("refs/heads/"):

+                     refname = refname.replace("refs/heads/", "")

+                     send_action_notification(

+                         session,

+                         "branch",

+                         "deletion",

+                         project,

+                         repodir,

+                         username,

+                         refname,

+                         oldrev,

+                     )

+                     print(

+                         "Deleting a branch, so we won't run the " "pagure hook"

+                     )

+                 else:

+                     print(

+                         "Deleting %s, so we wont run the pagure hook nor "

+                         "send notifications"

+                     )

+                 continue

              elif set(oldrev) == set(["0"]):

                  oldrev = "^%s" % oldrev

+                 if refname.startswith("refs/tags"):

+                     refname = refname.replace("refs/tags/", "")

+                     send_action_notification(

+                         session,

+                         "tag",

+                         "creation",

+                         project,

+                         repodir,

+                         username,

+                         refname,

+                         newrev,

+                     )

              elif pagure.lib.git.is_forced_push(oldrev, newrev, repodir):

                  forced = True

                  base = pagure.lib.git.get_base_revision(

file modified
+12
@@ -538,6 +538,18 @@ 

          request.title = form.title.data.strip()

          request.initial_comment = form.initial_comment.data.strip()

          flask.g.session.add(request)

+         if not request.private and not request.project.private:

+             pagure.lib.notify.log(

+                 request.project,

+                 topic="pull-request.initial_comment.edited",

+                 msg={

+                     "pullrequest": request.to_json(

+                         public=True, with_comments=False

+                     ),

+                     "project": request.project.to_json(public=True),

+                     "agent": flask.g.fas_user.username,

+                 },

+             )

          try:

              # Link the PR to issue(s) if there is such link

              pagure.lib.query.link_pr_to_issue_on_description(

We're sending notification when someone edits the initial comment
of a PR. This notification can now be using any of the bus we
support or simply web-hooks.

Fixes https://pagure.io/pagure/issue/4398

Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr

rebased onto 053ab19

2 years ago

1 new commit added

  • Send notifications on tag creation and tag and branch deletion
2 years ago

Pull-Request has been merged by pingou

2 years ago