not-lain commited on
Commit
bee5805
1 Parent(s): f8f713b

better logs

Browse files

WIP, logging a message by a trusted author

Files changed (1) hide show
  1. src/gradio_space_ci/webhook.py +19 -5
src/gradio_space_ci/webhook.py CHANGED
@@ -245,6 +245,20 @@ async def trigger_ci_on_pr(payload: WebhookPayload, task_queue: BackgroundTasks)
245
  space_id = payload.repo.name
246
 
247
  has_task = False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  if (
249
  # Means "a new PR has been opened"
250
  payload.event.scope.startswith("discussion")
@@ -253,9 +267,9 @@ async def trigger_ci_on_pr(payload: WebhookPayload, task_queue: BackgroundTasks)
253
  and payload.discussion.isPullRequest
254
  and payload.discussion.status == "open"
255
  ):
256
- if not is_pr_synced(space_id=space_id, pr_num=payload.discussion.num):
257
  # New PR! Sync task scheduled
258
- task_queue.add_task(sync_ci_space, space_id=space_id, pr_num=payload.discussion.num)
259
  has_task = True
260
  elif (
261
  # Means "a PR has been merged or closed"
@@ -268,7 +282,7 @@ async def trigger_ci_on_pr(payload: WebhookPayload, task_queue: BackgroundTasks)
268
  task_queue.add_task(
269
  delete_ci_space,
270
  space_id=space_id,
271
- pr_num=payload.discussion.num,
272
  )
273
  has_task = True
274
  elif (
@@ -290,11 +304,11 @@ async def trigger_ci_on_pr(payload: WebhookPayload, task_queue: BackgroundTasks)
290
  and payload.discussion.isPullRequest
291
  and payload.discussion.status == "open"
292
  # TODO:
293
- # this limited to owner only
294
  # check if it works with organizations
295
  and payload.discussion.author.id == payload.repo.owner
296
  ):
297
- print(payload.comment.content)
298
 
299
  if has_task:
300
  return Response("Task scheduled to sync/delete Space", status_code=status.HTTP_202_ACCEPTED)
 
245
  space_id = payload.repo.name
246
 
247
  has_task = False
248
+
249
+ pr_num = payload.discussion.num
250
+ details = get_discussion_details(repo_id=space_id, repo_type="space", discussion_num=pr_num)
251
+ event_author = details.events[-1]._event["author"]["name"] # username of that event
252
+ if (
253
+ # Means comment by a trusted author
254
+ payload.event.scope == "discussion.comment"
255
+ and payload.event.action == "create"
256
+ and payload.discussion.isPullRequest
257
+ and payload.discussion.status == "open"
258
+ and event_author in EPHEMERAL_SPACES_CONFIG["trusted_authors"]
259
+ ):
260
+ print("Comment detected with content:\n", payload.comment.content)
261
+
262
  if (
263
  # Means "a new PR has been opened"
264
  payload.event.scope.startswith("discussion")
 
267
  and payload.discussion.isPullRequest
268
  and payload.discussion.status == "open"
269
  ):
270
+ if not is_pr_synced(space_id=space_id, pr_num=pr_num):
271
  # New PR! Sync task scheduled
272
+ task_queue.add_task(sync_ci_space, space_id=space_id, pr_num=pr_num)
273
  has_task = True
274
  elif (
275
  # Means "a PR has been merged or closed"
 
282
  task_queue.add_task(
283
  delete_ci_space,
284
  space_id=space_id,
285
+ pr_num=pr_num,
286
  )
287
  has_task = True
288
  elif (
 
304
  and payload.discussion.isPullRequest
305
  and payload.discussion.status == "open"
306
  # TODO:
307
+ # this is limited to the owner only
308
  # check if it works with organizations
309
  and payload.discussion.author.id == payload.repo.owner
310
  ):
311
+ print("Payload by owner detected with content:\n ", payload.comment.content)
312
 
313
  if has_task:
314
  return Response("Task scheduled to sync/delete Space", status_code=status.HTTP_202_ACCEPTED)