From: Eric Ball Date: Tue, 27 Sep 2022 21:07:17 +0000 (-0700) Subject: Fix: Correct file path and url parsing X-Git-Tag: v0.37.0^0 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F43%2F70743%2F3;p=releng%2Flftools.git Fix: Correct file path and url parsing 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 --- diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 59713601..291a1b03 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,7 @@ repos: ########## - repo: https://github.com/ambv/black - rev: 22.6.0 + rev: 22.8.0 hooks: - id: black diff --git a/lftools/api/endpoints/gerrit.py b/lftools/api/endpoints/gerrit.py index b6fc2766..7dbe4893 100644 --- a/lftools/api/endpoints/gerrit.py +++ b/lftools/api/endpoints/gerrit.py @@ -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] diff --git a/lftools/git/gerrit.py b/lftools/git/gerrit.py index df15eb68..e94558c0 100644 --- a/lftools/git/gerrit.py +++ b/lftools/git/gerrit.py @@ -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 index 00000000..0bb7ca89 --- /dev/null +++ b/releasenotes/notes/info-merge-fixes-ef149399d1b2d8b2.yaml @@ -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.