@@ -384,9 +384,8 @@ async def test_set_pull_request_body_already_hyperlinked_bpo(action):
384384 "statuses_url" : "https://api.github.com/blah/blah/git-sha" ,
385385 "issue_url" : "https://api.github.com/repos/blah/blah/issues/comments/123456" ,
386386 "body" : ("bpo-123"
387- "[bpo-123](https://bugs.python.org/issue123)"
388- "<a href='https://bugs.python.org/issue123'>bpo-123</a>"
389- )
387+ "[bpo-123](https://bugs.python.org/issue123)"
388+ "<a href='https://bugs.python.org/issue123'>bpo-123</a>" )
390389 },
391390 "changes" : {"stuff" : "thingy" }
392391 }
@@ -407,9 +406,8 @@ async def test_set_comment_body_already_hyperlinked_bpo(action):
407406 "comment" : {
408407 "url" : "https://api.github.com/repos/blah/blah/issues/comments/123456" ,
409408 "body" : ("bpo-123"
410- "[bpo-123](https://bugs.python.org/issue123)"
411- "<a href='https://bugs.python.org/issue123'>bpo-123</a>"
412- )
409+ "[bpo-123](https://bugs.python.org/issue123)"
410+ "<a href='https://bugs.python.org/issue123'>bpo-123</a>" )
413411 }
414412 }
415413
@@ -419,3 +417,58 @@ async def test_set_comment_body_already_hyperlinked_bpo(action):
419417 body_data = gh .patch_data
420418 assert body_data ["body" ].count ("[bpo-123](https://bugs.python.org/issue123)" ) == 2
421419 assert "123456" in gh .patch_url
420+
421+
422+ @pytest .mark .asyncio
423+ @pytest .mark .parametrize ("action" , ["opened" , "edited" ])
424+ async def test_bpo_text_within_codeblocks_in_comments (action ):
425+ data = {
426+ "action" : action ,
427+ "pull_request" : {
428+ "title" : "[3.6] bpo-12345: some issue" ,
429+ "url" : "https://api.github.com/repos/python/cpython/pulls/4321" ,
430+ "statuses_url" : "https://api.github.com/blah/blah/git-sha" ,
431+ "issue_url" : "https://api.github.com/repos/blah/blah/issues/comments/123456" ,
432+ "body" : ("bpo-123"
433+ "```bpo-123```"
434+ "`bpo-123`"
435+ "[bpo-123](https://bugs.python.org/issue123)"
436+ "<a href='https://bugs.python.org/issue123'>bpo-123</a>" )
437+ },
438+ "changes" : {"stuff" : "thingy" }
439+ }
440+
441+ event = sansio .Event (data , event = "pull_request" , delivery_id = "123123" )
442+ gh = FakeGH ()
443+ await bpo .router .dispatch (event , gh )
444+ body_data = gh .patch_data
445+ assert body_data ["body" ].count ("[bpo-123](https://bugs.python.org/issue123)" ) == 2
446+ assert "123456" in gh .patch_url
447+
448+
449+ @pytest .mark .asyncio
450+ @pytest .mark .parametrize ("action" , ["opened" , "edited" ])
451+ async def test_bpo_text_within_codeblocks_in_pull_request (action ):
452+ data = {
453+ "action" : action ,
454+ "pull_request" : {
455+ "title" : "[3.6] bpo-12345: some issue" ,
456+ "url" : "https://api.github.com/repos/python/cpython/pulls/4321" ,
457+ "statuses_url" : "https://api.github.com/blah/blah/git-sha" ,
458+ "issue_url" : "https://api.github.com/repos/blah/blah/issues/comments/123456" ,
459+ "body" : ("bpo-123"
460+ "```bpo-123```"
461+ "`bpo-123`"
462+ "[bpo-123](https://bugs.python.org/issue123)"
463+ "<a href='https://bugs.python.org/issue123'>bpo-123</a>" )
464+ },
465+ "changes" : {"stuff" : "thingy" }
466+ }
467+
468+ event = sansio .Event (data , event = "pull_request" , delivery_id = "123123" )
469+ gh = FakeGH ()
470+ await bpo .router .dispatch (event , gh )
471+ body_data = gh .patch_data
472+ assert body_data ["body" ].count ("[bpo-123](https://bugs.python.org/issue123)" ) == 2
473+ assert "123456" in gh .patch_url
474+ assert 1 == 2
0 commit comments