#237 Replace pdc calls in distgit_bugzilla_sync
Closed 2 years ago by humaton. Opened 2 years ago by humaton.
fedora-infra/ humaton/toddlers distgit_bz_sync  into  main

@@ -24,6 +24,8 @@ 

          "pdc_config": {

              "server": "https://pdc.fedoraproject.org/rest_api/v1",

          },

+         "pagure_api_key": "some api key",

+         "pagure_url": "https://src.fedoraproject.org",

          # distgit_bugzilla_sync config values

          "ignorable_accounts": [],

          "fasjson": False,
@@ -95,6 +97,8 @@ 

      )

      @patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")

      @patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")

+     @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")

+     @patch("toddlers.utils.bodhi.set_bodhi")

      @patch("toml.load")

      def test_process_dry_run_edit_project(

          self,
@@ -370,6 +374,8 @@ 

      )

      @patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")

      @patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")

+     @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")

+     @patch("toddlers.utils.bodhi.set_bodhi")

      @patch("toml.load")

      def test_process_dry_run_specific_project(

          self,
@@ -493,6 +499,8 @@ 

      @patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")

      @patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")

      @patch("toddlers.plugins.distgit_bugzilla_sync.notify")

+     @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")

+     @patch("toddlers.utils.bodhi.set_bodhi")

      @patch("toml.load")

      def test_process_report_protocol_error(

          self,
@@ -606,6 +614,8 @@ 

      @patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")

      @patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")

      @patch("toddlers.plugins.distgit_bugzilla_sync.notify")

+     @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")

+     @patch("toddlers.utils.bodhi.set_bodhi")

      @patch("toml.load")

      def test_process_report_client_error(

          self,
@@ -739,6 +749,8 @@ 

      @patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")

      @patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")

      @patch("toddlers.plugins.distgit_bugzilla_sync.notify")

+     @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")

+     @patch("toddlers.utils.bodhi.set_bodhi")

      @patch("toml.load")

      def test_process_report_missing_mails(

          self,
@@ -835,6 +847,8 @@ 

      )

      @patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")

      @patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")

+     @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")

+     @patch("toddlers.utils.bodhi.set_bodhi")

      @patch("toml.load")

      def test_process_dry_run_verbose(

          self,
@@ -932,6 +946,8 @@ 

      )

      @patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")

      @patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")

+     @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")

+     @patch("toddlers.utils.bodhi.set_bodhi")

      @patch("toml.load")

      def test_process_missing_namespace(

          self,
@@ -984,6 +1000,8 @@ 

      )

      @patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")

      @patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")

+     @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")

+     @patch("toddlers.utils.bodhi.set_bodhi")

      @patch("toml.load")

      def test_process_missing_pdc_branches(

          self,
@@ -1041,6 +1059,8 @@ 

      @patch(

          "toddlers.plugins.distgit_bugzilla_sync.PackageSummaries.get_package_summaries"

      )

+     @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")

+     @patch("toddlers.utils.bodhi.set_bodhi")

      @patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")

      @patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")

      @patch("toml.load")
@@ -1157,6 +1177,8 @@ 

      @patch(

          "toddlers.plugins.distgit_bugzilla_sync.PackageSummaries.get_package_summaries"

      )

+     @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")

+     @patch("toddlers.utils.bodhi.set_bodhi")

      @patch("toddlers.plugins.distgit_bugzilla_sync.fedora_account")

      @patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")

      @patch("toml.load")
@@ -1165,6 +1187,10 @@ 

          mock_toml,

          mock_bugzilla,

          mock_fas,

+         mock_dist_git,

+         mock_set_pagure,

+         mock_set_bodhi,

+         mock_bodhi,

          mock_summaries,

          config,

          toddler,
@@ -1179,6 +1205,23 @@ 

          # Mock package summaries response

          mock_summaries.return_value = {"foo": "Summary"}

  

+         mock_dist_git = MagicMock()

+         mock_dist_git.get_retired_packages.side_effect = (

+             ["package01", "package02"],

+             ["package01", "package03"],

+         )

+         mock_dist_git.get_branches.return_value = ["f39", "f40"]

+         mock_dist_git.get_project.return_value = {

+             "user": {"name": "Gavriel Loken"},

+             "access_users": {"admin": ["Fulgrim", "orphan"]},

+             "access_groups": {"admin": ["Adeptus Astartes"]},

+         }

+         mock_set_pagure.return_value = mock_dist_git

+         mock_bodhi = MagicMock()

+         mock_bodhi.get_active_branches.return_value = ["f39", "f40"]

+         mock_set_bodhi.return_value = mock_bodhi

+ 

+ 

          # Mock pagure responses

          toddler.requests_session = Mock()

          response_pagure_poc = MagicMock()
@@ -1252,6 +1295,7 @@ 

      @patch("toddlers.plugins.distgit_bugzilla_sync.bugzilla_system")

      @patch("toddlers.plugins.distgit_bugzilla_sync.notify")

      @patch("toml.load")

+     @patch("toddlers.plugins.distgit_bugzilla_sync.pagure.set_pagure")

      def test_process_notify_user_cache_exists(

          self,

          mock_toml,

@@ -25,7 +25,7 @@ 

      tqdm = None

  

  from ..base import ToddlerBase

- from ..utils import bugzilla_system, fedora_account, notify

+ from ..utils import bugzilla_system, fedora_account, notify, pagure, bodhi

  from ..utils.package_summaries import PackageSummaries

  from ..utils.requests import make_session

  
@@ -38,7 +38,6 @@ 

      """

  

      name = "distgit_bugzilla_sync"

- 

      amqp_topics = ["org.fedoraproject.*.toddlers.trigger.distgit_bugzilla_sync"]

  

      def __init__(self):
@@ -54,6 +53,9 @@ 

          # Mapping of product to branch regex, will be filled from configuration

          self.product_to_branch_regex = {}

  

+         self.dist_git = None

+         self.bodhi = None

+ 

      def accepts_topic(self, topic: str) -> bool:

          """Returns a boolean whether this toddler is interested in messages

          from this specific topic.
@@ -86,6 +88,15 @@ 

              where no change was done

          :arg dry_run: Don't do any change in bugzilla

          """

+         self.dist_git = pagure.set_pagure(

+             {

+                 "pagure_url": config.get("dist_git_url"),

+                 "pagure_api_key": config.get("dist_git_token"),

+             }

+         )

+ 

+         self.bodhi = bodhi.set_bodhi(config)

+ 

          try:

              email_overrides = toml.load(config["email_overrides_file"])

          except Exception:
@@ -369,9 +380,6 @@ 

          """

          _log.debug("Querying PDC for EOL information.")

  

-         pdc_branches = self.requests_session.get(

-             pdc_url + "extras/active_branches.json"

-         ).json()

          for idx, project in enumerate(self.pagure_projects):

              # Summary

              summary = None
@@ -408,9 +416,9 @@ 

                  continue

  

              pdc_type = pdc_types[project["namespace"]]

-             project["branches"] = pdc_branches.get(pdc_type, {}).get(

-                 project["name"], []

-             )

+ 

+             project["branches"] = self.dist_git.get_branches(project["namespace"],project["name"])

+             

              if not project["branches"]:

                  self.errors["PDC"].append(

                      f"No PDC branch found for {project['namespace']}/{project['name']}"
@@ -481,15 +489,13 @@ 

          """

          branches = project["branches"]

          branch_regex = self.product_to_branch_regex.get(product)

-         for branch, active in branches:

-             if branch_regex:

-                 if branch_regex.match(branch) and active:

-                     return False

+         active_branches = bodhi.get_active_branches()

+         for branch in branches:

+             if branch_regex.match(branch) and branch in active_branches:

+                 if pagure.is_retired_on_branch(project["name"], branch):

+                     return True

              else:

-                 if active:

-                     return False

-         # No active branches means it is retired.

-         return True

+                 return False

  

  

  # In case this code needs to be run manually for some projects

file modified
+19
@@ -1171,6 +1171,25 @@ 

                  )

              )

  

+     def is_retired_on_branch(self, package, branch) -> bool:

+         """

+         Check if the given package is retired on branch

+ 

+         Params:

+           package: Package name

+           branch: Branch name

+ 

+         Raises:

+           `toddlers.utils.exceptions.PagureError``: When orphaning the package fails.

+         """

+ 

+         retired_on_branch = self.get_retired_packages(branch)

+ 

+         if package in retired_on_branch:

+             return True

+         else:

+             return False

+ 

      def orphan_package(

          self, namespace: str, package: str, reason: str, info: str

      ) -> None:

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging pagure.io/fedora-infra/toddlers for 237,b5cac73

Pull-Request has been closed by humaton

2 years ago