class CLI

Public Instance Methods

report() click to toggle source
# File lib/gh/contrib/cli.rb, line 11
def report
  u = options[:user]
  s = options[:start]
  e = options[:end]

  exit if !validate(u,s,e)

  terms = "#{s}"+".."+"#{e}"
  path = "/search/issues?q=type:pr+in:body+is:merged+merged:#{terms}+author:#{u}&per_page=100"
  uri = URI('https://api.github.com' + path)

  req = Net::HTTP::Get.new(uri)
  req['Authorization'] = 'token ' + ENV['GHCONTRIB_TOKEN'] if !ENV['GHCONTRIB_TOKEN'].nil?

  response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') { |http|
    http.request(req)
  }

  if response.code != "200" then
    puts "Get error from GitHub"
    puts "#{response.code} #{response.message}"
    exit
  end
  
  result = JSON.parse(response.body)

  puts "Hi #{u}, this is your contribution report :tada: in #{terms}"
  puts "# Pull Request"
  puts "your created and merged pull request is #{result['total_count']}!!"
  puts ""

  result['items'].each { |i|
    puts i['title']
    puts i['html_url']
    puts ""
  }
end

Private Instance Methods

validate(u,s,e) click to toggle source
# File lib/gh/contrib/cli.rb, line 50
def validate(u,s,e)
  if !s.match(/^\d{4}-\d{2}-\d{2}$/)
    return false
  elsif !e.match(/^\d{4}-\d{2}-\d{2}$/)
    return false
  else
    true
  end
end