Skip to content

Commit

Permalink
Fix: Correct file path and url parsing
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
eb-oss committed Sep 27, 2022
1 parent 977063d commit d84948c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
##########

- repo: https://github.com/ambv/black
rev: 22.6.0
rev: 22.8.0
hooks:
- id: black

Expand Down
2 changes: 1 addition & 1 deletion lftools/api/endpoints/gerrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def create_project(self, fqdn, gerrit_project, ldap_group, description, check):
--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]
Expand Down
6 changes: 4 additions & 2 deletions lftools/git/gerrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ def add_file(self, filepath, content):
"""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."""
Expand Down Expand Up @@ -166,7 +168,7 @@ def add_info_job(self, fqdn, gerrit_project, issue_id, agent):
)
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)
Expand Down
9 changes: 9 additions & 0 deletions releasenotes/notes/info-merge-fixes-ef149399d1b2d8b2.yaml
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit d84948c

Please sign in to comment.