Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: support gitlab as git provider #96

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

agokrani
Copy link

What does this PR do?

Implements GitLabManager class to support other git providers. Have also added other flags mentioned in issue #10.

@iuliaturc
Copy link
Contributor

@agokrani Just wanted to check: is this still WIP or is it ready for review?

@agokrani
Copy link
Author

@iuliaturc this is still WIP. It just require the default branch test. I will try to add it early tomorrow.

@kmussa1993
Copy link

@iuliaturc you can review it now.

Copy link
Contributor

@iuliaturc iuliaturc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I'm wondering if it's worth merging the two RepoManagers into one (with some occasional if/else blocks) to avoid so much duplication.

@@ -81,6 +81,8 @@ def add_repo_args(parser: ArgumentParser) -> Callable:
default="repos",
help="The local directory to store the repository",
)
parser.add("--git-provider", default="github", choices=["github", "gitlab"])
parser.add("--base-url", default=None, help="The base URL for the Git provider. This is only needed for GitLab.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please name the flag --gitlab-base-url to avoid confusion?

@@ -254,3 +254,253 @@ def from_args(args: Dict):
"For private repositories, please set the GITHUB_TOKEN variable in your environment."
)
return repo_manager


class GitLabRepoManager(DataManager):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new class introduces a lot of code duplication. IIUC, the only difference compared to GitHubRepoManager is how URLs are constructed. Is that correct? In that case, we could have a single unified GitRepoManager that takes a base URL (which would be github.com for GitHub and gitlab.com for GitLab). And maybe we'd need occasional if/else for e.g. url_for_file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Should be possible but I don't think getting different if else would be a good idea if you are incorporating other git providers as well. I haven't looked into other providers maybe something to check before we merge them into one class?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub and GitLab are the main ones, I'm not sure if there's a third one as widely used.

Alternative to if/else clauses, we could have an abstract class GitRepoManager that is implemented by GitHubRepoManager and GitLabRepoManager. For instance:

class GitRepoManager:
    @abstractclass
    def get_repo_url(self, repo_id: str):
        pass

    @cached_property
    def is_public(self) -> bool:
        """Checks whether a GitHub repository is publicly visible."""
        response = requests.get(self.get_repo_url(repo_id), timeout=10)
        # Note that the response will be 404 for both private and non-existent repos.
        return response.status_code == 200

    ... other methods

class GitHubRepoManager(GitRepoManager):
    def get_repo_url(self, repo_id: str):
        return f"https://api.github.com/repos/{self.repo_id}"
    ...

class GitLabRepoManager(GitRepoManager):
    def get_repo_url(self, repo_id: str):
        return f"https://gitlab.com/api/v4/projects/{repo_id}"  
    ... 

Does that make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants