-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Migrate GitHub OAuth App to GitHub App #11942
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
Closed
Closed
Changes from 14 commits
Commits
Show all changes
111 commits
Select commit
Hold shift + click to select a range
926f95d
Migrate GitHub OAuth App to GitHub App
stsewd 9c5746c
Merge branch 'main' into migrate-to-gh-apps
stsewd 1314a9c
wip
stsewd 22de5d6
Migration and stuff
stsewd 5119e48
Fixes
stsewd a854c7e
More hooks!
stsewd 7235cd8
Bug fixes and refactor
stsewd 632e2e5
Format
stsewd b0e2181
More events
stsewd ba47293
Merge branch 'main' into migrate-to-gh-apps
stsewd 91d23aa
More hooks and fixes
stsewd ddadee1
Implement members hook
stsewd 2c4c0cc
Dead code
stsewd 3c61db6
Delete code
stsewd 88b0021
Poor man implementation
stsewd 2987cf8
Merge branch 'main' into migrate-to-gh-apps
stsewd ad5655e
Stash
stsewd fa53c1c
Git service: depend on the project instead of users
stsewd f031b4b
Fix name
stsewd f7a3917
Fix tests
stsewd 083cfa0
Small updates
stsewd 8e6caa3
Format
stsewd 4671a46
Merge branch 'refactor-services' into migrate-to-gh-apps
stsewd 6d686f3
Format
stsewd d771092
Refactor
stsewd 0d0511c
Fix import
stsewd 4308bbf
Check for None
stsewd 7065003
refactor
stsewd b2a8a2b
Fix import
stsewd b0d9dcc
Full feature!
stsewd 54e7ec6
More refactor
stsewd 4d5a229
More fixes and updates
stsewd 12aab79
Docstrings and updates
stsewd c2ffe7d
Note on GH user access tokens
stsewd 56b024f
Remove code
stsewd c09186b
Error handling and logging
stsewd 0b2c686
Validate when trying to connect to an existing account
stsewd a7f1cb7
Less indentation
stsewd 50637b5
And both apps lived happy forever after.
stsewd 7fc1466
Updates from review
stsewd 27ad8c6
Skip incompatible integrations
stsewd 6ea1655
Format
stsewd 5daf4da
Check for attribute instead
stsewd 8e73ab4
Fix querysets
stsewd 1289298
Git service: attach each service to a allauth provider
stsewd 5319608
Missed this file
stsewd c9eb355
Use just the hostname for the base_api_url
stsewd c7b259b
Merge branch 'abstract-allauth-from-services' into migrate-to-gh-apps
stsewd e031477
Stash
stsewd bf5014c
Merge branch 'main' into migrate-to-gh-apps
stsewd 6165e4c
Format
stsewd 37738df
stash
stsewd 160d41f
Merge branch 'main' into migrate-to-gh-apps
stsewd cd5015c
Basic migration page
stsewd f67e028
Don't use the ID to get the organization
stsewd 933658c
Docstring
stsewd 346cc34
Fix template
stsewd cac9567
Cleanup
stsewd db1950f
More updates
stsewd 75cc864
Merge branch 'main' into migrate-to-gh-apps
stsewd 87dad06
Merge branch 'main' into migrate-to-gh-apps
stsewd 4b84536
Check for githuapp
stsewd 3899104
Uninstalling the app from a repository, means unlinking it from the p…
stsewd acfda4c
Format
stsewd d1e3cb4
Add a sync repositories permissions method
stsewd de06013
Merge branch 'main' into migrate-to-gh-apps
stsewd b3ad1a2
Add tests for webhook
stsewd 3fb1083
Stash
stsewd 34052b3
Merge branch 'main' into migrate-to-gh-apps
stsewd c5ea8a1
Merge branch 'main' into migrate-to-gh-apps
stsewd eacf058
Tests
stsewd 33d6151
Merge branch 'main' into migrate-to-gh-apps
stsewd 619858c
Tests
stsewd 80e6c88
More tests
stsewd 926ed6d
Tests for tasks
stsewd 0c338ab
stash
stsewd 616166e
Format to avoid conflicts
stsewd 2c81a2a
Merge branch 'main' into migrate-to-gh-apps
stsewd b58c3b8
Format
stsewd d106277
Update migration
stsewd c2a89d7
Remove suspended installations
stsewd 7fffcea
Delete installation when suspended
stsewd 0adc4b4
Handle authorization event
stsewd 7e3f3f4
Tests
stsewd 5c1ce0b
Merge branch 'main' into migrate-to-gh-apps
stsewd fa1b70c
Small changes
stsewd 339cf73
Complete migrate view
stsewd 7ff1e96
Create notifications when an error happens during the migration
stsewd 9b14e95
Fixes
stsewd 704ecb4
Check for users with multiple GH accounts
stsewd 19dc240
Better default for accounts linked to multiple GH accounts
stsewd 5a5d532
Rollback changes to avoid merge conflicts
stsewd 26ef7eb
Re-add pygithub
stsewd 34ddb25
Merge branch 'main' into migrate-to-gh-apps
stsewd 33893de
Clean up and docstrings
stsewd 5964ff1
Merge branch 'main' into migrate-to-gh-apps
stsewd 8f23fa4
Docs about local dev
stsewd 192f3ac
Add tests for migration page
stsewd 66fdd95
Merge branch 'main' into migrate-to-gh-apps
stsewd 08f9d2c
Fix merge conflict
stsewd ce6c2da
Match changes
stsewd c489137
Decouple migration from current GH account
stsewd 3a88a62
More decoupling
stsewd 928984b
Very WIP docs
stsewd 6227ea3
Update docs
stsewd c962205
Add old_github_accounts so we can use it as a listing
stsewd 6c5eefb
Add type
stsewd 60a5228
Merge branch 'main' into migrate-to-gh-apps
stsewd f2d5498
Fix merge conflicts
stsewd 34d7ed6
Format
stsewd 225c640
Fix reference
stsewd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from allauth.socialaccount.providers.github.provider import GitHubProvider | ||
|
||
from readthedocs.allauth.providers.githubapp.views import GitHubAppOAuth2Adapter | ||
|
||
|
||
class GitHubAppProvider(GitHubProvider): | ||
id = "githubapp" | ||
name = "GitHub App" | ||
oauth2_adapter_class = GitHubAppOAuth2Adapter | ||
|
||
|
||
provider_classes = [GitHubAppProvider] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns | ||
|
||
from readthedocs.allauth.providers.githubapp.provider import GitHubAppProvider | ||
|
||
urlpatterns = default_urlpatterns(GitHubAppProvider) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter | ||
from allauth.socialaccount.providers.oauth2.views import ( | ||
OAuth2CallbackView, | ||
OAuth2LoginView, | ||
) | ||
|
||
|
||
class GitHubAppOAuth2Adapter(GitHubOAuth2Adapter): | ||
provider_id = "githubapp" | ||
|
||
|
||
oauth2_login = OAuth2LoginView.adapter_view(GitHubAppOAuth2Adapter) | ||
oauth2_callback = OAuth2CallbackView.adapter_view(GitHubAppOAuth2Adapter) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 4.2.18 on 2025-02-03 21:58 | ||
from django_safemigrate import Safe | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django_extensions.db.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
safe = Safe.before_deploy | ||
|
||
dependencies = [ | ||
('oauth', '0016_deprecate_old_vcs'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='GitHubAppInstallation', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')), | ||
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')), | ||
('installation_id', models.PositiveBigIntegerField(db_index=True, help_text='The application installation ID', unique=True)), | ||
('target_id', models.PositiveBigIntegerField(help_text='A GitHub account ID, it can be from a user or an organization')), | ||
('target_type', models.CharField(choices=[('User', 'User'), ('Organization', 'Organization')], help_text='Account type that the target_id belongs to (user or organization)', max_length=255)), | ||
('extra_data', models.JSONField(default=dict, help_text='Extra data returned by the webhook when the installation is created')), | ||
], | ||
options={ | ||
'get_latest_by': 'modified', | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='remoterepository', | ||
name='github_app_installation', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='repositories', to='oauth.githubappinstallation', verbose_name='GitHub App Installation'), | ||
), | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.