feeds.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. """
  2. ForgeFed plugin for Pagure.
  3. Copyright (C) 2020-2021 zPlus <zplus@peers.community>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with this program; if not, see <https://www.gnu.org/licenses/>.
  14. SPDX-FileCopyrightText: 2020-2021 zPlus <zplus@peers.community>
  15. SPDX-License-Identifier: GPL-2.0-only
  16. """
  17. def create_tagref(repository, ref):
  18. """
  19. Feed to show when a new Tag has been created on a Git repository.
  20. """
  21. return {
  22. 'type': 'create_git_tag',
  23. 'repository': {
  24. 'name': repository['name'],
  25. 'id': repository['id']
  26. },
  27. 'ref': {
  28. 'name': ref['name'],
  29. 'id': ref['id']
  30. },
  31. }
  32. def follow(follower=None, followee=None):
  33. """
  34. Feed to show when a Follow request has been sent.
  35. :param follower: The actor that followed
  36. :type follower: dict
  37. :param followee: The actor being followed
  38. :type followee: dict
  39. """
  40. return {
  41. 'type': 'follow',
  42. 'follower': {
  43. 'name': follower['name'],
  44. 'id': follower['id']
  45. },
  46. 'followee': {
  47. 'name': followee['name'],
  48. 'id': followee['id']
  49. },
  50. }
  51. def accept_follow(follower=None, followee=None):
  52. """
  53. Feed to show when a Follow request has been accepted.
  54. :param follower: The actor that sent the Follow Activity
  55. :type follower: dict
  56. :param followee: The actor that Accepted the Follow Activity
  57. :type followee: dict
  58. """
  59. return {
  60. 'type': 'accept_follow',
  61. 'follower': {
  62. 'name': follower['name'],
  63. 'id': follower['id']
  64. },
  65. 'followee': {
  66. 'name': followee['name'],
  67. 'id': followee['id']
  68. },
  69. }
  70. def accept_ticket(tickettracker, ticket):
  71. """
  72. :param tickettracker: The TicketTracker that accepted the Ticket
  73. :type follower: dict
  74. :param followee: The Ticket
  75. :type followee: dict
  76. """
  77. return {
  78. 'type': 'accept_ticket',
  79. 'tickettracker': {
  80. 'name': tickettracker['name'],
  81. 'id': tickettracker['id']
  82. },
  83. 'ticket': {
  84. 'summary': ticket['summary'],
  85. 'id': ticket['id']
  86. },
  87. }
  88. def delete_ticket(actor, ticket):
  89. """
  90. :param tickettracker: The TicketTracker that accepted the Ticket
  91. :type follower: dict
  92. :param followee: The Ticket
  93. :type followee: dict
  94. """
  95. return {
  96. 'type': 'delete_ticket',
  97. 'actor': {
  98. 'name': actor.username,
  99. 'id': actor.uri
  100. },
  101. 'ticket': {
  102. 'id': ticket['id']
  103. },
  104. }
  105. def accept_mergerequest(mergerequest):
  106. """
  107. :param mergerequest: The mergerequest that was accepted
  108. :type follower: dict
  109. """
  110. return {
  111. 'type': 'accept_mergerequest',
  112. 'mergerequest': {
  113. 'summary': mergerequest['summary'],
  114. 'id': mergerequest['id']
  115. },
  116. }