Fix: Correct file path and url parsing 43/70743/3 v0.37.0
authorEric Ball <eball@linuxfoundation.org>
Tue, 27 Sep 2022 21:07:17 +0000 (14:07 -0700)
committerEric Ball <eball@linuxfoundation.org>
Tue, 27 Sep 2022 21:27:14 +0000 (14:27 -0700)
These two bugs are both blocking our info-master job, so they are
being grouped together. One is an issue with using an absolute rather
than relative file path when adding a file to git. The other is
parsing the url with safe slashes, which was causing issues with
creation of repos that have slashes in the name.

Issue: RELENG-4461
Change-Id: Ia63ffc5f157bfb5285e8c6bdb2274a91a384a3f4
Signed-off-by: Eric Ball <eball@linuxfoundation.org>
.pre-commit-config.yaml
lftools/api/endpoints/gerrit.py
lftools/git/gerrit.py
releasenotes/notes/info-merge-fixes-ef149399d1b2d8b2.yaml [new file with mode: 0644]

index 5971360..291a1b0 100644 (file)
@@ -19,7 +19,7 @@ repos:
   ##########
 
   - repo: https://github.com/ambv/black
-    rev: 22.6.0
+    rev: 22.8.0
     hooks:
     - id: black
 
index b6fc276..7dbe489 100644 (file)
@@ -377,7 +377,7 @@ class Gerrit(client.RestApi):
         --description="This is a demo project"
 
         """
-        gerrit_project = urllib.parse.quote(gerrit_project, encoding=None, errors=None)
+        gerrit_project = urllib.parse.quote(gerrit_project, safe="", encoding=None, errors=None)
 
         access_str = "projects/?query=name:{}".format(gerrit_project)
         result = self.get(access_str)[0]
index df15eb6..e94558c 100644 (file)
@@ -89,12 +89,14 @@ class Gerrit:
         """Add a file to the current git repo."""
         if filepath.find("/") >= 0:
             try:
+                log.debug("Making directories for {}".format(filepath[0]))
                 os.makedirs(os.path.split(filepath)[0])
             except FileExistsError:
-                pass
+                log.debug("Directories already exist, skipping")
         with open(filepath, "w") as newfile:
             newfile.write(content)
         self.repo.git.add(filepath)
+        log.debug(self.repo.git.status())
 
     def add_symlink(self, filepath, target):
         """Add a symlink to the current git repo."""
@@ -166,7 +168,7 @@ class Gerrit:
         )
         log.debug("File contents:\n{}".format(content))
 
-        filepath = os.path.join(self.repo.working_tree_dir, "jjb/{0}/{0}.yaml".format(gerrit_project_dashed))
+        filepath = "jjb/{0}/{0}.yaml".format(gerrit_project_dashed)
         self.add_file(filepath, content)
         commit_msg = "Chore: Automation adds {}".format(filename)
         self.commit(commit_msg, issue_id, push=True)
diff --git a/releasenotes/notes/info-merge-fixes-ef149399d1b2d8b2.yaml b/releasenotes/notes/info-merge-fixes-ef149399d1b2d8b2.yaml
new file mode 100644 (file)
index 0000000..0bb7ca8
--- /dev/null
@@ -0,0 +1,9 @@
+---
+fixes:
+  - |
+    Correct the file path for the JJB info file job. This was incorrectly set as
+    an absolute path, but it needs to be relative to the git repo root.
+  - |
+    Add the "safe" parameter to URL parsing in create_project. This removes the
+    default safe value which includes the forward slash. In this case, we do
+    want to escape slashes that are part of the repo name.