Skip to content

Commit

Permalink
addressing comments made by Wes on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
BigOleHealz committed Oct 28, 2024
1 parent 6c00947 commit 0eb0f57
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
6 changes: 3 additions & 3 deletions services/gitauto_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

supabase_manager = SupabaseManager(url=SUPABASE_URL, key=SUPABASE_SERVICE_ROLE_KEY)


async def handle_gitauto(payload: GitHubLabeledPayload, trigger_type: str) -> None:
"""Core functionality to create comments on issue, create PRs, and update progress."""
current_time: float = time.time()
Expand Down Expand Up @@ -84,12 +85,13 @@ async def handle_gitauto(payload: GitHubLabeledPayload, trigger_type: str) -> No
sender_id: int = payload["sender"]["id"]
is_automation: bool = sender_id == GITHUB_APP_USER_ID
sender_name: str = payload["sender"]["login"]
email: str = get_user_public_email(username=sender_name)

# Extract other information
github_urls, other_urls = extract_urls(text=issue_body)
installation_id: int = payload["installation"]["id"]
token: str = get_installation_access_token(installation_id=installation_id)
email: str | None = get_user_public_email(username=sender_name, token=token)

base_args: BaseArgs = {
"owner": owner_name,
"repo": repo_name,
Expand Down Expand Up @@ -255,7 +257,5 @@ async def handle_gitauto(payload: GitHubLabeledPayload, trigger_type: str) -> No
token_input=token_input,
token_output=token_output,
total_seconds=int(end_time - current_time),
user_id=sender_id,
email=email,
)
return
20 changes: 9 additions & 11 deletions services/github/github_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def create_comment_on_issue_with_gitauto_button(payload: GitHubLabeledPayload) -
issue_number: int = payload["issue"]["number"]
user_id: int = payload["sender"]["id"]
user_name: str = payload["sender"]["login"]
email: str = get_user_public_email(username=user_name)
email: str | None = get_user_public_email(username=user_name, token=token)

supabase_manager = SupabaseManager(url=SUPABASE_URL, key=SUPABASE_SERVICE_ROLE_KEY)

Expand Down Expand Up @@ -832,17 +832,15 @@ def update_comment_for_raised_errors(

raise RuntimeError("Error occurred")

@handle_exceptions(default_return_value=None, raise_on_error=False)
def get_user_public_email(username: str):
url = f"https://api.github.com/users/{username}"
headers = {
"Accept": "application/vnd.github.v3+json"
}

response: requests.Response = requests.get(url, headers=headers)
@handle_exceptions(default_return_value=None, raise_on_error=False)
def get_user_public_email(username: str, token: str) -> str | None:
response: requests.Response = requests.get(
url=f"{GITHUB_API_URL}/users/{username}",
headers=create_headers(token=token),
timeout=TIMEOUT,
)
response.raise_for_status()
user_data: dict = response.json()

email: str = user_data.get('email')

email: str | None = user_data.get('email')
return email
2 changes: 1 addition & 1 deletion services/supabase/gitauto_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def create_user_request(
.eq(column="unique_id", value=unique_issue_id)
.execute()
)
# If no issue exists with that unique_issue_id, create one
# If no issue exists with that unique_issue_id, create one
if not data[1]:
self.client.table(table_name="issues").insert(
json={
Expand Down
2 changes: 1 addition & 1 deletion services/webhook_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def handle_installation_created(payload: GitHubInstallationPayload) -> Non
user_id: int = payload["sender"]["id"]
user_name: str = payload["sender"]["login"]
token: str = get_installation_access_token(installation_id=installation_id)
email: str = get_user_public_email(username=user_name)
email: str | None = get_user_public_email(username=user_name, token=token)

# Create installation record in Supabase
supabase_manager.create_installation(
Expand Down
7 changes: 2 additions & 5 deletions tests/services/supabase/test_gitauto_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# run this file locally with: python -m tests.services.supabase.test_gitauto_manager
import os
from config import (EMAIL, OWNER_TYPE)
from config import EMAIL, OWNER_TYPE, USER_NAME
from services.supabase import SupabaseManager
from tests.services.supabase.wipe_data import (
wipe_installation_owner_user_data,
Expand All @@ -17,7 +17,7 @@ def test_create_update_user_request_works() -> None:
# using -1 to not conflict with real data
user_id = -1
installation_id = -1
user_name = "test"
user_name = USER_NAME

# Clean up at the beginning just in case a prior test failed to clean
wipe_installation_owner_user_data()
Expand Down Expand Up @@ -58,9 +58,6 @@ def test_create_update_user_request_works() -> None:
wipe_installation_owner_user_data()


# test_create_update_user_request_works()


def test_complete_and_update_usage_record_only_updates_one_record() -> None:
"""Tests based on creating a record and updating it in usage table"""
supabase_manager = SupabaseManager(url=SUPABASE_URL, key=SUPABASE_SERVICE_ROLE_KEY)
Expand Down
3 changes: 0 additions & 3 deletions tests/services/supabase/test_users_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ def test_create_and_update_user_request_works() -> None:
)


# test_create_and_update_user_request_works()


def test_how_many_requests_left() -> None:
"""Test that get_how_many_requests_left_and_cycle returns the correct values"""
supabase_manager = SupabaseManager(url=SUPABASE_URL, key=SUPABASE_SERVICE_ROLE_KEY)
Expand Down

0 comments on commit 0eb0f57

Please sign in to comment.