Skip to content

Commit

Permalink
Remove ./ when getting file in GitLab (#844)
Browse files Browse the repository at this point in the history
Remove ./ when getting file in GitLab

So that the behaviour is consistent among forges. GitLab cannot do this automatically (confirmed that both GitHub and Pagure can).
Related to #838
RELEASE NOTES BEGIN
GitLabProject.get_file_content can now correctly handle file paths starting with ./.
RELEASE NOTES END

Reviewed-by: Matej Focko
Reviewed-by: Laura Barcziová
  • Loading branch information
2 parents 7fc0829 + b79a9d6 commit 50b02cb
Show file tree
Hide file tree
Showing 3 changed files with 632 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ogr/services/gitlab/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: MIT

import logging
import os
from typing import Any, Optional, Union

import gitlab
Expand Down Expand Up @@ -361,6 +362,8 @@ def get_branches(self) -> list[str]:

def get_file_content(self, path, ref=None) -> str:
ref = ref or self.default_branch
# GitLab cannot resolve './'
path = os.path.normpath(path)
try:
file = self.gitlab_repo.files.get(file_path=path, ref=ref)
return file.decode().decode()
Expand Down
Loading

0 comments on commit 50b02cb

Please sign in to comment.