Spaces:
Sleeping
Sleeping
/help command
Browse files- open_pr.py +4 -0
- src/gradio_space_ci/webhook.py +15 -2
open_pr.py
CHANGED
@@ -19,6 +19,10 @@ This PR enables Space CI on your Space. **Gradio Space CI is a tool to create ep
|
|
19 |
- If trusted author => ephemeral Space is configured with variables, secrets and hardware.
|
20 |
- If not a trusted author => ephemeral Space is started without configuration.
|
21 |
- Space owners are trusted by default. Additional "trusted authors" can be configuration manually.
|
|
|
|
|
|
|
|
|
22 |
|
23 |
### ⚠️ Before merging:
|
24 |
|
|
|
19 |
- If trusted author => ephemeral Space is configured with variables, secrets and hardware.
|
20 |
- If not a trusted author => ephemeral Space is started without configuration.
|
21 |
- Space owners are trusted by default. Additional "trusted authors" can be configuration manually.
|
22 |
+
- Support Slash commands :
|
23 |
+
- `/help` to check the full documentation
|
24 |
+
- `/trust_pr` to temporarily trust a pr and configure it with the appropriate hardware and secrets.
|
25 |
+
- `/untrust_pr` to force a pr to reset to default hardware.
|
26 |
|
27 |
### ⚠️ Before merging:
|
28 |
|
src/gradio_space_ci/webhook.py
CHANGED
@@ -447,7 +447,7 @@ def notify_pr(
|
|
447 |
space_id: str,
|
448 |
pr_num: int,
|
449 |
action: Literal[
|
450 |
-
"created_not_configured", "created_and_configured", "updated", "deleted", "trusted_pr", "untrusted_pr"
|
451 |
],
|
452 |
) -> None:
|
453 |
ci_space_id = _get_ci_space_id(space_id=space_id, pr_num=pr_num)
|
@@ -463,6 +463,8 @@ def notify_pr(
|
|
463 |
comment = NOTIFICATION_TEMPLATE_TRUSTED_PR.format(ci_space_id=ci_space_id)
|
464 |
elif action == "untrusted_pr":
|
465 |
comment = NOTIFICATION_TEMPLATE_UNTRUSTED_PR.format(ci_space_id=ci_space_id)
|
|
|
|
|
466 |
else:
|
467 |
raise ValueError(f"Status {action} not handled.")
|
468 |
|
@@ -501,7 +503,9 @@ def handle_command(space_id: str, payload: WebhookPayload) -> None:
|
|
501 |
pr_num = payload.discussion.num
|
502 |
details = get_discussion_details(repo_id=space_id, repo_type="space", discussion_num=pr_num)
|
503 |
event_author = details.events[-1]._event["author"]["name"] # username of that event
|
504 |
-
if
|
|
|
|
|
505 |
if payload.comment.content == "/trust_pr":
|
506 |
configure_ephemeral_space(space_id=space_id, pr_num=pr_num, trusted_pr=True)
|
507 |
notify_pr(space_id=space_id, pr_num=pr_num, action="trusted_pr")
|
@@ -544,6 +548,15 @@ You can access this PR's ephemeral Space at [{ci_space_id}](https://huggingface.
|
|
544 |
_(This is an automated message.)_
|
545 |
"""
|
546 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
547 |
### TO MOVE TO ITS OWN MODULE
|
548 |
# Taken from https://github.com/huggingface/huggingface_hub/issues/1808#issuecomment-1802341663
|
549 |
|
|
|
447 |
space_id: str,
|
448 |
pr_num: int,
|
449 |
action: Literal[
|
450 |
+
"created_not_configured", "created_and_configured", "updated", "deleted", "trusted_pr", "untrusted_pr", "help"
|
451 |
],
|
452 |
) -> None:
|
453 |
ci_space_id = _get_ci_space_id(space_id=space_id, pr_num=pr_num)
|
|
|
463 |
comment = NOTIFICATION_TEMPLATE_TRUSTED_PR.format(ci_space_id=ci_space_id)
|
464 |
elif action == "untrusted_pr":
|
465 |
comment = NOTIFICATION_TEMPLATE_UNTRUSTED_PR.format(ci_space_id=ci_space_id)
|
466 |
+
elif action == "help":
|
467 |
+
comment = NOTIFICATION_TEMPLATE_HELP
|
468 |
else:
|
469 |
raise ValueError(f"Status {action} not handled.")
|
470 |
|
|
|
503 |
pr_num = payload.discussion.num
|
504 |
details = get_discussion_details(repo_id=space_id, repo_type="space", discussion_num=pr_num)
|
505 |
event_author = details.events[-1]._event["author"]["name"] # username of that event
|
506 |
+
if payload.comment.content == "/help":
|
507 |
+
notify_pr(space_id=space_id, pr_num=pr_num, action="help")
|
508 |
+
elif event_author in EPHEMERAL_SPACES_CONFIG["trusted_authors"]:
|
509 |
if payload.comment.content == "/trust_pr":
|
510 |
configure_ephemeral_space(space_id=space_id, pr_num=pr_num, trusted_pr=True)
|
511 |
notify_pr(space_id=space_id, pr_num=pr_num, action="trusted_pr")
|
|
|
548 |
_(This is an automated message.)_
|
549 |
"""
|
550 |
|
551 |
+
NOTIFICATION_TEMPLATE_HELP = """\
|
552 |
+
Here are the available commands:
|
553 |
+
- `/trust_pr`: Grants temporary trust status to the PR, and can only be used by a trusted user. If a new commit is made by an untrusted user it will automatically revoke trust status.
|
554 |
+
- `/untrust_pr`: Revokes trust status from the PR,can only be used by a trusted user on any pr (including his own PRs) and will reset the ephemeral space hardware, storage, secrets and variables.
|
555 |
+
- `/help`: Shows this help message.
|
556 |
+
To integrate gradio-space-ci into another space head into https://huggingface.co/spaces/Wauplin/gradio-space-ci and follow the instructions.
|
557 |
+
_(This is an automated message.)
|
558 |
+
"""
|
559 |
+
|
560 |
### TO MOVE TO ITS OWN MODULE
|
561 |
# Taken from https://github.com/huggingface/huggingface_hub/issues/1808#issuecomment-1802341663
|
562 |
|