-
Notifications
You must be signed in to change notification settings - Fork 0
/
const.py
57 lines (48 loc) · 1.62 KB
/
const.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
from dotenv import load_dotenv
from github import GithubIntegration
from github.Repository import Repository
from loguru import logger
from core.credit import CreditFetcher
from core.mongo import IssueOperation, global_client
from core.utils import get_repo_setting
from core.webhook.handler import GithubWebhookHandler
from settings.server import ServerSetting
load_dotenv()
webhook_handler = GithubWebhookHandler()
webhook_handler.debug = bool(os.getenv("DEBUG"))
if webhook_handler.debug:
print("Debug mode enabled")
git_integration = GithubIntegration(
integration_id=ServerSetting.github_app_id,
private_key=ServerSetting.github_private_key.get_secret_value(),
user_agent="pygithub/Python",
)
async def get_credentials(repo_name, repo: Repository):
return await CreditFetcher.get(
repo_setting=get_repo_setting(
repo_name=repo_name,
repo=repo
),
dash_api=ServerSetting.dashboard_api_url,
token_secret=ServerSetting.token_secret
)
async def fetch_operation(
issue_id: int, repo_name: str
):
try:
saved_issue = await global_client.find_one(
IssueOperation,
IssueOperation.issue_id == issue_id, # noqa
IssueOperation.repo_name == repo_name # noqa
)
if not saved_issue:
saved_issue = IssueOperation(
issue_id=issue_id,
repo_name=repo_name,
)
await global_client.save(saved_issue)
return saved_issue
except Exception as e:
logger.error(f"Failed to save issue operation: {e}")
return None