← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ilkeremrekoc/launchpad:maven-cargo-metadata-root into launchpad:master

 

İlker Emre Koç has proposed merging ~ilkeremrekoc/launchpad:maven-cargo-metadata-root into launchpad:master.

Commit message:
use publish url to extract root path

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ilkeremrekoc/launchpad/+git/launchpad/+merge/486511

To search within artifactory we need a root path to start from.
Originally, I tried getting it from a configuration field, but
decided extracting it from the already provided publishing url
would be the better option.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilkeremrekoc/launchpad:maven-cargo-metadata-root into launchpad:master.
diff --git a/lib/lp/crafts/model/craftrecipebuildjob.py b/lib/lp/crafts/model/craftrecipebuildjob.py
index a0af8ed..58aa740 100644
--- a/lib/lp/crafts/model/craftrecipebuildjob.py
+++ b/lib/lp/crafts/model/craftrecipebuildjob.py
@@ -151,8 +151,6 @@ class CraftPublishingJob(CraftRecipeBuildJobDerived):
     max_retries = 5
 
     task_queue = "native_publisher_job"
-
-    artifactory_base_url = config.artifactory.base_url
     config = config.ICraftPublishingJobSource
 
     @classmethod
@@ -518,8 +516,14 @@ class CraftPublishingJob(CraftRecipeBuildJobDerived):
         # We assume the URL ends with the repository name
         repo_name = publish_url.rstrip("/").split("/")[-1]
 
+        root_path_str = self._extract_root_path(publish_url)
+        if not root_path_str:
+            raise NotFoundError(
+                f"Could not extract root path from URL: {publish_url}"
+            )
+
         # Search for the artifact in Artifactory using AQL
-        root_path = ArtifactoryPath(self.artifactory_base_url)
+        root_path = ArtifactoryPath(root_path_str)
         artifacts = root_path.aql(
             "items.find",
             {
@@ -551,6 +555,20 @@ class CraftPublishingJob(CraftRecipeBuildJobDerived):
         )
         artifact_path.set_properties(new_properties)
 
+    def _extract_root_path(self, publish_url: str) -> str:
+        """
+        Extracts everything from the first occurrence of 'https' up to and
+        including 'artifactory'."""
+        start_index = publish_url.find("https")
+        if start_index == -1:
+            return ""
+
+        end_index = publish_url.find("artifactory", start_index)
+        if end_index == -1:
+            return ""
+
+        return publish_url[start_index : end_index + len("artifactory")]
+
     def _recipe_git_url(self):
         """Get the recipe git URL."""
 
diff --git a/lib/lp/crafts/tests/test_craftrecipebuildjob.py b/lib/lp/crafts/tests/test_craftrecipebuildjob.py
index 6fcd5da..bb28437 100644
--- a/lib/lp/crafts/tests/test_craftrecipebuildjob.py
+++ b/lib/lp/crafts/tests/test_craftrecipebuildjob.py
@@ -9,7 +9,7 @@ import tempfile
 from pathlib import Path
 
 from artifactory import ArtifactoryPath
-from fixtures import FakeLogger, MonkeyPatch
+from fixtures import FakeLogger
 from testtools.matchers import Equals, Is, MatchesStructure
 from zope.component import getUtility
 from zope.security.proxy import removeSecurityProxy
@@ -90,14 +90,6 @@ class TestCraftPublishingJob(TestCaseWithFactory):
             FakeArtifactoryFixture(self.base_url, self.repository_name)
         )
 
-        self.useFixture(
-            MonkeyPatch(
-                "lp.crafts.model.craftrecipebuildjob."
-                + "CraftPublishingJob.artifactory_base_url",
-                self.base_url,
-            )
-        )
-
     def _artifactory_search(self, repo_name, artifact_name):
         """Helper to search for a file in the Artifactory fixture."""