Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshinishio committed Jul 4, 2024
1 parent edd83cd commit f7803ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions scheduler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This is scheduled to run by AWS Lambda"""

import logging
import time
from config import PRODUCT_ID, SUPABASE_SERVICE_ROLE_KEY, SUPABASE_URL
from services.github.github_manager import (
add_label_to_issue,
Expand All @@ -22,6 +23,10 @@ def schedule_handler(_event, _context) -> dict[str, int]:

# Get all owners and repositories from GitHub.
for installation_id in installation_ids:
# Pause for 1+ second to avoid secondary rate limits. https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api?apiVersion=2022-11-28#pause-between-mutative-requests
time.sleep(1)

# Start processing this loop.
token: str = get_installation_access_token(installation_id=installation_id)
owners_repos: list[dict[str, str]] = get_installed_owners_and_repos(
installation_id=installation_id, token=token
Expand Down Expand Up @@ -51,6 +56,7 @@ def schedule_handler(_event, _context) -> dict[str, int]:
issue_number = issue["number"]

# Label the issue with the product ID to trigger GitAuto.
time.sleep(1)
add_label_to_issue(
owner=owner,
repo=repo,
Expand Down
6 changes: 3 additions & 3 deletions services/github/github_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@ def initialize_repo(repo_path: str, remote_url: str) -> None:
def get_installation_access_token(installation_id: int) -> str:
"""https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#create-an-installation-access-token-for-an-app"""
jwt_token: str = create_jwt()
headers: dict[str, str] = create_headers(token=jwt_token)
url = f"{GITHUB_API_URL}/app/installations/{installation_id}/access_tokens"
response: requests.Response = requests.post(
url=url, headers=headers, timeout=TIMEOUT_IN_SECONDS
url=f"{GITHUB_API_URL}/app/installations/{installation_id}/access_tokens",
headers=create_headers(token=jwt_token),
timeout=TIMEOUT_IN_SECONDS,
)
response.raise_for_status()
return response.json()["token"]
Expand Down

0 comments on commit f7803ec

Please sign in to comment.