fedmsg_hook.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2015-2016 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. from __future__ import unicode_literals, absolute_import
  8. import sqlalchemy as sa
  9. import wtforms
  10. try:
  11. from flask_wtf import FlaskForm
  12. except ImportError:
  13. from flask_wtf import Form as FlaskForm
  14. from sqlalchemy.orm import relation
  15. from sqlalchemy.orm import backref
  16. from pagure.hooks import BaseHook, BaseRunner
  17. from pagure.lib.model import BASE, Project
  18. class FedmsgTable(BASE):
  19. """Stores information about the fedmsg hook deployed on a project.
  20. Table -- hook_fedmsg
  21. """
  22. __tablename__ = "hook_fedmsg"
  23. id = sa.Column(sa.Integer, primary_key=True)
  24. project_id = sa.Column(
  25. sa.Integer,
  26. sa.ForeignKey("projects.id", onupdate="CASCADE", ondelete="CASCADE"),
  27. nullable=False,
  28. unique=True,
  29. index=True,
  30. )
  31. active = sa.Column(sa.Boolean, nullable=False, default=False)
  32. project = relation(
  33. "Project",
  34. remote_side=[Project.id],
  35. backref=backref(
  36. "fedmsg_hook",
  37. cascade="delete, delete-orphan",
  38. single_parent=True,
  39. uselist=False,
  40. ),
  41. )
  42. class FedmsgRunner(BaseRunner):
  43. """Runner for the fedmsg hook, it does nothing as all the magic is
  44. part of the default hook/runner.
  45. """
  46. pass
  47. class FedmsgForm(FlaskForm):
  48. """ Form to configure the fedmsg hook. """
  49. active = wtforms.BooleanField("Active", [wtforms.validators.Optional()])
  50. DESCRIPTION = """
  51. This hook pushes commit notification to the fedmsg bus to be consumed by other
  52. applications.
  53. It is different from the fedmsg setting present in the project options block
  54. which publishes notifications about events happening in the project via
  55. pagure's (web) user interface, for example: new tickets, new comments, new
  56. pull-requests and so on.
  57. This hook on the other only acts on commits.
  58. """
  59. class Fedmsg(BaseHook):
  60. """ Fedmsg hooks. """
  61. name = "Fedmsg"
  62. description = DESCRIPTION
  63. form = FedmsgForm
  64. db_object = FedmsgTable
  65. backref = "fedmsg_hook"
  66. form_fields = ["active"]
  67. runner = FedmsgRunner
  68. @classmethod
  69. def install(cls, project, dbobj):
  70. """Method called to install the hook for a project.
  71. :arg project: a ``pagure.model.Project`` object to which the hook
  72. should be installed
  73. This no longer does anything as the code has now been merged into
  74. the default hook. So we still need this for people to opt in/out of
  75. sending fedmsg notifications on commit push, but other than that
  76. this plugin doesn't do much anymore.
  77. """
  78. pass
  79. @classmethod
  80. def remove(cls, project):
  81. """Method called to remove the hook of a project.
  82. :arg project: a ``pagure.model.Project`` object to which the hook
  83. should be installed
  84. This no longer does anything as the code has now been merged into
  85. the default hook. So we still need this for people to opt in/out of
  86. sending fedmsg notifications on commit push, but other than that
  87. this plugin doesn't do much anymore.
  88. """
  89. pass