Wauplin HF staff commited on
Commit
e88d696
1 Parent(s): 421265e

should be better now

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. app.py +18 -11
Dockerfile CHANGED
@@ -12,5 +12,5 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt
12
 
13
  COPY --chown=user . .
14
 
15
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
16
 
 
12
 
13
  COPY --chown=user . .
14
 
15
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--log-level", "info"]
16
 
app.py CHANGED
@@ -64,7 +64,6 @@ async def post_webhook(
64
  task_queue: BackgroundTasks,
65
  x_webhook_secret: Optional[str] = Header(default=None),
66
  ):
67
- return
68
  logger.info("Received new hook!")
69
  if x_webhook_secret is None:
70
  logger.warning("HTTP 401: No webhook secret")
@@ -84,15 +83,19 @@ async def post_webhook(
84
  and payload.event.action == "create"
85
  and payload.discussion is not None
86
  and payload.discussion.isPullRequest
 
87
  ):
88
  # New PR!
89
- task_queue.add_task(
90
- sync_ci_space,
91
- space_id=space_id,
92
- pr_num=payload.discussion.num,
93
- private=payload.repo.private,
94
- )
95
- logger.info("New PR! Sync task scheduled")
 
 
 
96
  elif (
97
  payload.event.scope.startswith("discussion")
98
  and payload.event.action == "update"
@@ -117,7 +120,6 @@ async def post_webhook(
117
  for discussion in get_repo_discussions(
118
  repo_id=space_id, repo_type="space", token=HF_TOKEN
119
  ):
120
- break
121
  if discussion.is_pull_request and discussion.status == "open":
122
  if not is_pr_synced(space_id=space_id, pr_num=discussion.num):
123
  task_queue.add_task(
@@ -138,8 +140,13 @@ async def post_webhook(
138
  def is_pr_synced(space_id: str, pr_num: int) -> bool:
139
  # What is the last synced commit for this PR?
140
  ci_space_id = _get_ci_space_id(space_id=space_id, pr_num=pr_num)
141
- card = RepoCard.load(repo_id_or_path=ci_space_id, repo_type="space", token=HF_TOKEN)
142
- last_synced_sha = getattr(card.data, "synced_sha", None)
 
 
 
 
 
143
 
144
  # What is the last commit id for this PR?
145
  info = space_info(repo_id=space_id, revision=f"refs/pr/{pr_num}")
 
64
  task_queue: BackgroundTasks,
65
  x_webhook_secret: Optional[str] = Header(default=None),
66
  ):
 
67
  logger.info("Received new hook!")
68
  if x_webhook_secret is None:
69
  logger.warning("HTTP 401: No webhook secret")
 
83
  and payload.event.action == "create"
84
  and payload.discussion is not None
85
  and payload.discussion.isPullRequest
86
+ and payload.discussion.status == "open"
87
  ):
88
  # New PR!
89
+ if not is_pr_synced(space_id=space_id, pr_num=payload.discussion.num):
90
+ task_queue.add_task(
91
+ sync_ci_space,
92
+ space_id=space_id,
93
+ pr_num=payload.discussion.num,
94
+ private=payload.repo.private,
95
+ )
96
+ logger.info("New PR! Sync task scheduled")
97
+ else:
98
+ logger.info("New comment on PR but CI space already synced")
99
  elif (
100
  payload.event.scope.startswith("discussion")
101
  and payload.event.action == "update"
 
120
  for discussion in get_repo_discussions(
121
  repo_id=space_id, repo_type="space", token=HF_TOKEN
122
  ):
 
123
  if discussion.is_pull_request and discussion.status == "open":
124
  if not is_pr_synced(space_id=space_id, pr_num=discussion.num):
125
  task_queue.add_task(
 
140
  def is_pr_synced(space_id: str, pr_num: int) -> bool:
141
  # What is the last synced commit for this PR?
142
  ci_space_id = _get_ci_space_id(space_id=space_id, pr_num=pr_num)
143
+ try:
144
+ card = RepoCard.load(
145
+ repo_id_or_path=ci_space_id, repo_type="space", token=HF_TOKEN
146
+ )
147
+ last_synced_sha = getattr(card.data, "synced_sha", None)
148
+ except HTTPError:
149
+ last_synced_sha = None
150
 
151
  # What is the last commit id for this PR?
152
  info = space_info(repo_id=space_id, revision=f"refs/pr/{pr_num}")