-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
GitLab Integration #3327
GitLab Integration #3327
Conversation
Sync gitlab repos
Support private repositories and cleanup
…ocs.org into saily-sync-gitlab-repos - Skip test_oauth.py from flake8 since it has a lot of "Too long lines" - Add some style fixes following the new rules - Minimum adaptation for the registry OAuth classes
@@ -26,6 +26,7 @@ repos: | |||
'flake8-string-format', | |||
'flake8-tidy-imports', | |||
'flake8-todo'] | |||
exclude: 'test_oauth.py' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file has a lot of long lines that I don't want to fix now :)
|
||
* Go to the **Settings** page for your project | ||
* Click **Integrations** | ||
* For **URL**, use the URL of the integration on Read the Docs, found on the | ||
:ref:`integration detail page <integration-detail>` page | ||
* Leave the default **Push events** selected | ||
* Leave the default **Push events** selected and mark **Tag push events** also |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but I think we need the Tag push events here also...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we'd want them. +1
# TODO: I think this can be different than `gitlab.com` | ||
# self.adapter.provider_base_url | ||
GL_REGEXS = [ | ||
re.compile('gitlab.com/(.+)/(.+)(?:\.git){1}'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to support private gitlab instalation? How this should looks like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will, but this integration will be on the .com, we won't put that code here yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. So, I think the TODO note is good for now. I will leave it there
readthedocs/oauth/services/gitlab.py
Outdated
re.escape(urlparse(adapter.provider_base_url).netloc)) | ||
default_avatar = { | ||
'repo': urljoin(settings.MEDIA_URL, 'images/fa-bookmark.svg'), | ||
'org': urljoin(settings.MEDIA_URL, 'images/fa-users.svg'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want these default avatars? Github and Bitbucket are not using nothing similar to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say no, we use the github/bitbucket supplied avatar as the only source I believe.
or, alternatively, we edit all to include a default avatar. Perhaps in another PR later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove the default avatars and its files.
We can make it in another PR for all the services, but I think it doesn't worth it really.
readthedocs/oauth/services/gitlab.py
Outdated
|
||
# The ID or URL-encoded path of the project | ||
# https://docs.gitlab.com/ce/api/README.html#namespaced-path-encoding | ||
repo_id = '{}%2F{}'.format(owner, repo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is enough here but maybe it's better to find a way to get the proper repo:id
from gitlab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably fine. Github gives us this information in the api return, but i don't see anything wrong with this as long as owner and repo are supplied from the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a better way to do this,
# The ID or URL-encoded path of the project
# https://docs.gitlab.com/ce/api/README.html#namespaced-path-encoding
repo_id = json.loads(project.remote_repository.json).get('id')
It uses the RemoteRepository response saved in our database, which I think it's better than parsing a URL, more specifically in GitLab that the URL could have different domains.
So, I'll try to use the repo id
here instead of owner + repo and we can get rid of the GL_REGEX also, since it won't be needed anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex is also used at this point:
So, we will need to figure this out for that case, at least.
readthedocs/oauth/services/gitlab.py
Outdated
pass | ||
|
||
# @classmethod | ||
# def get_token_for_project(cls, project, force_local=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is only needed by Github, but I don't understand how it works yet...
'gitlab': { | ||
'SCOPE': [ | ||
'api', | ||
'read_user', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but maybe the sudo
permission is also required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll want to make sure here. Folks are really particular about the permissions we request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to understand their documentation. Seems poor to me: https://docs.gitlab.com/ce/user/profile/personal_access_tokens.html#limiting-scopes-of-a-personal-access-token
So far so good, I was able to connect the account and setup the webhooks using only these two.
@@ -228,15 +231,6 @@ def INSTALLED_APPS(self): # noqa | |||
CELERY_CREATE_MISSING_QUEUES = True | |||
|
|||
CELERY_DEFAULT_QUEUE = 'celery' | |||
# Wildcards not supported: https://github.com/celery/celery/issues/150 | |||
CELERY_ROUTES = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not used anymore. None of those tasks exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've moved to marking the queue on @task
declaration
Just a comment about our auto-linting configuration: @agjohnson I would say that we should disable D202 since I didn't find a way to make it automatically with the tools that I know. Having it enabled will produce a lot of this kind of manual changes: 0ce1702 The other way around is supported by |
@agjohnson another thing that it's missing here (but probably for another PR that also change the theme) is the context sent to sphinx at https://github.com/rtfd/readthedocs.org/blob/4db7339aac7a52d7a35b6359eff8032e8aadf6ae/readthedocs/doc_builder/backends/sphinx.py#L112 Let me know how you prefer to work on that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me! I didn't go through the gitlab docs really to see if we're doing everything right, but the code looks great. 👍
@@ -13,7 +13,7 @@ More information can be found in the :doc:`vcs` page. | |||
Auto-updating | |||
------------- | |||
|
|||
The :doc:`webhooks` page talks about the different ways you can ping RTD to let us know your project has been updated. We have official support for GitHub, and anywhere else we have a generic post-commit hook that allows you to POST to a URL to get your documentation built. | |||
The :doc:`webhooks` page talks about the different ways you can ping RTD to let us know your project has been updated. We have official support for GitHub, Bitbucket and GitLab, and anywhere else we have a generic post-commit hook that allows you to POST to a URL to get your documentation built. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3 doc updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Credits to @saily, the original author :)
|
||
* Go to the **Settings** page for your project | ||
* Click **Integrations** | ||
* For **URL**, use the URL of the integration on Read the Docs, found on the | ||
:ref:`integration detail page <integration-detail>` page | ||
* Leave the default **Push events** selected | ||
* Leave the default **Push events** selected and mark **Tag push events** also |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we'd want them. +1
""" | ||
# TODO Replace this check by keying project to remote repos | ||
return ( | ||
cls.url_pattern is not None and | ||
cls.url_pattern.search(project.repo) is not None | ||
) | ||
cls.url_pattern.search(project.repo) is not None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these are linting changes, I think? This is a bit of what I was worried about w/ the auto-linting, making it hard to catch real changes in the massive linting changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they are linting changes.
I try to make these changes in separated commits but sometimes it's complicated.
I don't know what's the best way for this. I think we can make a huge PR with all the automcatic linting changes and fix the specific one by hand after merging it. That will make PR with linting changes smaller in the future.
But I don't know what's best, honestly (I'm used to review PR with a lot of linting changes because we followed the same as I'm doing here but...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this a little. I don't think large commit is the answer yet, this shouldn't be priority. We can however be more careful in making PRs where autolint is a separate commit. This should be more easy to review, but requires some careful git rebasing depending on your workflow (if you are commiting autolint changes with your logic changes)
Or just a separate PR, whatever is easier to manage for your own sake.
log.debug( | ||
'Not importing %s because mismatched orgs', | ||
fields['name'], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if this should be a higher priority? Will this cause breakage for the user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly. I'm not sure. Github and Bitbucket code do exactly the same.
It's kind of a weird case, because it should happend that user U
created the repo R
with organization O
. Then, user UU
tries to import the same repo R
but with organization OO
and that generates this error, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct. Probably no need to surface this any harder, it's a weird edge case.
@humitos could you explain this more, i don't quite understand re: #3327 (comment) |
@agjohnson we are sending some context to sphinx (github_user, github_repo, etc). So, we will to send the same information about |
No need to do this on signal, it can be included in the block above, similar to github/butbucket. But good point, i didn't realize this was missing. |
I also found there is some helper methods missing. For example: https://github.com/rtfd/readthedocs.org/blob/61dc4b5389197c12c7ebe92a0968eebb551115c2/readthedocs/builds/models.py#L229 |
Looks like a few more pieces missing. I'll assign this to @humitos as a WIP until it's wrapped up next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay ... :)
One last change, we just need a test case for this GitLab URL in our context data. With that, I swear this will be mergeable.
path=filename, | ||
source_suffix=source_suffix, | ||
action=action_string, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Can anyone advise how to customise the gitlab_url - we have our own deployment. Following https://sphinx-rtd-theme.readthedocs.io/en/stable/configuring.html#file-wide-metadata, I tried to set in conf.py html_context = { But it doesn't work, it remains set to gitlab.com in the HTML. Did I put this in the wrong place? EDIT: Fixed. The right variable to use in html_context settings is gitlab_host (I inferred this from snippet on https://docs.readthedocs.io/en/stable/guides/vcs.html though it is not documented explicitly) |
@fcasson please, next time open a new issue instead of commenting in an old PR. Thanks! I think you will need |
This is the continuation of the work done by @saily at #1870
I updated the code to follow the new codebase and also use the
apiv4
endpoints from gitlab. Besides, there are a bunch of style-things.Missing things:
Closes #1441
Closes #1870
Closes #1443