From d84948c4d8c34c9d49b9a27bf1c18a6b54cc00d9 Mon Sep 17 00:00:00 2001 From: Eric Ball Date: Tue, 27 Sep 2022 14:07:17 -0700 Subject: [PATCH] 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 --- .pre-commit-config.yaml | 2 +- lftools/api/endpoints/gerrit.py | 2 +- lftools/git/gerrit.py | 6 ++++-- releasenotes/notes/info-merge-fixes-ef149399d1b2d8b2.yaml | 9 +++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/info-merge-fixes-ef149399d1b2d8b2.yaml 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. -- 2.16.6