-
-
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
Github Enterprise Support #3853
Conversation
888a0b0
to
38ee82a
Compare
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.
Thanks for your contribution! This seems to be a good addition.
Although, I'm not sure to fully understand the problem itself. The only difference between GH and GHE is the URL that we hit? I mean, instead of github.com
we need to hit whatever you defined in {{github_url}}
?
It seems that it's needed to update a django setting to match the github
provider name to the enterprise URL as pointed here: http://django-allauth.readthedocs.io/en/latest/providers.html#enterprise-support
I did that change and it worked. So, I think we need to mention that at some point.
In [1]: from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
In [2]: GitHubOAuth2Adapter.profile_url
Out[2]: 'http://localhost:8000/api/v3/user'
In [3]:
Finally, is there a way to co-exist both connections here: GH and GHE?
I'm requesting these changes before merging, but I think it's pretty close.
To swap out this connection with an enterprise edition of Github you need to: | ||
|
||
1. Create an OAuth Github Application by following the `official guide <https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app/>`_. Note here you must provide the address of the readthedocs | ||
instance you're setting up. This will give you a Github application ``client id`` and ``secret``. |
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.
Shouldn't this line be indented at the same level than Create
word?
readthedocs/builds/models.py
Outdated
@@ -36,6 +38,8 @@ | |||
|
|||
DEFAULT_VERSION_PRIVACY_LEVEL = getattr( | |||
settings, 'DEFAULT_VERSION_PRIVACY_LEVEL', 'public') | |||
ARGS = '/{user}/{repo}/{action}/{version}{docroot}{path}{source_suffix}' |
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.
maybe a name like _GITHUB_URL_ARS
instead?
site, _ = Site.objects.update_or_create(id=SITE_ID, defaults=dict(name=PRODUCTION_DOMAIN, domain=PRODUCTION_DOMAIN)) | ||
|
||
# change the github social account provider to link to the enterprise Github | ||
GITHUB = "{{github_url}}" |
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 doesn't seem to be used at all.
@humitos yes you need to change that, however in some places the To have the connect account feature work you need to setup the site setting correctly (e.g. point to your domain and not example.com as it's by default - which is the first change in the script). As for having both exists do we have a strong need for that, as would probably complicate the implementation. |
@humitos made the requested changes, ready to discuss supporting an enterprise instance with github.com in parallel. |
readthedocs/builds/models.py
Outdated
@@ -5,6 +5,8 @@ | |||
absolute_import, division, print_function, unicode_literals) | |||
|
|||
import logging | |||
|
|||
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter |
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.
from should go after import, and third party import should go after stdlib import and before local imports
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.
for import sorting, you can run isort
command which does the trick automatically following our rules.
@@ -37,17 +40,12 @@ def handle(self, *args, **options): | |||
return | |||
|
|||
for project in Project.objects.filter( | |||
programming_language__in=['none', '', 'words'] | |||
programming_language__in=['none', '', 'words'] |
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.
4 spaces was fine
tox.ini
Outdated
@@ -15,6 +15,7 @@ setenv = | |||
DJANGO_SETTINGS_MODULE=readthedocs.settings.test | |||
LANG=C | |||
DJANGO_SETTINGS_SKIP_LOCAL=True | |||
passenv = https_proxy http_proxy no_proxy |
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 unrelated
@@ -11,13 +11,16 @@ | |||
from __future__ import absolute_import | |||
from __future__ import print_function | |||
import os | |||
|
|||
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter |
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.
same comment as before
Made the requested changes. By the way running |
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.
Left some minor comments
|
||
.. code-block:: python | ||
|
||
SOCIALACCOUNT_PROVIDERS = {'github': {'SCOPE': ['user:email', 'read:org', |
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.
Can you update the formatting style here to be similar like this: https://github.com/rtfd/readthedocs.org/blob/adb5392c47a1b3fe506524d898dd147b038d4140/readthedocs/settings/base.py#L273-L289 ?
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.
Also, if you modify local_settings.py
like this, you override the setting and loose the gitlab
feature, for example.
I've been using somethin like this:
from .dev import CommunityDevSettings
INSTALLED_APPS = CommunityDevSettings().INSTALLED_APPS + [
'debug_toolbar',
]
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 I can do; my approach was that people in an enterprise env usually just want one VCS, hence why removing gitlab is not needed anymore
re.compile('github.com/(.+)/(.+)'), | ||
re.compile('github.com:(.+)/(.+)\.git$'), | ||
GITHUB_REGEX_BASES = [ | ||
'{}/(.+)/(.+)(?:\.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.
Not sure if this was on purpose, but it was {1}
and now it's {{1}}
. I suppose the original was correct.
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.
no this change is needed, because now we'll format the string to get the regex, hence the double quotation actually keeps it as it was beforehand (aka literal {
)
Yes. It's correctly configured but it's something new and we didn't run to the entire project yet. We were running it only the files that we modify on each PR. So, you could run it only on those files. At a higher level, we have |
We don't really need this for the community site since we don't support GHE in .org but I was asking you to know if this could be applicable in the readthedocs.com site. There, we will need to support:
Anyway, I was checking if we could advance in one of those point in this PR but it seems that we won't be able to do this yet. Currently, this is only useful for private installations of RTD source code. |
@humitos tox organization has a Indeed this PR is useful for private installations of RTD. We can look into supporting more part of further subsequent PRs. I don't have access to multiple instances of these, hence why was not focusing on taking a look at it. But most likely it's something that can be done. Additionally made the required change (this way we keep previous settings - from .dev import CommunityDevSettings
_SETTINGS = CommunityDevSettings()
SOCIALACCOUNT_PROVIDERS = _SETTINGS.SOCIALACCOUNT_PROVIDERS
SOCIALACCOUNT_PROVIDERS['github']['GITHUB_URL'] == '{{github_url}}' Part of a future PR we may want to make the PS. Also did rebase on current master, hence the change in commit hash here. |
…l remove the github.com integration
readthedocs/oauth/services/github.py
Outdated
@@ -28,7 +28,7 @@ class GitHubService(Service): | |||
|
|||
adapter = GitHubOAuth2Adapter | |||
# TODO replace this with a less naive check | |||
url_pattern = re.compile(r'github\.com') | |||
url_pattern = re.compile(re.escape(GitHubOAuth2Adapter.web_url)) |
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 just realized that we can simply use self.adapter
in all this class.
(it's the common usage for all the services implemented in RTD)
@humitos done |
@gaborbernat nice! Thanks. There is a linting error, could you check it? To me, this PR is ready for merge. Let's wait for another core team member to review it -- @agjohnson was interested on these changes also. |
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
@humitos fixed 😄 |
@core ping 👍 |
You're heard, @gaborbernat. Four days (and over the weekend) isn't a lot of time for us - we'll get to this when we can. |
I'm happy that someone is able to take this on. Thanks for the contribution @gaborbernat ! I'll have more feedback when I can focus on this more, but for starters: this is touching a lot of important code and has no tests. So, fixing that is a good place to continue this work. I'm going to target a future release, as this isn't quite on our roadmap. I think this is mostly close though. Apologies for any delays responding, off-roadmap PRs have lower priority for us. |
Just an update. I definitely plan to continue to work on this. Just other things have come up. The fact that the actual code has not tests at the moment means I first need to figure out how this part is intended to be tested. Which makes picking up this non-trivial. |
Due to lack of resource for working on this, I'll need to retract this PR. Thanks for the collaboration guys. |
@gaborbernat Thanks for letting us know, and for your work, even if it wasn't merged in the end. :) |
This solves #2194.
This change is