#126 Add a mechanism to tell that a branch is equal to another one when querying PDC
Merged 4 years ago by pingou. Opened 4 years ago by pingou.

file modified
+10 -4
@@ -29,7 +29,12 @@ 

      os.environ["PAGURE_CONFIG"] = config

  

  import pagure.config

- from pagure_distgit.model import BASE, PagureAnitya, PagureBZOverride, PagureOrphanReason

+ from pagure_distgit.model import (

+     BASE,

+     PagureAnitya,

+     PagureBZOverride,

+     PagureOrphanReason,

+ )

  

  db_url = pagure.config.config.get("DB_URL")

  if db_url.startswith("postgres"):
@@ -38,9 +43,10 @@ 

      engine = create_engine(db_url, echo=True)

  

  BASE.metadata.create_all(

-     engine, tables=[

+     engine,

+     tables=[

          PagureAnitya.__table__,

          PagureBZOverride.__table__,

-         PagureOrphanReason.__table__

-     ]

+         PagureOrphanReason.__table__,

+     ],

  )

file modified
+13 -11
@@ -77,7 +77,7 @@ 

          self.pdc_url = pagure_config.get("PDC_URL")

  

      def is_supported_branch(self, project, refname):

-         """ Returns whether a specific branch is currently supported for Fedora

+         """Returns whether a specific branch is currently supported for Fedora

  

          This retrieves the information about EOL status from PDC, to prevent

          EOL branches being pushed to.
@@ -115,16 +115,16 @@ 

          return res[0]["active"]

  

      def info(self, msg):

-         """ Function to print information.

+         """Function to print information.

  

-         Is a function to help with the test suite. """

+         Is a function to help with the test suite."""

          _log.info(msg)

          print(msg)

  

      def debug(self, msg):

-         """ Function to print if in debug mode.

+         """Function to print if in debug mode.

  

-         Function to help in test. """

+         Function to help in test."""

          _log.debug(msg)

          if self.is_debug:

              self.info(msg)
@@ -141,9 +141,9 @@ 

          revfrom,

          revto,

          is_internal,

-         **info

+         **info,

      ):

-         """ Perform dynamic ACL checks.

+         """Perform dynamic ACL checks.

  

          For arguments, see GitAuthHelper.check_acl."""

  
@@ -181,9 +181,7 @@ 

          usergroups = set(user.groups)

  

          # Determine whether the user is a committer/collaborator, ie: may commit

-         may_commit = is_repo_collaborator(

-             project, refname, username, session

-         )

+         may_commit = is_repo_collaborator(project, refname, username, session)

  

          # Determine whether the user is a SIG member

          user_sigs = self.supported_sigs & usergroups
@@ -243,7 +241,11 @@ 

  

              # For Fedora, allow supported branches, these are the active

              # branches in PDC

-             is_supported = self.is_supported_branch(project, refname)

+             pdc_ref = refname

+             branch_overrides = pagure_config.get("PDC_BRANCH_OVERRIDES") or {}

I dont think PDC_BRANCH_OVERRIDES is set, it is being used in tests but I couldn't find it in the normal code base though.

It's set in the configuration file (of the pagure instance) there is nothing to set in pagure-dist-git

+             if refname in (branch_overrides.get(project.namespace) or []):

Why checking in empty list?

if branch_overrides.get(project.namespace) returns None that will break the if refname in part, so we do if branch_overrides.get(project.namespace) is None, use [] instead (cf the use of the () and or)

+                 pdc_ref = branch_overrides[project.namespace][refname]

+             is_supported = self.is_supported_branch(project, pdc_ref)

              if is_supported is False:

                  self.info("Branch %s is unsupported" % refname)

                  return False

file modified
+3 -3
@@ -25,7 +25,7 @@ 

  

  

  class PagureAnitya(BASE):

-     """ Stores information about the monitoring of a project in anitya.

+     """Stores information about the monitoring of a project in anitya.

  

      Table -- pagure_anitya

      """
@@ -58,7 +58,7 @@ 

  

  

  class PagureOrphanReason(BASE):

-     """ Stores information about the orphaning reason.

+     """Stores information about the orphaning reason.

  

      Table -- pagure_orphan_reason

  
@@ -96,7 +96,7 @@ 

  

  

  class PagureBZOverride(BASE):

