Module: Trellish::Git
- Included in:
- Card
- Defined in:
- lib/trellish/git.rb
Instance Method Summary collapse
- #current_git_branch_is_up_to_date? ⇒ Boolean
- #git_create_local_branch(branch_name) ⇒ Object
- #git_repository_name ⇒ Object
- #git_repository_owner ⇒ Object
- #git_user_initials ⇒ Object
- #github_pull_request_url ⇒ Object
Instance Method Details
#current_git_branch_is_up_to_date? ⇒ Boolean
49 50 51 |
# File 'lib/trellish/git.rb', line 49 def current_git_branch_is_up_to_date? git_remote_up_to_date?(current_git_branch) end |
#git_create_local_branch(branch_name) ⇒ Object
43 44 45 46 47 |
# File 'lib/trellish/git.rb', line 43 def git_create_local_branch(branch_name) `git checkout -b #{branch_name} #{git_base_branch}` rescue Trellish.logger.warn "Failed to create a local git branch named #{branch_name}." end |
#git_repository_name ⇒ Object
35 36 37 |
# File 'lib/trellish/git.rb', line 35 def git_repository_name @git_repository_name ||= matches[2] end |
#git_repository_owner ⇒ Object
39 40 41 |
# File 'lib/trellish/git.rb', line 39 def git_repository_owner @git_repository_owner ||= matches[1] end |
#git_user_initials ⇒ Object
53 54 55 56 57 |
# File 'lib/trellish/git.rb', line 53 def git_user_initials return @user_initials if @user_initials username = presence(`git config github.user`) || presence(`git config user.email`) || presence(`whoami`) @user_initials = username[0..2] end |
#github_pull_request_url ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/trellish/git.rb', line 6 def github_pull_request_url return @github_pull_request_url if @github_pull_request_url conn = Faraday.new(:url => 'https://api.github.com', :ssl => {:ca_file => '/System/Library/OpenSSL/certs/ca-certificates.crt'}) do |faraday| faraday.request :url_encoded faraday.adapter ::Faraday.default_adapter end begin response = conn.post do |req| req.url "/repos/#{git_repository_owner}/#{git_repository_name}/pulls" req.headers['Content-Type'] = 'application/json' req.headers['Authorization'] = "token #{Trellish.config[:github_oauth_token]}" req.body = { title: @card.name, body: "[Trello card](#{@card.url})", base: git_base_branch, head: "#{git_repository_owner}:#{current_git_branch}" }.to_json end rescue Faraday::Error::ConnectionFailed => e Trellish.logger.error "Failed to connect to Github. Please check your github_oauth_token parameter in trellish.yml, or regenerate it if you continue to have problems. Original error: #{e.message}" exit end if response.status == 401 Trellish.logger.error "The response from the Github API says Bad Credentials. Please check your github_oauth_token parameter in trellish." exit end @github_pull_request_url = JSON.parse(response.body)["html_url"] end |