@@ -145,24 +145,29 @@ async fn milestone_cargo(
145145 // <https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-pull-requests-associated-with-a-commit>,
146146 // but it is a little awkward to use, only works on the default branch,
147147 // and this is a bit simpler/faster. However, it is sensitive to the
148- // specific messages generated by bors, and won't catch things merged
149- // without bors.
150- let merge_re = Regex :: new ( "(?:Auto merge of|Merge pull request) #([0-9]+)" ) . unwrap ( ) ;
151-
152- let pr_nums = commits. iter ( ) . filter_map ( |commit| {
153- log:: info!(
154- "getting PR number for cargo commit {} (len={})" ,
155- commit. sha,
156- commit. commit. message. len( )
157- ) ;
158- merge_re. captures ( & commit. commit . message ) . map ( |cap| {
159- cap. get ( 1 )
160- . unwrap ( )
161- . as_str ( )
162- . parse :: < u64 > ( )
163- . expect ( "digits only" )
164- } )
165- } ) ;
148+ // specific messages generated by bors or GitHub merge queue, and won't
149+ // catch things merged beyond them.
150+ let merge_re =
151+ Regex :: new ( r"(?:Auto merge of|Merge pull request) #([0-9]+)|\(#([0-9]+)\)$" ) . unwrap ( ) ;
152+
153+ let pr_nums = commits
154+ . iter ( )
155+ . filter ( |commit|
156+ // Assumptions:
157+ // * A merge commit always has two parent commits.
158+ // * Cargo's PR never got merged as fast-forward / rebase / squash merge.
159+ commit. parents . len ( ) == 2 )
160+ . filter_map ( |commit| {
161+ let first = commit. commit . message . lines ( ) . next ( ) . unwrap_or_default ( ) ;
162+ merge_re. captures ( first) . map ( |cap| {
163+ cap. get ( 1 )
164+ . or_else ( || cap. get ( 2 ) )
165+ . unwrap ( )
166+ . as_str ( )
167+ . parse :: < u64 > ( )
168+ . expect ( "digits only" )
169+ } )
170+ } ) ;
166171 let milestone = cargo_repo
167172 . get_or_create_milestone ( gh, release_version, "closed" )
168173 . await ?;
0 commit comments