Skip to content

Commit

Permalink
fixed gitlab CI generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Neagu committed May 4, 2022
1 parent 9696df8 commit bc43311
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
13 changes: 9 additions & 4 deletions src/docker_publisher_osparc_services/http_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ async def _gitlab_get_project_id(repo_model: RepoModel) -> str:
},
)
found_repos = result.json()
if len(found_repos) != 1:
message = f"Searching for {repo_name} did not yield the deisired reulst {found_repos}"
raise CouldNotFindAGitlabRepositoryRepoException(message)
return found_repos[0]["id"]
# check for http_url_to_repo
for repo in found_repos:
if repo_model.http_url_to_repo == repo["http_url_to_repo"]:
return repo["id"]

message = (
f"Searching for {repo_name} did not yield the deisired result {found_repos}"
)
raise CouldNotFindAGitlabRepositoryRepoException(message)


async def gitlab_did_last_repo_run_pass(
Expand Down
28 changes: 25 additions & 3 deletions src/docker_publisher_osparc_services/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ def require_access_token_for_gitlab(cls, values):
)
return values

@property
def repo(self) -> str:
def _format_repo(
self, escape_credentials: bool = False, strip_credentials: bool = False
) -> str:
if self.gitlab is None:
return self.address

Expand All @@ -101,8 +102,29 @@ def repo(self) -> str:
if user is None or password is None:
return self.address

clear_password = password.get_secret_value()
if escape_credentials:
user = user.replace("@", "%40")
clear_password = clear_password.replace("@", "%40")

protocol, url = self.address.split("://")
return f"{protocol}://{user}:{password.get_secret_value()}@{url}"

if strip_credentials:
return f"{protocol}://{url}"
else:
return f"{protocol}://{user}:{clear_password}@{url}"

@property
def repo(self) -> str:
return self._format_repo(escape_credentials=False)

@property
def escaped_repo(self) -> str:
return self._format_repo(escape_credentials=True)

@property
def http_url_to_repo(self) -> str:
return self._format_repo(strip_credentials=True)


class ConfigModel(BaseModel):
Expand Down
4 changes: 2 additions & 2 deletions src/docker_publisher_osparc_services/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

async def get_branch_hash(repo_model: RepoModel) -> str:
result = await command_output(
f"git ls-remote {repo_model.repo} refs/heads/{repo_model.branch} -q",
f"git ls-remote {repo_model.escaped_repo} refs/heads/{repo_model.branch} -q"
)
# since multiple lines might be present in the output, fetch from the end
commit_hash = result.split()[-2]
Expand All @@ -25,7 +25,7 @@ async def get_branch_hash(repo_model: RepoModel) -> str:
async def clone_repo(repo_model: RepoModel) -> None:
"""clones and stores the cloned_dir"""
target_dir: Path = Path(TemporaryDirectory().name)
await command_output(f"git clone {repo_model.repo} {target_dir}")
await command_output(f"git clone {repo_model.escaped_repo} {target_dir}")
repo_model.clone_path = target_dir


Expand Down

0 comments on commit bc43311

Please sign in to comment.