Skip to content

Commit d29b143

Browse files
committed
Stop cloning the repository into another path
which seems to prevent it from fetching notes when the path is not the actual repository but a shallow-cloned repository.
1 parent 9c9f3bb commit d29b143

File tree

2 files changed

+39
-48
lines changed

2 files changed

+39
-48
lines changed

.github/workflows/check_misc.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ jobs:
6262
GITHUB_NEW_SHA: ${{ github.event.pull_request.merge_commit_sha }}
6363
if: ${{ github.repository == 'ruby/ruby' && startsWith(github.event_name, 'pull') }}
6464

65-
- name: Push PR notes to GitHub
66-
run: ruby tool/notes-github-pr.rb "$(pwd)/.git" "$GITHUB_OLD_SHA" "$GITHUB_NEW_SHA" refs/heads/master
67-
env:
68-
GITHUB_OLD_SHA: ${{ github.event.before }}
69-
GITHUB_NEW_SHA: ${{ github.event.after }}
70-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71-
GIT_AUTHOR_NAME: git
72-
GIT_COMMITTER_NAME: git
73-
74-
if: ${{ github.repository == 'ruby/ruby' && github.ref == 'refs/heads/master' && github.event_name == 'push' }}
75-
7665
- name: Check if C-sources are US-ASCII
7766
run: |
7867
grep -r -n --include='*.[chyS]' --include='*.asm' $'[^\t-~]' -- . && exit 1 || :
@@ -143,6 +132,17 @@ jobs:
143132
name: ${{ steps.docs.outputs.htmlout }}
144133
if: ${{ steps.docs.outcome == 'success' }}
145134

135+
- name: Push PR notes to GitHub
136+
run: ruby tool/notes-github-pr.rb "$(pwd)/.git" "$GITHUB_OLD_SHA" "$GITHUB_NEW_SHA" refs/heads/master
137+
env:
138+
GITHUB_OLD_SHA: ${{ github.event.before }}
139+
GITHUB_NEW_SHA: ${{ github.event.after }}
140+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
141+
GIT_AUTHOR_NAME: git
142+
GIT_COMMITTER_NAME: git
143+
144+
if: ${{ github.repository == 'ruby/ruby' && github.ref == 'refs/heads/master' && github.event_name == 'push' }}
145+
146146
- uses: ./.github/actions/slack
147147
with:
148148
SLACK_WEBHOOK_URL: ${{ secrets.SIMPLER_ALERTS_URL }} # ruby-lang slack: ruby/simpler-alerts-bot

tool/notes-github-pr.rb

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -103,45 +103,36 @@ def git(*cmd, repo_path: nil)
103103
github = GitHub.new(ENV.fetch('GITHUB_TOKEN'))
104104

105105
repo_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
147138
end

0 commit comments

Comments
 (0)