Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'json'
- # run from git repo. Make sure to pull first
- # EXAMPLE
- # cd MY_LIGHTNING_GLOBAL_GIT_FOLDER
- # ~/cherrychecker.rb
- # ~/cherrychecker.rb email=mmakarov@salesforce.com
- # ~/cherrychecker.rb --slack
- # ~/cherrychecker.rb compare=212-patch
- # Getting a hash from params passed
- args_hash = {}
- ARGV.each { |a| key, value = a.split('='); args_hash[key] = value }
- # Vars
- SLACK_URL = ENV['SLACK_URL']
- PR_REGEX = /#([0-9]+)/
- LOG = 'git log --pretty=format:"%h||%an||%ae||%s"'
- FIELDS = [:hash, :name, :email, :message]
- AMOUNT = args_hash['amount'] ? args_hash['amount'].to_i : 20
- USER_EMAIL = args_hash['email'] ? "| grep '#{args_hash['email']}'" : ''
- PATCH_BRANCH_NAME = args_hash['compare'] || '212-patch'
- prs = {}
- def get_commits_array(branch)
- prs = []
- ref_prs = []
- history = `#{LOG} #{branch} #{USER_EMAIL}`.split("\n")
- records = history.map do |h|
- obj = {}
- records = h.split("||")
- parsed_prs = records.last.scan(PR_REGEX)
- if parsed_prs.length > 0
- obj[:pr] = parsed_prs.last
- prs << parsed_prs.last
- end
- if parsed_prs.length == 2
- obj[:ref_pr] = parsed_prs.first
- ref_prs << parsed_prs.first
- end
- FIELDS.each_with_index do |f, i|
- obj[f] = records[i]
- end
- obj
- end
- {
- records: records,
- prs: prs,
- ref_prs: ref_prs,
- }
- end
- master = get_commits_array('master')
- patch = get_commits_array(PATCH_BRANCH_NAME)
- missing_prs = patch[:prs] - master[:ref_prs]
- missing_prs = missing_prs - master[:prs]
- last_20_numbers = missing_prs.first(AMOUNT)
- last_20 = last_20_numbers.map do |pr|
- patch[:records].select {|r| r[:pr] == pr}.first
- end
- # Posting to slack if slack param's present
- if args_hash['--slack']
- last_20_json = last_20.map do |r|
- {
- "title": "#{r[:hash]} #{r[:pr]} #{r[:message]}",
- "value": "by #{r[:name]}",
- "short": false,
- }
- end
- message = [
- {
- "pretext": "Last 20 PRs that got merge to 212-patch and were not cherry picked to master",
- "fields": last_20_json,
- }
- ]
- puts message.to_json
- puts `curl -X POST --data-urlencode 'payload={"channel": "#cherry-picks", "username": "TEST: Mr. IO", "text": "TEST", "attachments": #{message.to_json}, "icon_emoji": ":philosoraptor:"}' #{SLACK_URL}`
- else
- # if no slack param, outputting
- last_20.each_with_index do |r, i|
- puts "#{i + 1}) *** #{r[:hash]} *** #{r[:email]} #{r[:name]} #{r[:pr]}"
- puts "#{r[:message]}"
- end
- end
Add Comment
Please, Sign In to add comment