-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgithub_installation.py
33 lines (28 loc) · 1.07 KB
/
github_installation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import logging
from database.models.core import (
GITHUB_APP_INSTALLATION_DEFAULT_NAME,
Owner,
OwnerInstallationNameToUseForTask,
)
log = logging.getLogger(__file__)
def get_installation_name_for_owner_for_task(task_name: str, owner: Owner) -> str:
if owner.service not in ["github", "github_enterprise"]:
# The `installation` concept only exists in GitHub.
# We still return a default here, primarily to satisfy types.
return GITHUB_APP_INSTALLATION_DEFAULT_NAME
dbsession = owner.get_db_session()
config_for_owner = (
dbsession.query(OwnerInstallationNameToUseForTask)
.filter(
OwnerInstallationNameToUseForTask.task_name == task_name,
OwnerInstallationNameToUseForTask.ownerid == owner.ownerid,
)
.first()
)
if config_for_owner:
log.info(
"Owner has dedicated app for this task",
extra=dict(this_task=task_name, ownerid=owner.ownerid),
)
return config_for_owner.installation_name
return GITHUB_APP_INSTALLATION_DEFAULT_NAME