Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.

Commit a6961ff

Browse files
committed
feat: Enhance GitHub App functionality with improved error logging and API versioning
1 parent 46e3367 commit a6961ff

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

infra/terraform/main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ resource "google_artifact_registry_repository" "app" {
8282
}
8383

8484
# Cloud Run service for the GitHub App (deployed only if image is provided)
85+
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_v2_service#attributes-reference
8586
resource "google_cloud_run_v2_service" "app" {
86-
count = local.deploy_app ? 1 : 0
87-
name = var.service_name
88-
location = var.region
89-
87+
count = local.deploy_app ? 1 : 0
88+
name = var.service_name
89+
location = var.region
90+
deletion_protection = false
9091
template {
9192
service_account = google_service_account.app.email
9293

@@ -177,7 +178,7 @@ resource "google_api_gateway_api_config" "webhook" {
177178
document {
178179
path = "${path.module}/api-config.yaml"
179180
contents = base64encode(templatefile("${path.module}/api-config.yaml", {
180-
service_url = google_cloud_run_v2_service.app[0].uri
181+
service_url = "https://${var.service_name}-${data.google_project.project.number}.${var.region}.run.app"
181182
}))
182183
}
183184
}

src/github_app.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44
import jwt
55
import requests
6+
import logging
67

78
from src.config import get_env, normalize_private_key
89
from src.config import get_secret
910

1011
GITHUB_API = "https://api.github.com"
12+
logger = logging.getLogger("github-app")
13+
GITHUB_API_VERSION = "2022-11-28"
1114

1215

1316
def create_app_jwt() -> str:
@@ -29,8 +32,16 @@ def get_installation_token(installation_id: int) -> Dict[str, str]:
2932
headers = {
3033
"Authorization": f"Bearer {token}",
3134
"Accept": "application/vnd.github+json",
35+
"User-Agent": "ons-github-app",
36+
"X-GitHub-Api-Version": GITHUB_API_VERSION,
3237
}
3338
response = requests.post(url, headers=headers, timeout=10)
39+
if not response.ok:
40+
logger.error(
41+
"GitHub installation token request failed status=%s body=%s",
42+
response.status_code,
43+
response.text,
44+
)
3445
response.raise_for_status()
3546
data = response.json()
3647
return {"token": data["token"], "expires_at": data["expires_at"]}
@@ -42,8 +53,18 @@ def post_pr_comment(*, installation_id: int, repo_full_name: str, pr_number: int
4253
token = get_installation_token(installation_id)["token"]
4354
url = f"{GITHUB_API}/repos/{repo_full_name}/issues/{pr_number}/comments"
4455
headers = {
45-
"Authorization": f"token {token}",
56+
"Authorization": f"Bearer {token}",
4657
"Accept": "application/vnd.github+json",
58+
"User-Agent": "ons-github-app",
59+
"X-GitHub-Api-Version": GITHUB_API_VERSION,
4760
}
4861
response = requests.post(url, headers=headers, json={"body": body}, timeout=10)
62+
if not response.ok:
63+
logger.error(
64+
"GitHub post comment failed repo=%s pr=%s status=%s body=%s",
65+
repo_full_name,
66+
pr_number,
67+
response.status_code,
68+
response.text,
69+
)
4970
response.raise_for_status()

0 commit comments

Comments
 (0)