-     """ Stores information about default assignees (Fedora vs. EPEL)

+     """Stores information about default assignees (Fedora vs. EPEL)

  

      Table -- pagure_bzoverride

      """

file modified
+11 -15
@@ -38,8 +38,8 @@ 

  

  @DISTGIT_NS.route("/anitya/<namespace>/<repo>", methods=["GET"])

  def anitya_get_endpoint(namespace, repo):

-     """ Returns the current status of the monitoring in anitya of this package.

-     """

+     """Returns the current status of the monitoring in anitya of this

+     package."""

      repo = flask.g.repo

      output = {"monitoring": "no-monitoring"}

      if repo.anitya:
@@ -51,8 +51,8 @@ 

  @api_login_required(acls=["modify_project"])

  @api_method

  def anitya_patch_endpoint(namespace, repo):

-     """ Updates the current status of the monitoring in anitya of this package.

-     """

+     """Updates the current status of the monitoring in anitya of this

+     package."""

  

      repo = _get_repo(repo, namespace=namespace)

      _check_token(repo, project_token=False)
@@ -98,8 +98,7 @@ 

  @DISTGIT_NS.route("/actived/<namespace>/<repo>", methods=["GET"])

  @api_method

  def get_actived_status(namespace, repo):

-     """ Retrieves the active status of the specified package.

-     """

+     """Retrieves the active status of the specified package."""

      _log.info("Received a request to unorphan: %s/%s", namespace, repo)

  

      repo = _get_repo(repo, namespace=namespace)
@@ -117,7 +116,7 @@ 

  

  

  def _is_active_in_pdc(name, namespace):

-     """ Queries PDC and return whether the project is active on the master

+     """Queries PDC and return whether the project is active on the master

      branch in PDC or not.

      """

      pdc_url = flask.current_app.config.get("PDC_URL")
@@ -329,8 +328,7 @@ 

  @api_login_required(acls=["modify_project"])

  @api_method

  def take_orphan_endpoint(namespace, repo):

-     """ Updates the current point of contact of orphan packages.

-     """

+     """Updates the current point of contact of orphan packages."""

      _log.info("Received a request to unorphan: %s/%s", namespace, repo)

  

      repo = _get_repo(repo, namespace=namespace)
@@ -391,8 +389,7 @@ 

  @DISTGIT_NS.route("/bodhi_updates/<namespace>/<repo>", methods=["GET"])

  @api_method

  def bodhi_updates_endpoint(namespace, repo):

-     """ Retrieves the current updates in bodhi for the specified package.

-     """

