Class: Wagemage::Repo
- Inherits:
-
Object
- Object
- Wagemage::Repo
- Defined in:
- lib/wagemage/repo.rb
Instance Attribute Summary collapse
-
#clone_dir ⇒ Object
readonly
Returns the value of attribute clone_dir.
Instance Method Summary collapse
- #add_all! ⇒ Object
- #branches ⇒ Object
- #checkout!(ref, create: false) ⇒ Object
- #clone! ⇒ Object
- #commit!(message) ⇒ Object
- #has_changed? ⇒ Boolean
-
#initialize(info, dir, branch_pattern) ⇒ Repo
constructor
A new instance of Repo.
- #name ⇒ Object
- #pull_request!(base_branch, reviewers = []) ⇒ Object
- #push! ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(info, dir, branch_pattern) ⇒ Repo
Returns a new instance of Repo.
5 6 7 8 9 |
# File 'lib/wagemage/repo.rb', line 5 def initialize(info, dir, branch_pattern) @info = info @clone_dir = [dir, info[:full_name]].join('/') @branch_pattern = branch_pattern end |
Instance Attribute Details
#clone_dir ⇒ Object (readonly)
Returns the value of attribute clone_dir.
3 4 5 |
# File 'lib/wagemage/repo.rb', line 3 def clone_dir @clone_dir end |
Instance Method Details
#add_all! ⇒ Object
54 55 56 |
# File 'lib/wagemage/repo.rb', line 54 def add_all! Wagemage.command('git add .', chdir: @clone_dir) end |
#branches ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/wagemage/repo.rb', line 23 def branches @branches ||= begin result = Wagemage.command('git branch -a', chdir: @clone_dir) return [] unless result[:status].success? branch_list = result[:stdout] .split("\n") .select { |b| b.include?('remotes/origin/') } .reject { |b| b.include?('->') } .map { |b| b.split('/')[2..-1].join('/') } if branch_list.include?('master') branch_list .reject! { |b| b == 'master' } .push('master') end return branch_list if @branch_pattern.nil? branch_name_regex = Regexp.new(@branch_pattern) branch_list.select { |b| b =~ branch_name_regex } end end |
#checkout!(ref, create: false) ⇒ Object
49 50 51 52 |
# File 'lib/wagemage/repo.rb', line 49 def checkout!(ref, create: false) cmd = create ? "git checkout -b #{ref}" : "git checkout #{ref}" Wagemage.command(cmd, chdir: @clone_dir) end |
#clone! ⇒ Object
19 20 21 |
# File 'lib/wagemage/repo.rb', line 19 def clone! Wagemage.command("git clone #{url} #{clone_dir}", error: true) end |
#commit!(message) ⇒ Object
58 59 60 |
# File 'lib/wagemage/repo.rb', line 58 def commit!() Wagemage.command(%Q[git commit -m "#{}"], chdir: @clone_dir) end |
#has_changed? ⇒ Boolean
73 74 75 76 |
# File 'lib/wagemage/repo.rb', line 73 def has_changed? result = Wagemage.command('git status -s', chdir: @clone_dir) !result[:stdout].empty? end |
#name ⇒ Object
11 12 13 |
# File 'lib/wagemage/repo.rb', line 11 def name @info[:full_name] end |
#pull_request!(base_branch, reviewers = []) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/wagemage/repo.rb', line 66 def pull_request!(base_branch, reviewers = []) cmd = "hub pull-request --no-edit -b #{base_branch}" cmd = [cmd, '-r', reviewers.join(',')].join(' ') unless reviewers.empty? Wagemage.command(cmd, chdir: @clone_dir) end |
#push! ⇒ Object
62 63 64 |
# File 'lib/wagemage/repo.rb', line 62 def push! Wagemage.command('git push origin HEAD', chdir: @clone_dir) end |
#url ⇒ Object
15 16 17 |
# File 'lib/wagemage/repo.rb', line 15 def url @info[:ssh_url] end |