Class: Toolshed::Git::Github
- Inherits:
-
Toolshed::Git
- Object
- Toolshed::Git
- Toolshed::Git::Github
- Includes:
- HTTParty
- Defined in:
- lib/toolshed/git/github.rb
Overview
Class created to handle specific git tasks related to github
Constant Summary
Constants inherited from Toolshed::Git
DEFAULT_BRANCH_FROM, DEFAULT_GIT_TOOL
Instance Attribute Summary collapse
-
#default_options ⇒ Object
Returns the value of attribute default_options.
Attributes inherited from Toolshed::Git
#force, #from_remote_branch_name, #from_remote_name, #passed_branch_name, #to_remote_branch_name, #to_remote_name, #validator
Class Method Summary collapse
Instance Method Summary collapse
-
#create_pull_request(title, body, options = {}) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength.
-
#initialize(options = {}) ⇒ Github
constructor
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
Methods inherited from Toolshed::Git
git_submodule_command, #remote_update
Constructor Details
#initialize(options = {}) ⇒ Github
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/toolshed/git/github.rb', line 12 def initialize( = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength super() username = Toolshed::Client.instance.github_username password = Toolshed::Client.instance.github_password token = Toolshed::Client.instance.github_token username = [:username] unless [:username].nil? password = [:password] unless [:password].nil? unless token.nil? username = token password = nil end unless [:token].nil? username = [:token] password = nil end @auth = { username: username, password: password } self. = { headers: { 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17' # rubocop:disable Metrics/LineLength }, basic_auth: @auth } end |
Instance Attribute Details
#default_options ⇒ Object
Returns the value of attribute default_options.
10 11 12 |
# File 'lib/toolshed/git/github.rb', line 10 def end |
Class Method Details
.create_instance ⇒ Object
82 83 84 |
# File 'lib/toolshed/git/github.rb', line 82 def self.create_instance Toolshed::Git::Github.new(username: Toolshed::Git::Github.username, password: Toolshed::Git::Github.password) # rubocop:disable Metrics/LineLength end |
.password ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/toolshed/git/github.rb', line 71 def self.password password = Toolshed::Client.instance.github_password return password unless password.nil? system 'stty -echo' puts 'Github password? ' password = $stdin.gets.chomp.strip system 'stty echo' password end |
.username ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/toolshed/git/github.rb', line 63 def self.username username = Toolshed::Client.instance.github_username return username unless username.nil? puts 'Github username? ' $stdin.gets.chomp.strip end |
Instance Method Details
#create_pull_request(title, body, options = {}) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/toolshed/git/github.rb', line 40 def create_pull_request(title, body, = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength .merge!() .merge!( body: { title: title, body: body, head: "#{Toolshed::Client.instance.github_username}:#{Toolshed::Git::Branch.name}", # rubocop:disable Metrics/LineLength base: Toolshed::Git::Branch.from }.to_json ) = Marshal.load(Marshal.dump()) [:basic_auth][:password] = '********' Toolshed.logger.info "Creating pull request with the following options: #{display_options.inspect}" # rubocop:disable Metrics/LineLength response = HTTParty.post("#{Toolshed::Client::GITHUB_BASE_API_URL}repos/#{Toolshed::Client.instance.pull_from_repository_user}/#{Toolshed::Client.instance.pull_from_repository_name}/pulls", ).response # rubocop:disable Metrics/LineLength response = JSON.parse(response.body) if response['errors'].nil? response else fail "Validation errors #{response.inspect}" end end |