Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/check_misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,14 @@ jobs:
if: ${{ steps.docs.outcome == 'success' }}

- name: Push PR notes to GitHub
run: ruby tool/notes-github-pr.rb "$(pwd)" "$GITHUB_OLD_SHA" "$GITHUB_NEW_SHA" refs/heads/master
run: ruby tool/notes-github-pr.rb "$(pwd)/.git" "$GITHUB_OLD_SHA" "$GITHUB_NEW_SHA" refs/heads/master
env:
GITHUB_OLD_SHA: ${{ github.event.before }}
GITHUB_NEW_SHA: ${{ github.event.after }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_NAME: git
GIT_COMMITTER_NAME: git
EMAIL: svn-admin@ruby-lang.org
if: ${{ github.repository == 'ruby/ruby' && github.ref == 'refs/heads/master' && github.event_name == 'push' }}

- uses: ./.github/actions/slack
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v5
- uses: actions/labeler@v6
65 changes: 28 additions & 37 deletions tool/notes-github-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,45 +103,36 @@ def git(*cmd, repo_path: nil)
github = GitHub.new(ENV.fetch('GITHUB_TOKEN'))

repo_path, *rest = ARGV
rest.each_slice(3).map do |oldrev, newrev, refname|
branch = Git.abbrev_ref(refname, repo_path: repo_path)
next if branch != 'master' # we use pull requests only for master branches

Dir.mktmpdir do |workdir|
# Clone a branch and fetch notes
depth = Git.rev_list("#{oldrev}..#{newrev}", repo_path: repo_path).size + 50
system('git', 'clone', "--depth=#{depth}", "--branch=#{branch}", "file://#{repo_path}", workdir)
Dir.chdir(workdir)
system('git', 'fetch', 'origin', 'refs/notes/commits:refs/notes/commits')

updated = false
Git.rev_list("#{oldrev}..#{newrev}", first_parent: true).each do |sha|
github.pulls(owner: 'ruby', repo: 'ruby', commit_sha: sha).each do |pull|
number = pull.fetch('number')
url = pull.fetch('html_url')
next unless url.start_with?('https://github.com/ruby/ruby/pull/')

# "Merged" notes for "Squash and merge"
message = Git.commit_message(sha)
notes = Git.notes_message(sha)
if !message.include?(url) && !message.match(/[ (]##{number}[) ]/) && !notes.include?(url)
system('git', 'notes', 'append', '-m', "Merged: #{url}", sha)
updated = true
end

# "Merged-By" notes for "Rebase and merge"
if Git.committer_name(sha) == 'GitHub' && Git.committer_email(sha) == 'noreply@github.com'
username = github.pull_request(owner: 'ruby', repo: 'ruby', number: number).fetch('merged_by').fetch('login')
email = github.user(username: username).fetch('email')
email ||= SVN_TO_EMAILS[GITHUB_TO_SVN.fetch(username, username)]&.first
system('git', 'notes', 'append', '-m', "Merged-By: #{username}#{(" <#{email}>" if email)}", sha)
updated = true
end
rest.each_slice(3).map do |oldrev, newrev, _refname|
system('git', 'fetch', 'origin', 'refs/notes/commits:refs/notes/commits', exception: true)

updated = false
Git.rev_list("#{oldrev}..#{newrev}", first_parent: true).each do |sha|
github.pulls(owner: 'ruby', repo: 'ruby', commit_sha: sha).each do |pull|
number = pull.fetch('number')
url = pull.fetch('html_url')
next unless url.start_with?('https://github.com/ruby/ruby/pull/')

# "Merged" notes for "Squash and merge"
message = Git.commit_message(sha)
notes = Git.notes_message(sha)
if !message.include?(url) && !message.match(/[ (]##{number}[) ]/) && !notes.include?(url)
system('git', 'notes', 'append', '-m', "Merged: #{url}", sha, exception: true)
updated = true
end
end

if updated
system('git', 'push', 'origin', 'refs/notes/commits')
# "Merged-By" notes for "Rebase and merge"
if Git.committer_name(sha) == 'GitHub' && Git.committer_email(sha) == 'noreply@github.com'
username = github.pull_request(owner: 'ruby', repo: 'ruby', number: number).fetch('merged_by').fetch('login')
email = github.user(username: username).fetch('email')
email ||= SVN_TO_EMAILS[GITHUB_TO_SVN.fetch(username, username)]&.first
system('git', 'notes', 'append', '-m', "Merged-By: #{username}#{(" <#{email}>" if email)}", sha, exception: true)
updated = true
end
end
end

if updated
system('git', 'push', 'origin', 'refs/notes/commits', exception: true)
end
end