+     """Retrieves the current updates in bodhi for the specified package."""

      if namespace not in ["rpms"]:

          raise pagure.exceptions.APIError(

              400,
@@ -553,8 +550,8 @@ 

  @DISTGIT_NS.route("/bzoverrides/<namespace>/<repo>", methods=["GET"])

  @api_method

  def bzoverride_get_endpoint(repo, namespace):

-     """ Returns the current default assignee(s) of this package.

-         Defaults to the repo user if unset.

+     """Returns the current default assignee(s) of this package.

+     Defaults to the repo user if unset.

      """

      repo = _get_repo(repo, namespace=namespace)

      output = {
@@ -573,8 +570,7 @@ 

  @api_method

  @api_login_required(acls=["modify_project"])

  def bzoverride_patch_endpoint(repo, namespace):

-     """ Updates the default assignees of this package.

-     """

+     """Updates the default assignees of this package."""

  

      def _validate_input(inputname):

          """ Validate if the input is either an username or a group name. """

@@ -36,8 +36,7 @@ 

          self.assertDictEqual(data, expected_result)

  

      def test_token_missing_ACL(self):

-         """Test the bz endpoint with an API token missing the `modify_project` ACL.

-         """

+         """Test the bz endpoint with an API token missing the `modify_project` ACL."""

          headers = {"Authorization": "token foo_token"}

          output = self.app.post(

              "/_dg/bzoverrides/somenamespace/test3", headers=headers
@@ -184,8 +183,7 @@ 

          self.assertDictEqual(data, expected_result)

  

      def test_reset_fedora_assignees(self):

-         """Test the bz endpoint when resetting the Fedora assignee.

-         """

+         """Test the bz endpoint when resetting the Fedora assignee."""

          headers = {"Authorization": "token aaabbbcccddd"}

          datainput = {"fedora_assignee": "foo"}

          output = self.app.post(
@@ -199,7 +197,9 @@ 

              data, {"epel_assignee": "pingou", "fedora_assignee": "foo"}

          )

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test3", namespace="somenamespace",

+             self.session,

+             "test3",

+             namespace="somenamespace",

          )

          self.assertIsNotNone(repo.bzoverride)

  
@@ -215,13 +215,14 @@ 

              data, {"epel_assignee": "pingou", "fedora_assignee": "pingou"}

          )

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test3", namespace="somenamespace",

+             self.session,

+             "test3",

+             namespace="somenamespace",

          )

          self.assertIsNotNone(repo.bzoverride)

  

      def test_reset_epel_assignees(self):

-         """Test the bz endpoint when resetting the EPEL assignee.

-         """

+         """Test the bz endpoint when resetting the EPEL assignee."""

          headers = {"Authorization": "token aaabbbcccddd"}

          datainput = {"epel_assignee": "foo", "fedora_assignee": "pingou"}

          output = self.app.post(
@@ -246,13 +247,14 @@ 

          )

  

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test3", namespace="somenamespace",

+             self.session,

+             "test3",

+             namespace="somenamespace",

          )

          self.assertIsNotNone(repo.bzoverride)

  

      def test_reset_both_assignees(self):

-         """Test the bz endpoint when resetting the both assignees.

-         """

+         """Test the bz endpoint when resetting the both assignees."""

          headers = {"Authorization": "token aaabbbcccddd"}

          datainput = {}

          output = self.app.post(
@@ -267,7 +269,9 @@ 

          )

  

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test3", namespace="somenamespace",

+             self.session,

+             "test3",

+             namespace="somenamespace",

          )

          self.assertIsNone(repo.bzoverride)

  
@@ -337,8 +341,7 @@ 

              )

  

      def test_resetting_assignees_logged_in(self):

-         """Test the bz endpoint when resetting assignees when logged in the UI.

-         """

+         """Test the bz endpoint when resetting assignees when logged in the UI."""

          user = tests.FakeUser(username="pingou")

          with tests.user_set(self.app.application, user):

              # Changing one of them before the reset

@@ -64,7 +64,12 @@ 

          super(DistGitAuthTests, self).tearDown()

  

      def create_namespaced_project(

-         self, namespace, name, is_fork=False, settings={}

+         self,

+         namespace,

+         name,

+         is_fork=False,

+         settings={},

+         hook_token_postfix="",

      ):

          item = pagure.lib.model.Project(

              user_id=1,  # pingou
@@ -72,7 +77,7 @@ 

              is_fork=is_fork,

              parent_id=3 if is_fork else None,

              description="namespaced test project",

-             hook_token="aaabbbeee",

+             hook_token="aaabbbeee" + hook_token_postfix,

              namespace=namespace,

              settings=settings,

          )
@@ -852,3 +857,133 @@ 

          )

  

          self.expect_info_msg("Access to namespace rpms is restricted")

+ 

+ 

+ class DistGitAuthTestsFedoraBranchOverride(DistGitAuthTests):

+     dga_config = {

+         "PR_ONLY": False,

+         "ACL_BLOCK_UNSPECIFIED": False,

+         "BLACKLIST_RES": ["refs/heads/c[0-9]+.*"],

+         "UNSPECIFIED_BLACKLIST_RES": ["refs/heads/f[0-9]+"],

+         "RCM_GROUP": "relenggroup",

+         "RCM_BRANCHES": ["refs/heads/f[0-9]+"],

+         "ACL_PROTECTED_NAMESPACES": ["rpms", "modules", "container"],

+         "PDC_URL": "invalid://",

+         "PDC_BRANCH_OVERRIDES": {

+             "rpms": {"refs/heads/main": "refs/heads/rawhide"}

+         },

+     }

+ 

+     def setUp(self):

+         super(DistGitAuthTestsFedoraBranchOverride, self).setUp()

+ 

+         project = self.create_namespaced_project("rpms", "test")

+         project = self.create_namespaced_project(

+             "container", "cockpit", hook_token_postfix="b"

+         )

+ 

+         msg = add_user_to_project(

+             session=self.session,

+             project=project,

+             new_user="foo",

+             user="pingou",

+             access="collaborator",

+             branches="epel*",

+         )

+         self.session.commit()

+         self.assertEqual(msg, "User added")

+ 

+     @patch("dist_git_auth.requests")

+     def test_pushing_to_rpms_main_calls_pdc_correctly(self, mock_requests):

+         project = get_project(self.session, name="test", namespace="rpms")

+         res = Mock()

+         res.ok = True

+         res.json.return_value = {"results": []}

+         mock_requests.get.return_value = res

+ 

+         self.assertFalse(

+             self.dga.check_acl(

+                 self.session,

+                 project=project,

+                 username="foo",

+                 refname="refs/heads/main",

+                 pull_request=None,

+                 repodir=None,

+                 repotype="main",

+                 revfrom=None,

+                 revto=None,

+                 is_internal=False,

+             )

+         )

+ 

+         self.expect_info_msg("Committer: False")

+         self.expect_info_msg("Fall-through deny")

+ 

+         mock_requests.get.assert_called_with(

+             "invalid://component-branches/?global_component=test"

+             "&name=rawhide&type=rpm&fields=active"

+         )

+ 

+     @patch("dist_git_auth.requests")

+     def test_pushing_to_rpms_rawhide_calls_pdc_correctly(self, mock_requests):

+         project = get_project(self.session, name="test", namespace="rpms")

+         res = Mock()

+         res.ok = True

+         res.json.return_value = {"results": []}

+         mock_requests.get.return_value = res

+ 

+         self.assertFalse(

+             self.dga.check_acl(

+                 self.session,

+                 project=project,

+                 username="foo",

+                 refname="refs/heads/rawhide",

+                 pull_request=None,

+                 repodir=None,

+                 repotype="main",

+                 revfrom=None,

+                 revto=None,

+                 is_internal=False,

+             )

+         )

+ 

+         self.expect_info_msg("Committer: False")

+         self.expect_info_msg("Fall-through deny")

+ 

+         mock_requests.get.assert_called_with(

+             "invalid://component-branches/?global_component=test"

+             "&name=rawhide&type=rpm&fields=active"

+         )

+ 

+     @patch("dist_git_auth.requests")

+     def test_pushing_to_containers_calls_pdc_correctly(self, mock_requests):

+         project = get_project(

+             self.session, name="cockpit", namespace="container"

+         )

+         res = Mock()

+         res.ok = True

+         res.json.return_value = {"results": []}

+         mock_requests.get.return_value = res

+ 

+         self.assertTrue(

+             self.dga.check_acl(

+                 self.session,

+                 project=project,

+                 username="foo",

+                 refname="refs/heads/epel8",

+                 pull_request=None,

+                 repodir=None,

+                 repotype="main",

+                 revfrom=None,

+                 revto=None,

+                 is_internal=False,

+             )

+         )

+ 

+         self.expect_info_msg("Committer: True")

+         self.expect_info_msg("Committer push")

+ 

+         mock_requests.get.assert_called_with(

+             "invalid://component-branches/?global_component=cockpit"

+             "&name=epel8&type=container&fields=active"

+         )

@@ -27,7 +27,9 @@ 

              self.session, "orphan", "orphan", ["orphan@fedoraproject.org"]

          )

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test3", namespace="somenamespace",

+             self.session,

+             "test3",

+             namespace="somenamespace",

          )

          token = pagure.lib.query.get_api_token(self.session, "aaabbbcccddd")

          token.project = repo
@@ -36,8 +38,7 @@ 

          self._app.register_blueprint(plugin.DISTGIT_NS)

  

      def test_token_missing_ACL(self):

-         """Test the orphan endpoint with an API token missing the `modify_project` ACL.

-         """

+         """Test the orphan endpoint with an API token missing the `modify_project` ACL."""

          headers = {"Authorization": "token foo_token"}

          output = self.app.post(

              "/_dg/orphan/somenamespace/test3", headers=headers
@@ -50,64 +51,76 @@ 

          headers = {"Authorization": "token BBBZZZOOO"}

          datainput = {}

          output = self.app.post(

-             "/_dg/orphan/somenamespace/test3", data=datainput, headers=headers,

+             "/_dg/orphan/somenamespace/test3",

+             data=datainput,

+             headers=headers,

          )

          assert output.status_code == 401

  

      def test_empty_form(self):

-         """Assert that empty form is accepted.

-         """

+         """Assert that empty form is accepted."""

          headers = {"Authorization": "token aaabbbcccddd"}

          datainput = {}

          output = self.app.post(

-             "/_dg/orphan/somenamespace/test3", data=datainput, headers=headers,

+             "/_dg/orphan/somenamespace/test3",

+             data=datainput,

+             headers=headers,

          )

          assert output.status_code == 200

  

      def test_invalid_form(self):

-         """Assert that invalid form is not accepted.

-         """

+         """Assert that invalid form is not accepted."""

          headers = {"Authorization": "token aaabbbcccddd"}

          datainput = {"orphan_reason": "bar"}

          output = self.app.post(

-             "/_dg/orphan/somenamespace/test3", data=datainput, headers=headers,

+             "/_dg/orphan/somenamespace/test3",

+             data=datainput,

+             headers=headers,

          )

          assert output.status_code == 400

  

      def test_already_orphaned_package(self):

-         """Assert that already orphaned package can't be orphaned again.

-         """

+         """Assert that already orphaned package can't be orphaned again."""

          headers = {"Authorization": "token aaabbbcccddd"}

          datainput = {}

          orphan_user_obj = pagure.lib.query.get_user(self.session, "orphan")

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test3", namespace="somenamespace",

+             self.session,

+             "test3",

+             namespace="somenamespace",

          )

          repo.user = orphan_user_obj

          self.session.add(repo)

          self.session.commit()

          output = self.app.post(

-             "/_dg/orphan/somenamespace/test3", data=datainput, headers=headers,

+             "/_dg/orphan/somenamespace/test3",

+             data=datainput,

+             headers=headers,

          )

          assert output.status_code == 401

  

      @patch("pagure_distgit.plugin.pagure.lib.notify.log")

      def test_orphan_package(self, mock_log):

