not-lain commited on
Commit
7a55abe
1 Parent(s): 5b91e33
Files changed (1) hide show
  1. src/gradio_space_ci/webhook.py +8 -5
src/gradio_space_ci/webhook.py CHANGED
@@ -205,6 +205,8 @@ def recover_after_restart(space_id: str) -> None:
205
  print("Looping through PRs to check if any needs to be synced.")
206
  for discussion in get_repo_discussions(repo_id=space_id, repo_type="space", discussion_type="pull_request"):
207
  if discussion.status in ACTIVE_PR_STATUS:
 
 
208
  if not is_pr_synced(space_id=space_id, pr_num=discussion.num):
209
  # Found a PR that is not yet synced
210
  print(f"Recovery. Found an open PR that is not synced: {discussion.url}. Syncing it.")
@@ -438,7 +440,9 @@ def delete_ci_space(space_id: str, pr_num: int) -> None:
438
  def notify_pr(
439
  space_id: str,
440
  pr_num: int,
441
- action: Literal["created_not_configured", "created_and_configured", "updated", "deleted","trusted_pr","untrusted_pr"],
 
 
442
  ) -> None:
443
  ci_space_id = _get_ci_space_id(space_id=space_id, pr_num=pr_num)
444
  if action == "created_not_configured":
@@ -449,7 +453,7 @@ def notify_pr(
449
  comment = NOTIFICATION_TEMPLATE_UPDATED.format(ci_space_id=ci_space_id)
450
  elif action == "deleted":
451
  comment = NOTIFICATION_TEMPLATE_DELETED
452
- elif action == "trusted_pr":
453
  comment = NOTIFICATION_TEMPLATE_TRUSTED_PR
454
  elif action == "untrusted_pr":
455
  comment = NOTIFICATION_TEMPLATE_UNTRUSTED_PR
@@ -517,11 +521,10 @@ def handle_command(space_id: str, payload: WebhookPayload) -> None:
517
  if event_author in EPHEMERAL_SPACES_CONFIG["trusted_authors"]:
518
  if payload.comment.content == "/trust_pr":
519
  set_config(space_id=space_id, pr_num=pr_num)
520
- notify_pr(space_id=space_id,pr_num=pr_num,action="trusted_pr")
521
  elif payload.comment.content == "/untrust_pr":
522
  unset_config(space_id=space_id, pr_num=pr_num)
523
- notify_pr(space_id=space_id,pr_num=pr_num,action="untrusted_pr")
524
-
525
 
526
 
527
  NOTIFICATION_TEMPLATE_CREATED_AND_CONFIGURED = """\
 
205
  print("Looping through PRs to check if any needs to be synced.")
206
  for discussion in get_repo_discussions(repo_id=space_id, repo_type="space", discussion_type="pull_request"):
207
  if discussion.status in ACTIVE_PR_STATUS:
208
+ # check pr trust status
209
+ handle_modification(space_id=space_id, discussion=discussion)
210
  if not is_pr_synced(space_id=space_id, pr_num=discussion.num):
211
  # Found a PR that is not yet synced
212
  print(f"Recovery. Found an open PR that is not synced: {discussion.url}. Syncing it.")
 
440
  def notify_pr(
441
  space_id: str,
442
  pr_num: int,
443
+ action: Literal[
444
+ "created_not_configured", "created_and_configured", "updated", "deleted", "trusted_pr", "untrusted_pr"
445
+ ],
446
  ) -> None:
447
  ci_space_id = _get_ci_space_id(space_id=space_id, pr_num=pr_num)
448
  if action == "created_not_configured":
 
453
  comment = NOTIFICATION_TEMPLATE_UPDATED.format(ci_space_id=ci_space_id)
454
  elif action == "deleted":
455
  comment = NOTIFICATION_TEMPLATE_DELETED
456
+ elif action == "trusted_pr":
457
  comment = NOTIFICATION_TEMPLATE_TRUSTED_PR
458
  elif action == "untrusted_pr":
459
  comment = NOTIFICATION_TEMPLATE_UNTRUSTED_PR
 
521
  if event_author in EPHEMERAL_SPACES_CONFIG["trusted_authors"]:
522
  if payload.comment.content == "/trust_pr":
523
  set_config(space_id=space_id, pr_num=pr_num)
524
+ notify_pr(space_id=space_id, pr_num=pr_num, action="trusted_pr")
525
  elif payload.comment.content == "/untrust_pr":
526
  unset_config(space_id=space_id, pr_num=pr_num)
527
+ notify_pr(space_id=space_id, pr_num=pr_num, action="untrusted_pr")
 
528
 
529
 
530
  NOTIFICATION_TEMPLATE_CREATED_AND_CONFIGURED = """\