1- import typing
21from enum import Enum
2+ from typing import List , Optional
33
44import strawberry
55
66from .github import add_or_edit_comment , update_labels
77from .release import ReleaseInfo
8- from .templates import INVALID_RELEASE_FILE , MISSING_RELEASE_FILE , RELEASE_FILE_ADDED
8+ from .templates import (
9+ INVALID_RELEASE_FILE ,
10+ MISSING_RELEASE_FILE ,
11+ OK_TO_PREVIEW ,
12+ RELEASE_FILE_ADDED ,
13+ )
914
1015
1116@strawberry .type
@@ -26,11 +31,34 @@ class ReleaseFileStatus(Enum):
2631class AddReleaseFileCommentInput :
2732 pr_number : int
2833 status : ReleaseFileStatus
29- release_info : typing .Optional [ReleaseInfo ] = None
34+ release_info : Optional [ReleaseInfo ] = None
35+
36+
37+ @strawberry .input
38+ class AddOkToPreviewCommentInput :
39+ pr_number : int
40+ paths : List [str ]
3041
3142
3243@strawberry .type
3344class Mutation :
45+ @strawberry .mutation
46+ def add_ok_to_preview_comment (self , input : AddOkToPreviewCommentInput ) -> str :
47+ paths = [
48+ p .replace (".md" , "" ).replace ("docs/" , "" ).replace ("README" , "" )
49+ for p in input .paths
50+ ]
51+ links = [
52+ f"https://strawberry.rocks/docs/pr/{ input .pr_number } /{ path } "
53+ for path in paths
54+ ]
55+
56+ comment = OK_TO_PREVIEW .format (links = links )
57+
58+ add_or_edit_comment (input .pr_number , comment , slug = "ok-to-preview" )
59+
60+ return "ok"
61+
3462 @strawberry .mutation
3563 def add_release_file_comment (self , input : AddReleaseFileCommentInput ) -> str :
3664 """Adds a comment about the release file to a PR."""
@@ -46,7 +74,7 @@ def add_release_file_comment(self, input: AddReleaseFileCommentInput) -> str:
4674 if input .release_info :
4775 comment = comment .format (changelog_preview = input .release_info .changelog )
4876
49- add_or_edit_comment (input .pr_number , comment )
77+ add_or_edit_comment (input .pr_number , comment , slug = "release-file" )
5078 update_labels (input .pr_number , input .release_info )
5179
5280 return "ok"
0 commit comments