@@ -538,6 +538,96 @@ def test_normalize_short_commit_message():
538538 )
539539
540540
541+ @pytest .mark .parametrize (
542+ "commit_message,expected_commit_message" ,
543+ (
544+ # ensure existing co-author is retained
545+ (
546+ """Fix broken `Show Source` links on documentation pages (GH-3113)
547+
548+ Co-authored-by: PR Co-Author <another@author.com>""" ,
549+ """[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)
550+ (cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)
551+
552+ Co-authored-by: PR Author <author@name.email>
553+ Co-authored-by: PR Co-Author <another@author.com>""" ,
554+ ),
555+ # ensure co-author trailer is not duplicated
556+ (
557+ """Fix broken `Show Source` links on documentation pages (GH-3113)
558+
559+ Co-authored-by: PR Author <author@name.email>""" ,
560+ """[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)
561+ (cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)
562+
563+ Co-authored-by: PR Author <author@name.email>""" ,
564+ ),
565+ # ensure message is formatted properly when original commit is short
566+ (
567+ "Fix broken `Show Source` links on documentation pages (GH-3113)" ,
568+ """[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)
569+ (cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)
570+
571+ Co-authored-by: PR Author <author@name.email>""" ,
572+ ),
573+ # ensure message is formatted properly when original commit is long
574+ (
575+ """Fix broken `Show Source` links on documentation pages (GH-3113)
576+
577+ The `Show Source` was broken because of a change made in sphinx 1.5.1
578+ In Sphinx 1.4.9, the sourcename was "index.txt".
579+ In Sphinx 1.5.1+, it is now "index.rst.txt".""" ,
580+ """[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)
581+
582+ The `Show Source` was broken because of a change made in sphinx 1.5.1
583+ In Sphinx 1.4.9, the sourcename was "index.txt".
584+ In Sphinx 1.5.1+, it is now "index.rst.txt".
585+ (cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)
586+
587+ Co-authored-by: PR Author <author@name.email>""" ,
588+ ),
589+ # ensure message is formatted properly when original commit is long
590+ # and it has a co-author
591+ (
592+ """Fix broken `Show Source` links on documentation pages (GH-3113)
593+
594+ The `Show Source` was broken because of a change made in sphinx 1.5.1
595+ In Sphinx 1.4.9, the sourcename was "index.txt".
596+ In Sphinx 1.5.1+, it is now "index.rst.txt".
597+
598+ Co-authored-by: PR Co-Author <another@author.com>""" ,
599+ """[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)
600+
601+ The `Show Source` was broken because of a change made in sphinx 1.5.1
602+ In Sphinx 1.4.9, the sourcename was "index.txt".
603+ In Sphinx 1.5.1+, it is now "index.rst.txt".
604+ (cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)
605+
606+ Co-authored-by: PR Author <author@name.email>
607+ Co-authored-by: PR Co-Author <another@author.com>""" ,
608+ ),
609+ ),
610+ )
611+ def test_get_updated_commit_message_with_trailers (commit_message , expected_commit_message ):
612+ cherry_pick_branch = "backport-22a594a-3.6"
613+ commit = "b9ff498793611d1c6a9b99df464812931a1e2d69"
614+
615+ with mock .patch ("cherry_picker.cherry_picker.validate_sha" , return_value = True ):
616+ cherry_picker = CherryPicker ("origin" , commit , [])
617+
618+ with mock .patch (
619+ "cherry_picker.cherry_picker.validate_sha" , return_value = True
620+ ), mock .patch .object (
621+ cherry_picker , "get_commit_message" , return_value = commit_message
622+ ), mock .patch (
623+ "cherry_picker.cherry_picker.get_author_info_from_short_sha" ,
624+ return_value = "PR Author <author@name.email>" ,
625+ ):
626+ updated_commit_message = cherry_picker .get_updated_commit_message (cherry_pick_branch )
627+
628+ assert updated_commit_message == expected_commit_message
629+
630+
541631@pytest .mark .parametrize (
542632 "input_path" , ("/some/path/without/revision" , "HEAD:some/non-existent/path" )
543633)
0 commit comments