-         """Assert that package is correctly orphaned.

-         """

+         """Assert that package is correctly orphaned."""

          headers = {"Authorization": "token aaabbbcccddd"}

          datainput = {"orphan_reason": "Lack of time"}

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test3", namespace="somenamespace",

+             self.session,

+             "test3",

+             namespace="somenamespace",

          )

          user = repo.user

          project_user = pagure.lib.model.ProjectUser(

-             project_id=repo.id, user_id=repo.user.id, access="admin",

+             project_id=repo.id,

+             user_id=repo.user.id,

+             access="admin",

          )

          self.session.add(project_user)

          self.session.commit()

          output = self.app.post(

-             "/_dg/orphan/somenamespace/test3", data=datainput, headers=headers,

+             "/_dg/orphan/somenamespace/test3",

+             data=datainput,

+             headers=headers,

          )

          assert output.status_code == 200

          data = json.loads(output.get_data(as_text=True))
@@ -127,16 +140,19 @@ 

  

      @patch("pagure_distgit.plugin.pagure.lib.notify.log")

      def test_orphan_package_repo_users_empty(self, mock_log):

-         """Assert that package is correctly orphaned.

-         """

+         """Assert that package is correctly orphaned."""

          headers = {"Authorization": "token aaabbbcccddd"}

          datainput = {"orphan_reason": "Lack of time"}

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test3", namespace="somenamespace",

