Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Count on Issue labeled, removed unecessary get_installation_id function, and disabled Sentry in local env #39

Merged
merged 9 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
# Create FastAPI instance
app = FastAPI()

sentry_sdk.init(
if(ENV != "local"):
sentry_sdk.init(
"https://b7ca4effebf7d7825b6464eade11734f@o4506827828101120.ingest.us.sentry.io/4506865231200256",
environment=ENV,
integrations=[AwsLambdaIntegration()],
traces_sample_rate=1.0
)
)

handler = Mangum(app=app)

Expand Down
Binary file modified requirements.txt
Binary file not shown.
16 changes: 10 additions & 6 deletions services/supabase/supabase_manager.py
Copy link
Collaborator

@hiroshinishio hiroshinishio Mar 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. If it involves database changes, I would like to be able to see it in the PR.
  2. Also, we need to ensure that the changes are included in the production DB along with the PR, or it will cause production errors. Is there a good way to ensure this?
  3. Also, this would out-date everyone's dev and stg environments in Supabase except who raised this PR. We can handle that right now, but is there a better way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no DB change, that's why I am doing requests only and i/o of tokens later. I think for your #3 it makes sense to migrate right before deploying. If it's a breaking DB change, we can set aside a time when no one is using our product to implement those changes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? I don't think requests and invoice_no columns existed before...

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
from supabase import create_client, Client

import logging

# Manager class to handle installation tokens
class InstallationTokenManager:
Expand Down Expand Up @@ -29,12 +29,16 @@ def save_installation_token(
"repository_ids": repository_ids,
}).execute()

def get_installation_id(self, repository_id: int) -> str:
data, _ = self.client.table(table_name="repo_info").select("installation_id").contains(column='repository_ids', value=[str(object=repository_id)]).execute()
if (data[1] and data[0][1]):
return data[1][0].get('installation_id')
raise RuntimeError("Installation ID for this repo not found.")

def delete_installation_token(self, installation_id: int) -> None:
data: dict[str, str] = {"deleted_at": datetime.datetime.utcnow().isoformat()}
self.client.table(table_name="repo_info").update(json=data).eq(column="installation_id", value=installation_id).execute()

def increment_request_count(self, installation_id: int) -> None:
try:
data, _ = self.client.table(table_name="repo_info").select("*").eq(column="installation_id", value=installation_id).execute()
if (data[1] and data[1][0]):
self.client.table(table_name="repo_info").update(json={"requests": data[1][0]['requests'] + 1}).eq(column="installation_id", value=installation_id).execute()
except Exception as e:
logging.error(msg=f"Increment Request Count Error: {e}")

6 changes: 4 additions & 2 deletions services/webhook_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ async def handle_issue_labeled(payload: GitHubLabeledPayload):
owner: str = repo["owner"]["login"]
repo_name: str = repo["name"]
base_branch: str = repo["default_branch"]

# Get the installation token and the remote file tree
# Prepare token and file tree for Agent
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
Expand Down Expand Up @@ -135,6 +135,8 @@ async def handle_issue_labeled(payload: GitHubLabeledPayload):
token=token
)
print(f"{time.strftime('%H:%M:%S', time.localtime())} Pull request created.\n")

supabase_manager.increment_request_count(installation_id=installation_id)

return

Expand Down
Loading