Skip to content

Commit

Permalink
Merge pull request #379 from gitautoai/wes
Browse files Browse the repository at this point in the history
Fix a 404 error in get_workflow_run_path()
  • Loading branch information
hiroshinishio authored Nov 18, 2024
2 parents 81b02f9 + 24eff0e commit 21e4879
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
12 changes: 7 additions & 5 deletions services/check_run_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Repository,
)
from services.github.pulls_manager import get_pull_request, get_pull_request_files
from services.github.utils import create_permission_url
from services.openai.commit_changes import chat_with_agent
from services.openai.chat import chat_with_ai
from services.openai.instructions.identify_cause import IDENTIFY_CAUSE
Expand Down Expand Up @@ -144,6 +145,12 @@ def handle_check_run(payload: CheckRunCompletedPayload) -> None:
workflow_path = get_workflow_run_path(
owner=owner_name, repo=repo_name, run_id=workflow_run_id, token=token
)
permission_url = create_permission_url(
owner_type=owner_type, owner_name=owner_name, installation_id=installation_id
)
if workflow_path == 404:
comment_body = f"Approve permission(s) to allow GitAuto to access the check run logs here: {permission_url}"
return update_comment(body=comment_body, base_args=base_args)
workflow_content = get_remote_file_content(
file_path=workflow_path, base_args=base_args
)
Expand All @@ -160,11 +167,6 @@ def handle_check_run(payload: CheckRunCompletedPayload) -> None:
owner=owner_name, repo=repo_name, run_id=workflow_run_id, token=token
)
if error_log == 404:
permission_url = (
f"https://github.com/organizations/{owner_name}/settings/installations/{installation_id}/permissions/update"
if owner_type == "Organization"
else f"https://github.com/settings/installations/{installation_id}/permissions/update"
)
comment_body = f"Approve permission(s) to allow GitAuto to access the check run logs here: {permission_url}"
return update_comment(body=comment_body, base_args=base_args)
if error_log is None:
Expand Down
6 changes: 6 additions & 0 deletions services/github/actions_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def get_failed_step_log_file_name(owner: str, repo: str, run_id: int, token: str
url = f"{GITHUB_API_URL}/repos/{owner}/{repo}/actions/runs/{run_id}/jobs"
headers = create_headers(token=token)
response = requests.get(url=url, headers=headers, timeout=TIMEOUT)
if response.status_code == 404 and "Not Found" in response.text:
return response.status_code
response.raise_for_status()
data = response.json()

Expand All @@ -33,6 +35,8 @@ def get_workflow_run_path(owner: str, repo: str, run_id: int, token: str):
url = f"{GITHUB_API_URL}/repos/{owner}/{repo}/actions/runs/{run_id}"
headers = create_headers(token=token)
response = requests.get(url=url, headers=headers, timeout=TIMEOUT)
if response.status_code == 404 and "Not Found" in response.text:
return response.status_code
response.raise_for_status()
json = response.json()
path: str = json["path"]
Expand All @@ -53,6 +57,8 @@ def get_workflow_run_logs(owner: str, repo: str, run_id: int, token: str):
failed_step_fname = get_failed_step_log_file_name(
owner=owner, repo=repo, run_id=run_id, token=token
)
if failed_step_fname == 404:
return failed_step_fname

# Read the content of the zip file
with zipfile.ZipFile(io.BytesIO(response.content)) as zf:
Expand Down
11 changes: 11 additions & 0 deletions services/github/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from typing import Literal


def create_permission_url(
owner_type: Literal["Organization", "User"], owner_name: str, installation_id: int
):
url_base = "https://github.com"
url_part = f"settings/installations/{installation_id}/permissions/update"
if owner_type == "Organization":
return f"{url_base}/organizations/{owner_name}/{url_part}"
return f"{url_base}/{url_part}"

0 comments on commit 21e4879

Please sign in to comment.