-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Projects: create integration for GitHub App projects #12322
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c761af6
Projects: create integration for GitHub App projects
stsewd e9eda5e
Always link to app
stsewd b1f6648
Don't link, that would be confusing
stsewd 042ffd3
This isn't for linking
stsewd adcca9b
Updates from review
stsewd 1e7acd7
Fix migration
stsewd deed4e2
Update readthedocs/integrations/models.py
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
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
31 changes: 31 additions & 0 deletions
31
readthedocs/projects/migrations/0152_create_gh_app_integration.py
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,31 @@ | ||
# Generated by Django 5.2.3 on 2025-07-14 20:18 | ||
from django.db import migrations | ||
from django_safemigrate import Safe | ||
|
||
|
||
def forwards_func(apps, schema_editor): | ||
"""Create GitHub App integration for projects connected to a GitHub App.""" | ||
Project = apps.get_model("projects", "Project") | ||
for project in Project.objects.filter(remote_repository__vcs_provider="githubapp"): | ||
integration, _ = project.integrations.get_or_create( | ||
integration_type="githubapp", | ||
) | ||
remote_repo = project.remote_repository | ||
installation = project.remote_repository.github_app_installation | ||
integration.provider_data = { | ||
"installation_id": installation.installation_id, | ||
"repository_id": remote_repo.remote_id, | ||
"repository_full_name": remote_repo.full_name, | ||
} | ||
stsewd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
integration.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
safe = Safe.after_deploy() | ||
dependencies = [ | ||
("projects", "0151_addons_linkpreviews_selector"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(forwards_func), | ||
] |
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,47 @@ | ||
from django.contrib.auth.models import User | ||
from django.test import TestCase | ||
from django_dynamic_fixture import get | ||
from readthedocs.integrations.models import Integration | ||
from readthedocs.oauth.constants import GITHUB, GITHUB_APP | ||
from readthedocs.oauth.models import GitHubAppInstallation, RemoteRepository | ||
from readthedocs.projects.models import Project | ||
|
||
|
||
class TestProjectSignals(TestCase): | ||
def setUp(self): | ||
self.user = get(User) | ||
self.project = get(Project, users=[self.user]) | ||
|
||
def test_create_github_app_integration(self): | ||
github_repo = get( | ||
RemoteRepository, | ||
vcs_provider=GITHUB, | ||
) | ||
github_app_repo = get( | ||
RemoteRepository, | ||
vcs_provider=GITHUB_APP, | ||
github_app_installation=get(GitHubAppInstallation) | ||
) | ||
|
||
assert not self.project.is_github_app_project | ||
assert not self.project.integrations.exists() | ||
|
||
# Not a GitHub App repository, no integration created. | ||
self.project.remote_repository = github_repo | ||
self.project.save() | ||
assert not self.project.is_github_app_project | ||
assert not self.project.integrations.exists() | ||
|
||
# Now set the remote repository to a GitHub App repository. | ||
self.project.remote_repository = github_app_repo | ||
self.project.save() | ||
assert self.project.is_github_app_project | ||
integration = self.project.integrations.first() | ||
assert integration.integration_type == Integration.GITHUBAPP | ||
|
||
# Even if the connection is removed, the integration should still exist. | ||
self.project.remote_repository = None | ||
self.project.save() | ||
assert not self.project.is_github_app_project | ||
integration = self.project.integrations.first() | ||
assert integration.integration_type == Integration.GITHUBAPP |
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
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.