+             self.session,

+             "test3",

+             namespace="somenamespace",

          )

          user = repo.user

          output = self.app.post(

-             "/_dg/orphan/somenamespace/test3", data=datainput, headers=headers,

+             "/_dg/orphan/somenamespace/test3",

+             data=datainput,

+             headers=headers,

          )

          assert output.status_code == 200

          data = json.loads(output.get_data(as_text=True))
@@ -155,8 +171,7 @@ 

          assert mock_log.call_count == 1

  

      def test_orphan_package_repo_no_orphan_user(self):

-         """Assert that missing orphan user is correctly handled.

-         """

+         """Assert that missing orphan user is correctly handled."""

          headers = {"Authorization": "token aaabbbcccddd"}

          datainput = {}

          orphan_user_obj = pagure.lib.query.get_user(self.session, "orphan")
@@ -164,7 +179,9 @@ 

          self.session.commit()

  

          output = self.app.post(

-             "/_dg/orphan/somenamespace/test3", data=datainput, headers=headers,

+             "/_dg/orphan/somenamespace/test3",

+             data=datainput,

+             headers=headers,

          )

          assert output.status_code == 400

  
@@ -184,7 +201,9 @@ 

              self.session, "orphan", "orphan", ["orphan@fedoraproject.org"]

          )

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test3", namespace="somenamespace",

