class LazyPr::CreatePr
Public Class Methods
new()
click to toggle source
# File lib/lazy_pr.rb, line 6 def initialize @head_branch = ARGV[0] @pull_request_title = ARGV[1] check_params end
Public Instance Methods
create_pull_request()
click to toggle source
# File lib/lazy_pr.rb, line 20 def create_pull_request begin @client.create_pull_request(repo, @head_branch, base, pull_request_title) puts "Successfully created PR...!" rescue Octokit::UnprocessableEntity => e puts e.errors[0][:message] rescue puts "Failed to create PR. Please ensure you have required authorization." end end
login_user()
click to toggle source
# File lib/lazy_pr.rb, line 12 def login_user if access_token.nil? login_using_credentials else login_using_access_token end end
Private Instance Methods
access_token()
click to toggle source
# File lib/lazy_pr.rb, line 40 def access_token ENV["github_personal_access_token"] end
base()
click to toggle source
# File lib/lazy_pr.rb, line 81 def base begin base_branch = `git rev-parse --abbrev-ref HEAD` return base_branch.partition("\n").first rescue puts "Make sure you have atleast one commit." exit(false) end end
check_params()
click to toggle source
# File lib/lazy_pr.rb, line 33 def check_params if @head_branch.nil? puts "Pass the branch name you want your changes pulled into (ex: lazypr master)" exit(false) end end
login_using_access_token()
click to toggle source
# File lib/lazy_pr.rb, line 61 def login_using_access_token begin @client = Octokit::Client.new(access_token: access_token) user = @client.user user.login rescue puts "Login failed using access token. Please check your access token." exit(false) end end
login_using_credentials()
click to toggle source
# File lib/lazy_pr.rb, line 44 def login_using_credentials puts "Can't find the access token...!" puts "Github Username" username = STDIN.gets.chomp puts "Github Password" password = STDIN.noecho(&:gets).chomp puts "\nLogging In..." begin @client = Octokit::Client.new login: username, password: password user = @client.user user.login rescue puts "Login failed. Try again." exit(false) end end
parse_url(remote_url)
click to toggle source
# File lib/lazy_pr.rb, line 96 def parse_url remote_url if remote_url.include?("https") return remote_url.partition(".com/").last.partition(".git").first else return remote_url.partition(":").last.partition(".git").first end end
pull_request_title()
click to toggle source
# File lib/lazy_pr.rb, line 91 def pull_request_title return @pull_request_title unless @pull_request_title.nil? return base end
repo()
click to toggle source
# File lib/lazy_pr.rb, line 72 def repo remote_url = `git config remote.origin.url` if remote_url.nil? || remote_url.empty? puts "Can't find remote url. Make sure you have configured the remote repo." exit(false) end return parse_url remote_url end