@@ -103,45 +103,36 @@ def git(*cmd, repo_path: nil)
103103github = GitHub . new ( ENV . fetch ( 'GITHUB_TOKEN' ) )
104104
105105repo_path , *rest = ARGV
106- rest . each_slice ( 3 ) . map do |oldrev , newrev , refname |
107- branch = Git . abbrev_ref ( refname , repo_path : repo_path )
108- next if branch != 'master' # we use pull requests only for master branches
109-
110- Dir . mktmpdir do |workdir |
111- # Clone a branch and fetch notes
112- depth = Git . rev_list ( "#{ oldrev } ..#{ newrev } " , repo_path : repo_path ) . size + 50
113- system ( 'git' , 'clone' , "--depth=#{ depth } " , "--branch=#{ branch } " , "file://#{ repo_path } " , workdir )
114- Dir . chdir ( workdir )
115- system ( 'git' , 'fetch' , 'origin' , 'refs/notes/commits:refs/notes/commits' )
116-
117- updated = false
118- Git . rev_list ( "#{ oldrev } ..#{ newrev } " , first_parent : true ) . each do |sha |
119- github . pulls ( owner : 'ruby' , repo : 'ruby' , commit_sha : sha ) . each do |pull |
120- number = pull . fetch ( 'number' )
121- url = pull . fetch ( 'html_url' )
122- next unless url . start_with? ( 'https://github.com/ruby/ruby/pull/' )
123-
124- # "Merged" notes for "Squash and merge"
125- message = Git . commit_message ( sha )
126- notes = Git . notes_message ( sha )
127- if !message . include? ( url ) && !message . match ( /[ (]##{ number } [) ]/ ) && !notes . include? ( url )
128- system ( 'git' , 'notes' , 'append' , '-m' , "Merged: #{ url } " , sha )
129- updated = true
130- end
131-
132- # "Merged-By" notes for "Rebase and merge"
133- if Git . committer_name ( sha ) ==
'GitHub' &&
Git . committer_email ( sha ) ==
'[email protected] ' 134- username = github . pull_request ( owner : 'ruby' , repo : 'ruby' , number : number ) . fetch ( 'merged_by' ) . fetch ( 'login' )
135- email = github . user ( username : username ) . fetch ( 'email' )
136- email ||= SVN_TO_EMAILS [ GITHUB_TO_SVN . fetch ( username , username ) ] &.first
137- system ( 'git' , 'notes' , 'append' , '-m' , "Merged-By: #{ username } #{ ( " <#{ email } >" if email ) } " , sha )
138- updated = true
139- end
106+ rest . each_slice ( 3 ) . map do |oldrev , newrev , _refname |
107+ system ( 'git' , 'fetch' , 'origin' , 'refs/notes/commits:refs/notes/commits' , exception : true )
108+
109+ updated = false
110+ Git . rev_list ( "#{ oldrev } ..#{ newrev } " , first_parent : true ) . each do |sha |
111+ github . pulls ( owner : 'ruby' , repo : 'ruby' , commit_sha : sha ) . each do |pull |
112+ number = pull . fetch ( 'number' )
113+ url = pull . fetch ( 'html_url' )
114+ next unless url . start_with? ( 'https://github.com/ruby/ruby/pull/' )
115+
116+ # "Merged" notes for "Squash and merge"
117+ message = Git . commit_message ( sha )
118+ notes = Git . notes_message ( sha )
119+ if !message . include? ( url ) && !message . match ( /[ (]##{ number } [) ]/ ) && !notes . include? ( url )
120+ system ( 'git' , 'notes' , 'append' , '-m' , "Merged: #{ url } " , sha , exception : true )
121+ updated = true
140122 end
141- end
142123
143- if updated
144- system ( 'git' , 'push' , 'origin' , 'refs/notes/commits' )
124+ # "Merged-By" notes for "Rebase and merge"
125+ if Git . committer_name ( sha ) ==
'GitHub' &&
Git . committer_email ( sha ) ==
'[email protected] ' 126+ username = github . pull_request ( owner : 'ruby' , repo : 'ruby' , number : number ) . fetch ( 'merged_by' ) . fetch ( 'login' )
127+ email = github . user ( username : username ) . fetch ( 'email' )
128+ email ||= SVN_TO_EMAILS [ GITHUB_TO_SVN . fetch ( username , username ) ] &.first
129+ system ( 'git' , 'notes' , 'append' , '-m' , "Merged-By: #{ username } #{ ( " <#{ email } >" if email ) } " , sha , exception : true )
130+ updated = true
131+ end
145132 end
146133 end
134+
135+ if updated
136+ system ( 'git' , 'push' , 'origin' , 'refs/notes/commits' , exception : true )
137+ end
147138end
0 commit comments