+             self.session,

+             "test3",

+             namespace="somenamespace",

          )

          token = pagure.lib.query.get_api_token(self.session, "aaabbbcccddd")

          token.project = repo
@@ -204,15 +223,18 @@ 

          self.assertDictEqual(data, exp)

  

      def test_orphaned(self):

-         """ Assert that correct output is returned when package is orphaned.

-         """

+         """Assert that correct output is returned when package is orphaned."""

          orphan_user_obj = pagure.lib.query.get_user(self.session, "orphan")

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test3", namespace="somenamespace",

+             self.session,

+             "test3",

+             namespace="somenamespace",

          )

          repo.user = orphan_user_obj

          reason = model.PagureOrphanReason(

-             project_id=repo.id, reason="reason", reason_info="reason_info",

+             project_id=repo.id,

+             reason="reason",

+             reason_info="reason_info",

          )

          self.session.add(reason)

          self.session.add(repo)
@@ -229,11 +251,12 @@ 

          self.assertDictEqual(data, exp)

  

      def test_orphaned_no_reason(self):

-         """ Assert that correct output is returned when package is orphaned.

-         """

+         """Assert that correct output is returned when package is orphaned."""

          orphan_user_obj = pagure.lib.query.get_user(self.session, "orphan")

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test3", namespace="somenamespace",

+             self.session,

+             "test3",

+             namespace="somenamespace",

          )

          repo.user = orphan_user_obj

          self.session.add(repo)
@@ -285,7 +308,12 @@ 

              description="test project #4",

              hook_token="aaabbbcccdd",

          )

-         item.close_status = ["Invalid", "Insufficient data", "Fixed", "Duplicate"]

+         item.close_status = [

+             "Invalid",

+             "Insufficient data",

+             "Fixed",

+             "Duplicate",

+         ]

          self.session.add(item)

          self.session.flush()

          tests.create_locks(self.session, item)
@@ -295,14 +323,18 @@ 

          pygit2.init_repository(repo_path, bare=True)

  

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test4", namespace="rpms",

+             self.session,

+             "test4",

+             namespace="rpms",

          )

          token = pagure.lib.query.get_api_token(self.session, "aaabbbcccddd")

          token.project = repo

          orphan_user_obj = pagure.lib.query.get_user(self.session, "orphan")

          repo.user = orphan_user_obj

          reason = model.PagureOrphanReason(

-             project_id=repo.id, reason="reason", reason_info="reason_info",

+             project_id=repo.id,

+             reason="reason",

+             reason_info="reason_info",

          )

          self.session.add(reason)

          self.session.add(repo)
@@ -316,9 +348,7 @@ 

          the `modify_project` ACL.

          """

          headers = {"Authorization": "token foo_token"}

-         output = self.app.post(

-             "/_dg/take_orphan/rpms/test4", headers=headers

-         )

+         output = self.app.post("/_dg/take_orphan/rpms/test4", headers=headers)

          # invalid token

          assert output.status_code == 401

  
@@ -326,23 +356,26 @@ 

          """Test the take orphan endpoint with an invalid API token. """

          headers = {"Authorization": "token BBBZZZOOO"}

          output = self.app.post(

-             "/_dg/take_orphan/rpms/test4", headers=headers,

+             "/_dg/take_orphan/somenamespace/test3",

+             headers=headers,

          )

          assert output.status_code == 401

  

      @patch("pagure_distgit.plugin._is_active_in_pdc")

      @patch("pagure_distgit.plugin.pagure.lib.notify.log")

      def test_take_orphan(self, mock_log, mock_pdc):

-         """Assert that package is correctly adopted.

