Skip to content

Commit

Permalink
Minor fix (#2938)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlu1248 authored Jan 12, 2024
1 parent 99ef7b8 commit 177f4f7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ services:
# network_mode: "host"
volumes:
- .:/app
ports:
- "${PORT:-8080}:${PORT:-8080}"
command: >
sh -c ". bin/startup.sh"
stdin_open: true
Expand Down
24 changes: 16 additions & 8 deletions sweepai/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
import os
import time
from itertools import chain, islice

from github import Github
from github.Event import Event
Expand All @@ -11,6 +12,8 @@
from sweepai.api import handle_request
from sweepai.utils.event_logger import logger

DEBUG = os.environ.get("DEBUG", False)


def pascal_to_snake(name):
return "".join(["_" + i.lower() if i.isupper() else i for i in name]).lstrip("_")
Expand All @@ -25,32 +28,37 @@ def get_event_type(event: Event | IssueEvent):

def stream_events(repo: Repository, timeout: int = 2, offset: int = 2 * 60):
processed_event_ids = set()
all_events = []
all_events += list(repo.get_events())
all_events += list(repo.get_issues_events())

current_time = time.time() - offset
local_tz = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo

while True:
all_events = []
all_events += list(repo.get_events())
all_events += list(repo.get_issues_events())
for event in all_events[::-1]:
events_iterator = chain(
repo.get_events(), islice(repo.get_issues_events(), 100)
)
for event in events_iterator:
if event.id not in processed_event_ids:
local_time = event.created_at.replace(
tzinfo=datetime.timezone.utc
).astimezone(local_tz)

if local_time.timestamp() > current_time:
yield event
else:
if DEBUG:
logger.debug(
f"Skipping event {event.id} because it is too old ({local_time})"
)
if DEBUG:
logger.debug(f"Skipping event {event.id} because it is already handled")
processed_event_ids.add(event.id)
time.sleep(timeout)


g = Github(os.environ["GITHUB_PAT"])
repo_name = os.environ["REPO"]
repo = g.get_repo(repo_name)
if DEBUG:
logger.debug("Debug mode enabled")
print(f"Starting server, listening to events from {repo_name}...")
print(
f"To create a PR, please create an issue at https://github.com/{repo_name}/issues with a title prefixed with 'Sweep:'"
Expand Down
25 changes: 25 additions & 0 deletions tests/monitor_prod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import time

from github import Github

g = Github(os.environ.get("GITHUB_PAT"))
issue_url = "https://github.com/wwzeng1/landing-page/issues/206"
issue = g.get_repo("wwzeng1/landing-page").get_issue(206)

comment_id = list(issue.get_comments())[0].id

while True:
comment = issue.get_comment(comment_id)
body = comment.body
start_time = time.time()
print(f"Editing comment {comment_id}...")
comment.edit(body=body.replace("- [ ] ↻ Restart Sweep", "- [x] ↻ Restart Sweep"))
for i in range(60):
comment = issue.get_comment(comment_id)
print(f"Checking comment... ({time.time() - start_time:.2f})")
if "- [ ] ↻ Restart Sweep" in comment.body:
print(f"Got a response in {time.time() - start_time:.2f} seconds")
break
time.sleep(2)
time.sleep(1)

0 comments on commit 177f4f7

Please sign in to comment.