Skip to content

Commit 2154c2f

Browse files
authored
GitHub App: check if installation exists for target account (#12449)
Needed for readthedocs/ext-theme#647
1 parent c18cccf commit 2154c2f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

readthedocs/oauth/migrate.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""This module contains the logic to help users migrate from the GitHub OAuth App to the GitHub App."""
22

33
from dataclasses import dataclass
4+
from functools import cached_property
45
from typing import Iterator
56
from urllib.parse import urlencode
67

@@ -14,6 +15,7 @@
1415
from readthedocs.oauth.constants import GITHUB
1516
from readthedocs.oauth.constants import GITHUB_APP
1617
from readthedocs.oauth.models import GitHubAccountType
18+
from readthedocs.oauth.models import GitHubAppInstallation
1719
from readthedocs.oauth.models import RemoteRepository
1820
from readthedocs.oauth.services import GitHubAppService
1921
from readthedocs.oauth.services import GitHubService
@@ -30,6 +32,13 @@ class GitHubAccountTarget:
3032
avatar_url: str
3133
profile_url: str
3234

35+
@cached_property
36+
def has_installation(self) -> bool:
37+
"""Check if the GitHub App is installed in this account."""
38+
return GitHubAppInstallation.objects.filter(
39+
target_id=self.id, target_type=self.type
40+
).exists()
41+
3342

3443
@dataclass
3544
class InstallationTargetGroup:

0 commit comments

Comments
 (0)