not-lain commited on
Commit
990c959
1 Parent(s): 5f1bfb3

add notifications

Browse files
Files changed (1) hide show
  1. src/gradio_space_ci/webhook.py +19 -5
src/gradio_space_ci/webhook.py CHANGED
@@ -437,7 +437,7 @@ def delete_ci_space(space_id: str, pr_num: int) -> None:
437
  def notify_pr(
438
  space_id: str,
439
  pr_num: int,
440
- action: Literal["created_not_configured", "created_and_configured", "updated", "deleted"],
441
  ) -> None:
442
  ci_space_id = _get_ci_space_id(space_id=space_id, pr_num=pr_num)
443
  if action == "created_not_configured":
@@ -448,6 +448,10 @@ def notify_pr(
448
  comment = NOTIFICATION_TEMPLATE_UPDATED.format(ci_space_id=ci_space_id)
449
  elif action == "deleted":
450
  comment = NOTIFICATION_TEMPLATE_DELETED
 
 
 
 
451
  else:
452
  raise ValueError(f"Status {action} not handled.")
453
 
@@ -511,13 +515,12 @@ def handle_command(space_id: str, payload: WebhookPayload) -> None:
511
  event_author = details.events[-1]._event["author"]["name"] # username of that event
512
  if event_author in EPHEMERAL_SPACES_CONFIG["trusted_authors"]:
513
  if payload.comment.content == "/trust_pr":
514
- print("trusting pr ...")
515
  set_config(space_id=space_id, pr_num=pr_num)
516
- print("pr has been trusted")
517
  elif payload.comment.content == "/untrust_pr":
518
- print("untrusting pr ...")
519
  unset_config(space_id=space_id, pr_num=pr_num)
520
- print("pr has been untrusted")
 
521
 
522
 
523
  NOTIFICATION_TEMPLATE_CREATED_AND_CONFIGURED = """\
@@ -542,6 +545,17 @@ PR is now merged/closed. The ephemeral Space has been deleted.
542
  _(This is an automated message.)_
543
  """
544
 
 
 
 
 
 
 
 
 
 
 
 
545
  ### TO MOVE TO ITS OWN MODULE
546
  # Taken from https://github.com/huggingface/huggingface_hub/issues/1808#issuecomment-1802341663
547
 
 
437
  def notify_pr(
438
  space_id: str,
439
  pr_num: int,
440
+ action: Literal["created_not_configured", "created_and_configured", "updated", "deleted","trusted_pr","untrusted_pr"],
441
  ) -> None:
442
  ci_space_id = _get_ci_space_id(space_id=space_id, pr_num=pr_num)
443
  if action == "created_not_configured":
 
448
  comment = NOTIFICATION_TEMPLATE_UPDATED.format(ci_space_id=ci_space_id)
449
  elif action == "deleted":
450
  comment = NOTIFICATION_TEMPLATE_DELETED
451
+ elif action == "trusted_pr":
452
+ comment = NOTIFICATION_TEMPLATE_TRUSTED_PR
453
+ elif action == "untrusted_pr":
454
+ comment = NOTIFICATION_TEMPLATE_UNTRUSTED_PR
455
  else:
456
  raise ValueError(f"Status {action} not handled.")
457
 
 
515
  event_author = details.events[-1]._event["author"]["name"] # username of that event
516
  if event_author in EPHEMERAL_SPACES_CONFIG["trusted_authors"]:
517
  if payload.comment.content == "/trust_pr":
 
518
  set_config(space_id=space_id, pr_num=pr_num)
519
+ notify_pr(space_id=space_id,pr_num=pr_num,action="trusted_pr")
520
  elif payload.comment.content == "/untrust_pr":
 
521
  unset_config(space_id=space_id, pr_num=pr_num)
522
+ notify_pr(space_id=space_id,pr_num=pr_num,action="untrusted_pr")
523
+
524
 
525
 
526
  NOTIFICATION_TEMPLATE_CREATED_AND_CONFIGURED = """\
 
545
  _(This is an automated message.)_
546
  """
547
 
548
+ NOTIFICATION_TEMPLATE_TRUSTED_PR = """\
549
+ This PR has been granted temporary trust status Thus granting it with the appropriate approriate hardware, storage, and secrets.
550
+ Trust status will be revokeduser either when a trusted author uses `/untrust_pr` command or when new commits are pushed to this PR.
551
+ _(This is an automated message.)_
552
+ """
553
+
554
+ NOTIFICATION_TEMPLATE_UNTRUSTED_PR = """\
555
+ This PR has been untrusted. Thus resetting all hardware, storage, and secrets.
556
+ _(This is an automated message.)_
557
+ """
558
+
559
  ### TO MOVE TO ITS OWN MODULE
560
  # Taken from https://github.com/huggingface/huggingface_hub/issues/1808#issuecomment-1802341663
561