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

Add GitLab fetcher #649

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

suhanoves
Copy link

Proposed changes

Hello Augusto,
Thank you for developing such a fantastic library!

I've been working on incorporating the ability to store style files on a self-hosted GitLab instance, which I noticed was missing from the library, so I took the initiative to add this feature.

I've made an effort to thoroughly document the nuances of interfacing with GitLab's API in the method docstrings. Unlike GitHub, GitLab's API relies on project IDs, while the GitLab website uses project paths. This distinction necessitated implementing functionality to support both behaviors.

I faced some challenges setting up the project, as I was unfamiliar with tox.

Currently, I've managed to write tests only for the URL generation, not for the Fetcher itself. I'm unsure which existing tests cover similar functionality.

If you could provide some guidance, I would be eager to fully complete the merge request. I'm relatively new to contributing to open source and would appreciate your help.

Checklist

  • Read the contribution guidelines
  • Run make locally before pushing commits
  • Add tests for the relevant parts:
    • API
    • CLI
    • flake8 plugin (normal mode)
    • flake8 plugin (offline mode)
  • Write documentation when there's a new API or functionality

@andreoliwa
Copy link
Owner

Hey, thanks for this PR! 🙏🏻
I'm a bit busy at the moment but I will take a look as soon as possible.

Copy link
Owner

Choose a reason for hiding this comment

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

Now at least the build is fixed.
For reference, here is the last build of lines with missing coverage.

We can try to mimic how GitHub was tested.

@@ -42,6 +42,9 @@ Remote style

Use the URL of the remote file.

Github
Copy link
Owner

Choose a reason for hiding this comment

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

It's a capital "H". 😅

Suggested change
Github
GitHub

Please fix it everywhere if there are other places.

@@ -111,6 +114,85 @@ Or you can use an environment variable to avoid keeping secrets in plain text.
A literal token cannot start with a ``$``.
All tokens must not contain any ``@`` or ``:`` characters.

Gitlab
Copy link
Owner

Choose a reason for hiding this comment

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

Same thing here, capital "L". 😄

Suggested change
Gitlab
GitLab

@@ -1,3 +1,4 @@
# pylint: disable=too-many-lines # TODO: refactor: break this into separate modules in a follow-up PR
Copy link
Owner

Choose a reason for hiding this comment

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

I added this and will fix it later on another PR, so this one stays small.

A literal token cannot start with a ``$``.
All tokens must not contain any ``@`` or ``:`` characters.


Copy link
Owner

Choose a reason for hiding this comment

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

I read this far.
Good docs, thanks a lot. 👍🏻 👏🏻

I will try it out on some GitLab repo from gitlab.com (I don't have a self-hosted or paid versions).

Comment on lines +138 to +141
def raise_gitlab_incorrect_url_error(url: furl) -> NoReturn:
"""Raise an error if the URL is not a valid GitLab URL."""
message = f"Invalid GitLab URL: {url}"
raise ValueError(message)
Copy link
Owner

Choose a reason for hiding this comment

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

This could be a private method on the GitLabURL below since it's only used there.

Comment on lines +773 to +774
if token is not None and token.startswith("$"):
token = os.getenv(token[1:])
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe this works, I haven't tried.

Suggested change
if token is not None and token.startswith("$"):
token = os.getenv(token[1:])
if not token and token.startswith("$"):
token = os.getenv(token[1:])

@property
def authorization_header(self) -> dict[Literal["PRIVATE-TOKEN"], str] | None:
"""Authorization header encoded in this URL."""
return {"PRIVATE-TOKEN": self.token} if self.token else None
Copy link
Owner

Choose a reason for hiding this comment

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

This could a constant in constants.py:

GITLAB_TOKEN_KEY = "PRIVATE-TOKEN"

Or some similar name.

host=self.host,
path=[*self.project, "-", "raw", self.git_reference, *self.path],
query_params=self.query_params,
)
Copy link
Owner

Choose a reason for hiding this comment

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

I reviewed this far, will continue later.

@suhanoves
Copy link
Author

Thanks for the review!
I was on vacation, I’ll fix everything soon, according to your comments

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

Successfully merging this pull request may close these issues.

None yet

2 participants