Class: Lampwick::Git
- Inherits:
-
Object
- Object
- Lampwick::Git
- Defined in:
- lib/lampwick/git.rb
Constant Summary collapse
- REQUIRED_INITIAL =
[ :git ]
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config) ⇒ Git
constructor
pass a git repository, access credentials to the git repo (username/password or path to an ssh key) { :git => ”, :user => ‘foo’, :password => ‘bar’, :key => ‘path/to/key’ } returns a new lampwick object.
- #named_directories(target = @config.target) ⇒ Object
- #populate_environments(target = @config.target) ⇒ Object
- #pull_requests(repo = @config.repo) ⇒ Object
- #update_or_clone(repo = @config.repo) ⇒ Object
Constructor Details
#initialize(config) ⇒ Git
pass a git repository, access credentials to the git repo (username/password or path to an ssh key) { :git => ”, :user => ‘foo’, :password => ‘bar’, :key => ‘path/to/key’ } returns a new lampwick object
13 14 15 16 17 18 19 20 |
# File 'lib/lampwick/git.rb', line 13 def initialize(config) @config = ::OpenStruct.new(config) REQUIRED_INITIAL.each do |arg| raise ArgumentError, "Needs the #{arg} argument" unless @config.respond_to?(arg) raise ArgumentError, "#{arg} argument cannot be empty/blank" if @config.__send__(arg.to_s).nil? or @config.__send__(arg.to_s).empty? end @config.git = URI(@config.git) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/lampwick/git.rb', line 8 def config @config end |
Instance Method Details
#named_directories(target = @config.target) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/lampwick/git.rb', line 52 def named_directories(target = @config.target) Dir.chdir target do github_requests.each do |hash,name| File.symlink(hash, name) end end end |
#populate_environments(target = @config.target) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lampwick/git.rb', line 40 def populate_environments(target = @config.target) raise StandardError, "Repo has not been cloned at: #{repo}" unless repo_exists?(@config.repo) Dir.chdir target do pull_requests.each do |ref, hash| %x|git clone #{@config.repo} #{target}/#{hash}| Dir.chdir "#{target}/#{hash}" do %x|git checkout --quiet #{hash}| end end end end |
#pull_requests(repo = @config.repo) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lampwick/git.rb', line 28 def pull_requests(repo = @config.repo) raise StandardError, "Repo has not been cloned at: #{repo}" unless repo_exists?(repo) refs = Hash.new Dir.chdir @config.repo do %x|git fetch --quiet origin '+refs/pull/*/head:refs/remotes/origin/pr/*'| refs = %x|git show-ref --dereference| flipped_refs = refs.split("\n").map{|ab| ab.split(/\s+/).reverse }.flatten refs = Hash[*flipped_refs].delete_if { |ref,hash| ref !~ /origin\/pr\/\d+$/ } end refs end |
#update_or_clone(repo = @config.repo) ⇒ Object
22 23 24 25 26 |
# File 'lib/lampwick/git.rb', line 22 def update_or_clone(repo = @config.repo) if @config.git.scheme == 'https' %x|git clone --quiet #{@config.git} #{repo}| unless repo_exists?(repo) end end |