-         """

+         """Assert that package is correctly adopted."""

          mock_pdc.return_value = True

          headers = {"Authorization": "token aaabbbcccddd"}

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test4", namespace="rpms",

+             self.session,

+             "test4",

+             namespace="rpms",

          )

          assert repo.orphan_reason.reason == "reason"

          output = self.app.post(

-             "/_dg/take_orphan/rpms/test4", headers=headers,

+             "/_dg/take_orphan/rpms/test4",

+             headers=headers,

          )

          assert output.status_code == 200

          data = json.loads(output.get_data(as_text=True))
@@ -369,13 +402,16 @@ 

          mock_req.get.return_value = resp

          headers = {"Authorization": "token aaabbbcccddd"}

          repo = pagure.lib.query.get_authorized_project(

-             self.session, "test4", namespace="rpms",

+             self.session,

+             "test4",

+             namespace="rpms",

          )

          reason = repo.orphan_reason

          self.session.delete(reason)

          self.session.commit()

          output = self.app.post(

-             "/_dg/take_orphan/rpms/test4", headers=headers,

+             "/_dg/take_orphan/rpms/test4",

+             headers=headers,

          )

          assert output.status_code == 200

          data = json.loads(output.get_data(as_text=True))
@@ -391,5 +427,5 @@ 

          mock_req.get.assert_called_with(

              "invalid:/component-branches/?"

              "global_component=test4&name=rawhide&type=rpm",

-             timeout=(30, 30)

+             timeout=(30, 30),

          )

file modified
+7 -3
@@ -30,7 +30,7 @@ 

  

  

  def main(args):

-     """ Creates a JSON blob containing the following structure:

+     """Creates a JSON blob containing the following structure:

      {

        namespace: {

          package: [people watching issues],
@@ -57,7 +57,9 @@ 

      # Start the watchers by the main admin

      query = (

          session.query(

-             model.Project.namespace, model.Project.name, model.User.user,

+             model.Project.namespace,

+             model.Project.name,

+             model.User.user,

          )

          .filter(model.Project.user_id == model.User.id)

          .filter(model.Project.parent_id == None)
@@ -73,7 +75,9 @@ 

      # Add the contributors

      query = (

          session.query(

-             model.Project.namespace, model.Project.name, model.User.user,

+             model.Project.namespace,

+             model.Project.name,

+             model.User.user,

          )

          .filter(model.Project.id == model.ProjectUser.project_id)

          .filter(model.ProjectUser.user_id == model.User.id)

@@ -30,7 +30,7 @@ 

  

  

  def main(args):

-     """ Creates a JSON blob containing the following structure:

+     """Creates a JSON blob containing the following structure:

      {

        namespace: {

          package: [people watching issues],
@@ -57,7 +57,9 @@ 

      # Start the owner list by the main admin

      query = (

          session.query(

-             model.Project.namespace, model.Project.name, model.User.user,

+             model.Project.namespace,

+             model.Project.name,

+             model.User.user,

          )

          .filter(model.Project.user_id == model.User.id)

          .filter(model.Project.parent_id == None)
@@ -74,7 +76,9 @@ 

  

      query = (

          session.query(

-             model.Project.namespace, model.Project.name, model.User.user,

+             model.Project.namespace,

+             model.Project.name,

+             model.User.user,

          )

          .filter(model.Project.id == model.ProjectUser.project_id)

          .filter(model.ProjectUser.user_id == model.User.id)

file modified
+1 -1
@@ -31,7 +31,7 @@ 

  

  

  def main(args):

-     """ Creates a JSON blob containing the following structure:

+     """Creates a JSON blob containing the following structure:

      {

        namespace: {

          package: { main admin, epel_assignee, fedora_assignee },

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

This probably deserves some tests

rebased onto af0b2677e8ebb7c2d7406f66ec39bab25bf13101

4 years ago

rebased onto aedd9e0d43e29047a6876ec142abc3cfa79b0fd8

4 years ago

This needs to be on a per namespace feature

rebased onto a9226f1d66895e8e7be3a56b493e6dffb19380fe

4 years ago

I dont think PDC_BRANCH_OVERRIDES is set, it is being used in tests but I couldn't find it in the normal code base though.

Why checking in empty list?

It's set in the configuration file (of the pagure instance) there is nothing to set in pagure-dist-git

if branch_overrides.get(project.namespace) returns None that will break the if refname in part, so we do if branch_overrides.get(project.namespace) is None, use [] instead (cf the use of the () and or)

rebased onto c16e6f0

4 years ago

Thanks for the review!

Pull-Request has been merged by pingou

4 years ago