Class: EasyAuto::PullRequest

Inherits:
Object
  • Object
show all
Includes:
ClientWrapper, EasyUtilities, GitWrapper, SystemHelper
Defined in:
lib/easy_auto/pull_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SystemHelper

#check_install, #cli_send, #os

Methods included from ClientWrapper

#client, #username

Methods included from GitWrapper

#git

Methods included from EasyUtilities

#ask, #hidden_input

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



11
12
13
# File 'lib/easy_auto/pull_request.rb', line 11

def body
  @body
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/easy_auto/pull_request.rb', line 11

def title
  @title
end

Instance Method Details

#ask_bodyObject



36
37
38
# File 'lib/easy_auto/pull_request.rb', line 36

def ask_body
  self.body = ask "Description:"
end

#ask_titleObject



32
33
34
# File 'lib/easy_auto/pull_request.rb', line 32

def ask_title
  self.title = ask "Title:"
end

#baseObject



40
41
42
# File 'lib/easy_auto/pull_request.rb', line 40

def base
  'master'
end

#headObject



44
45
46
# File 'lib/easy_auto/pull_request.rb', line 44

def head
  git.current_branch_name
end

#open_in_browser(pr_number) ⇒ Object



23
24
25
# File 'lib/easy_auto/pull_request.rb', line 23

def open_in_browser pr_number
  cli_send "open 'https://github.com/#{repo_path}/pull/#{pr_number}'"
end

#push_changesObject



60
61
62
# File 'lib/easy_auto/pull_request.rb', line 60

def push_changes
  git.perform "push"
end

#remote_pathsObject



64
65
66
# File 'lib/easy_auto/pull_request.rb', line 64

def remote_paths
  git.perform "remote -v"
end

#repo_nameObject



48
49
50
# File 'lib/easy_auto/pull_request.rb', line 48

def repo_name
  remote_paths.match(/\/(.+)\.git/)[1]
end

#repo_ownerObject



52
53
54
# File 'lib/easy_auto/pull_request.rb', line 52

def repo_owner
  (origin_owner || any_owner)[1]
end

#repo_pathObject



56
57
58
# File 'lib/easy_auto/pull_request.rb', line 56

def repo_path
  "#{repo_owner}/#{repo_name}"
end

#runObject



13
14
15
16
17
18
19
20
21
# File 'lib/easy_auto/pull_request.rb', line 13

def run
  state_merge_intent
  ask_title
  ask_body
  push_changes
  resp = client.create_pull_request(repo_path, base, head, title, body)
  pr_number = resp.attrs[:number]
  open_in_browser pr_number
end

#state_merge_intentObject



27
28
29
30
# File 'lib/easy_auto/pull_request.rb', line 27

def state_merge_intent
  puts "Preparing pull request:"
  puts "#{repo_owner}/#{repo_name}/#{head} -> #{repo_owner}/#{repo_name}/master"
end