@@ -72,6 +72,74 @@ async def test_stage():
7272 assert post_ [1 ] == [awaiting .Blocker .merge .value ]
7373
7474
75+ async def test_opened_draft_pr ():
76+ # New Draft PR from a core dev.
77+ username = "brettcannon"
78+ issue_url = "https://api.github.com/issue/42"
79+ data = {
80+ "action" : "opened" ,
81+ "pull_request" : {
82+ "user" : {
83+ "login" : username ,
84+ },
85+ "issue_url" : issue_url ,
86+ "draft" : True ,
87+ },
88+ }
89+ event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
90+ teams = [{"name" : "python core" , "id" : 6 }]
91+ items = {
92+ f"https://api.github.com/teams/6/memberships/{ username } " : "OK" ,
93+ issue_url : {"labels" : [], "labels_url" : "https://api.github.com/labels" },
94+ }
95+ gh = FakeGH (
96+ getiter = {"https://api.github.com/orgs/python/teams" : teams }, getitem = items
97+ )
98+ await awaiting .router .dispatch (event , gh )
99+ assert len (gh .post_ ) == 0
100+
101+ # Draft PR is published
102+ data ["action" ] = "edited"
103+ data ["pull_request" ]["draft" ] = False
104+ event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
105+ gh = FakeGH (
106+ getiter = {"https://api.github.com/orgs/python/teams" : teams }, getitem = items
107+ )
108+ await awaiting .router .dispatch (event , gh )
109+ assert len (gh .post_ ) == 1
110+ post_ = gh .post_ [0 ]
111+ assert post_ [0 ] == "https://api.github.com/labels"
112+ assert post_ [1 ] == [awaiting .Blocker .core_review .value ]
113+
114+ # Published PR is unpublished (set back to Draft)
115+ data ["action" ] = "edited"
116+ data ["pull_request" ]["draft" ] = True
117+ encoded_label = "awaiting%20core%20review"
118+ items [issue_url ] = {
119+ "labels" : [
120+ {
121+ "url" : f"https://api.github.com/repos/python/cpython/labels/{ encoded_label } " ,
122+ "name" : "awaiting core review" ,
123+ },
124+ {
125+ "url" : "https://api.github.com/repos/python/cpython/labels/CLA%20signed" ,
126+ "name" : "CLA signed" ,
127+ },
128+ ],
129+ "labels_url" : "https://api.github.com/repos/python/cpython/issues/12345/labels{/name}" ,
130+ }
131+ event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
132+ gh = FakeGH (
133+ getiter = {"https://api.github.com/orgs/python/teams" : teams }, getitem = items
134+ )
135+ await awaiting .router .dispatch (event , gh )
136+ assert len (gh .post_ ) == 0
137+ assert (
138+ gh .delete_url ==
139+ f"https://api.github.com/repos/python/cpython/issues/12345/labels/{ encoded_label } "
140+ )
141+
142+
75143async def test_opened_pr ():
76144 # New PR from a core dev.
77145 username = "brettcannon"
@@ -110,6 +178,7 @@ async def test_opened_pr():
110178 "login" : username ,
111179 },
112180 "issue_url" : issue_url ,
181+ "draft" : False ,
113182 },
114183 }
115184 event = sansio .Event (data , event = "pull_request" , delivery_id = "12345" )
0 commit comments