Skip to content

Commit

Permalink
Merge branch 'main' into nikita-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitamalinov authored Mar 9, 2024
2 parents 5f5fc31 + 2f0e96f commit ba486b9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: local
hooks:
- id: pip-freeze
name: pip freeze
entry: bash -c 'pip freeze > requirements.txt && git add requirements.txt'
language: system
always_run: true
stages: [pre-commit]
Binary file modified README.md
Binary file not shown.
Binary file modified requirements.txt
Binary file not shown.
21 changes: 20 additions & 1 deletion services/github/github_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import time
from typing import Any
from uuid import UUID

# Third-party imports
import jwt # For generating JWTs (JSON Web Tokens)
Expand Down Expand Up @@ -165,6 +164,26 @@ def get_installation_access_token(installation_id: int) -> str:
raise


def get_issue_comments(owner: str, repo: str, issue_number: int, token: str) -> list[str]:
""" https://docs.github.com/en/rest/issues/comments#list-issue-comments """
try:
response = requests.get(
url=f"https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}/comments",
headers=create_headers(token=token),
timeout=TIMEOUT_IN_SECONDS
)
response.raise_for_status()
comments = response.json()
comment_texts: list[str] = [comment['body'] for comment in comments]
return comment_texts
except requests.exceptions.HTTPError as e:
logging.error(msg=f"HTTP Error: {e.response.status_code} - {e.response.text}")
raise
except Exception as e:
logging.error(msg=f"Error: {e}")
raise


def get_latest_remote_commit_sha(owner: str, repo: str, branch: str, token: str) -> str:
""" SHA stands for Secure Hash Algorithm. It's a unique identifier for a commit.
https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#get-a-reference """
Expand Down
10 changes: 7 additions & 3 deletions services/webhook_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
create_pull_request,
create_remote_branch,
get_installation_access_token,
get_issue_comments,
get_latest_remote_commit_sha,
get_remote_file_tree
)
Expand Down Expand Up @@ -65,18 +66,21 @@ async def handle_issue_labeled(payload: GitHubLabeledPayload):
issue: IssueInfo = payload["issue"]
issue_title: str = issue["title"]
issue_body: str = issue["body"] or ""
issue_comments: list[str] = [""]
issue_number: int = issue["number"]
installation_id: int = payload["installation"]["id"]
repo: RepositoryInfo = payload["repository"]
owner: str = repo["owner"]["login"]
repo_name: str = repo["name"]
base_branch: str = repo["default_branch"]

# Clone the repository
# Get the installation token and the remote file tree
token: str = get_installation_access_token(installation_id=installation_id)
file_paths: list[str] = get_remote_file_tree(
owner=owner, repo=repo_name, ref=base_branch, token=token
)
issue_comments: list[str] = get_issue_comments(
owner=owner, repo=repo_name, issue_number=issue_number, token=token
)
print(f"{time.strftime('%H:%M:%S', time.localtime())} Installation token received.\n")

diffs: list[str] = run_assistant(
Expand Down Expand Up @@ -137,7 +141,7 @@ async def handle_issue_labeled(payload: GitHubLabeledPayload):

async def handle_webhook_event(payload: GitHubEventPayload) -> None:
""" Determine the event type and call the appropriate handler """
action = payload.get("action")
action: str = payload.get("action")
if not action:
return

Expand Down

0 comments on commit ba486b9

Please sign in to comment.