class Lander
Public Instance Methods
run(github_pr, metadata)
click to toggle source
# File lib/committer-tools.rb, line 19 def run(github_pr, metadata) check_to_land(github_pr, metadata) introduce_commit(github_pr, metadata) puts "[\u{2714}] Commit(s) applied locally. Please update to your liking, and then type 'lgtm'." if ENV['BOT'] && ENV['BOT'] == 'bot' lgtm = "lgtm" else lgtm = gets.strip! while !lgtm do sleep end end if lgtm && lgtm == 'lgtm' add_metadata_to_commit(metadata) validate_commit puts "\n[\u{2714}] Landed in #{`git rev-list upstream/master...HEAD`} -- committer-tools is done! Edit away to your content, and then push away :)" end end
Private Instance Methods
add_metadata_to_commit(metadata)
click to toggle source
# File lib/committer-tools.rb, line 45 def add_metadata_to_commit(metadata) msg = `git log --format=%B -n 1` + [metadata[:pr_url], metadata[:reviewers]].compact.join("\n") `git commit --amend -m '#{msg}'` end
check_to_land(github_pr, metadata)
click to toggle source
# File lib/committer-tools.rb, line 50 def check_to_land(github_pr, metadata) # At least 48 hours of review time if Time.parse(github_pr['created_at']) > (Date.today - 2).to_time puts "[✘] PR must remain open for at least 48 hours" end # At least two approvals if (metadata[:reviewers].length < 2) puts "[✘] PR must have at least two reviewers" end # No failing CI builds failing_statuses = metadata[:ci_statuses].select { |job| job[:status] == 'failure' } if (failing_statuses.length > 0) puts "[✘] Failing builds on #{failing_statuses.map { |s| s[:name] }.join(', ')}" end end
introduce_commit(github_pr, metadata)
click to toggle source
# File lib/committer-tools.rb, line 68 def introduce_commit(github_pr, metadata) # Clear current status `git am --abort` `git rebase --abort` `git checkout master` # Update from upstream `git fetch upstream` `git merge --ff-only upstream/master` # Download and apply patch `curl -L https://github.com/#{github_pr['base']['user']['login']}/#{github_pr['base']['repo']['name']}/pull/#{github_pr['number']}.patch | git am --whitespace=fix` end
validate_commit()
click to toggle source
# File lib/committer-tools.rb, line 82 def validate_commit puts "Running core-validate-commit..." system('git rev-list upstream/master...HEAD | xargs core-validate-commit') end