Skip to content

Commit 0397810

Browse files
committed
Fix the race-condition fix, so it works in NRI CI
NoRedInk CI merges in master before running anything in CI. This means that taking HEAD from git includes all master changes merged in. This is what was causing the race condition fix in 0.13.3 to trigger absurd checks for simple branches. This commit introduces an option to override the head commit used in the checks, so we can pass e.g. the GIT_COMMIT env var from Jenkins and make the checks sane again.
1 parent 094e095 commit 0397810

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

exe/pr-checklist.rb

+15-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# options and validation
1313
class Options
14-
attr_writer :git_dir, :branch, :token, :org, :repo, :dry_run, :checklist
14+
attr_writer :git_dir, :branch, :head_commit, :token, :org, :repo, :dry_run, :checklist
1515

1616
# Use the supplied git dir, GIT_DIR from environment, find the .git directory
1717
# in a parent directory recursively or fail out by using the current
@@ -35,6 +35,11 @@ def branch
3535
b
3636
end
3737

38+
def head_commit
39+
# Fall back to 'HEAD' unless specified
40+
@head_commit || 'HEAD'
41+
end
42+
3843
def token
3944
t = @token || ENV['GITHUB_TOKEN']
4045
raise "--token or GITHUB_TOKEN must be set" unless t
@@ -72,6 +77,11 @@ def checklist
7277
"Which branch should we examine?"
7378
) { |branch| options.branch = branch }
7479

80+
opts.on(
81+
"-hc", "--head-commit HEAD", String,
82+
"Use a custom head commit. Useful if you merge other stuff in before running this check."
83+
) { |head_commit| options.head_commit = head_commit }
84+
7585
opts.on(
7686
"-t", "--token token", String,
7787
"Github access token (default: ENV['GITHUB_TOKEN'])"
@@ -120,7 +130,10 @@ def checklist
120130
# 3. We ask for `pr.head`, which is newer than `git.object('HEAD')`
121131
#
122132
# This race condition breaks commands that rely on `head` below
123-
head = git.object('HEAD').sha
133+
#
134+
# We also allow overriding the HEAD, since CI might change HEAD in a way that
135+
# interferes with checks here. (e.g. merging in master before running CI)
136+
head = git.object(options.head_commit).sha
124137

125138
# Calculate the common ancestor where head diverged from pr.base, so the diff
126139
# is of the unique changes in head and not the changes that have since merged

0 commit comments

Comments
 (0)