8
8
9
9
10
10
class FakeGH :
11
- def __init__ (self , * , getitem = None , getiter = None , put = None ):
11
+ def __init__ (self , * , getitem = None , getiter = None , put = None , post = None ):
12
12
self ._getitem_return = getitem
13
13
self ._getiter_return = getiter
14
14
self .getitem_url = None
15
15
self .getiter_url = None
16
16
self ._put_return = put
17
- self ._post_return = put
17
+ self ._post_return = post
18
18
19
19
async def getitem (self , url ):
20
20
self .getitem_url = url
@@ -30,7 +30,11 @@ async def getiter(self, url):
30
30
async def put (self , url , * , data ):
31
31
self .put_url = url
32
32
self .put_data = data
33
- return self ._put_return
33
+ to_return = self ._put_return
34
+ if isinstance (to_return , Exception ):
35
+ raise to_return
36
+ else :
37
+ return to_return
34
38
35
39
async def post (self , url , * , data ):
36
40
self .post_url = url
@@ -1217,3 +1221,74 @@ async def test_automerge_commit_not_found():
1217
1221
await status_change .router .dispatch (event , gh )
1218
1222
assert not hasattr (gh , "post_data" ) # does not leave a comment
1219
1223
assert not hasattr (gh , "put_data" ) # does not merge
1224
+
1225
+
1226
+ async def test_automerge_failed ():
1227
+ sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9"
1228
+ data = {
1229
+ "action" : "labeled" ,
1230
+ "pull_request" : {
1231
+ "user" : {"login" : "Mariatta" },
1232
+ "labels" : [
1233
+ {"name" : "awaiting merge" },
1234
+ {"name" : AUTOMERGE_LABEL },
1235
+ {"name" : "CLA signed" },
1236
+ ],
1237
+ "head" : {"sha" : sha },
1238
+ "number" : 5547 ,
1239
+ "title" : "bpo-32720: Fixed the replacement field grammar documentation." ,
1240
+ "body" : "\n \n `arg_name` and `element_index` are defined as `digit`+ instead of `integer`." ,
1241
+ },
1242
+ }
1243
+
1244
+ event = sansio .Event (data , event = "pull_request" , delivery_id = "1" )
1245
+
1246
+ getitem = {
1247
+ f"/repos/python/cpython/commits/{ sha } /status" : {
1248
+ "state" : "success" ,
1249
+ "statuses" : [
1250
+ {
1251
+ "state" : "success" ,
1252
+ "description" : "Issue report skipped" ,
1253
+ "context" : "bedevere/issue-number" ,
1254
+ },
1255
+ {
1256
+ "state" : "success" ,
1257
+ "description" : "The Travis CI build passed" ,
1258
+ "target_url" : "https://travis-ci.org/python/cpython/builds/340259685?utm_source=github_status&utm_medium=notification" ,
1259
+ "context" : "continuous-integration/travis-ci/pr" ,
1260
+ },
1261
+ ],
1262
+ }
1263
+ }
1264
+
1265
+ getiter = {
1266
+ "/repos/python/cpython/pulls/5547/commits" : [
1267
+ {"sha" : "5f007046b5d4766f971272a0cc99f8461215c1ec" },
1268
+ {"sha" : sha },
1269
+ ]
1270
+ }
1271
+
1272
+ gh = FakeGH (
1273
+ getitem = getitem ,
1274
+ getiter = getiter ,
1275
+ put = gidgethub .BadRequest (status_code = http .HTTPStatus (400 )),
1276
+ post = {
1277
+ "html_url" : f"https://github.com/python/cpython/pull/5547#issuecomment-401309376"
1278
+ },
1279
+ )
1280
+
1281
+ await status_change .router .dispatch (event , gh )
1282
+
1283
+ assert gh .put_data ["sha" ] == sha
1284
+ assert gh .put_data ["merge_method" ] == "squash"
1285
+ assert (
1286
+ gh .put_data ["commit_title" ]
1287
+ == "bpo-32720: Fixed the replacement field grammar documentation. (GH-5547)"
1288
+ )
1289
+ assert (
1290
+ gh .put_data ["commit_message" ]
1291
+ == "\n \n `arg_name` and `element_index` are defined as `digit`+ instead of `integer`."
1292
+ )
1293
+
1294
+ assert "Sorry, I can't merge this PR" in gh .post_data ["body" ]
0 commit comments