diff --git a/.github/workflows/check_misc.yml b/.github/workflows/check_misc.yml index b332eef541468f..07c43a0c3b0788 100644 --- a/.github/workflows/check_misc.yml +++ b/.github/workflows/check_misc.yml @@ -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 diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index e57cd86e2b3c7f..16dbac1afa0f18 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -9,4 +9,4 @@ jobs: pull-requests: write runs-on: ubuntu-latest steps: - - uses: actions/labeler@v5 + - uses: actions/labeler@v6 diff --git a/tool/notes-github-pr.rb b/tool/notes-github-pr.rb index e282386eba15d4..d69d479cdf79f1 100644 --- a/tool/notes-github-pr.rb +++ b/tool/notes-github-pr.rb @@ -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