Class: Cyclid::API::Plugins::Git
- Defined in:
- app/cyclid/plugins/source/git.rb
Overview
Git source plugin
Class Method Summary collapse
-
.metadata ⇒ Object
Plugin metadata.
Instance Method Summary collapse
-
#checkout(transport, ctx, sources = []) ⇒ Object
Run commands via.
Methods inherited from Source
Methods inherited from Base
author, config?, config_schema, default_config, get_config, homepage, human_name, license, register_plugin, set_config, update_config, version
Class Method Details
Instance Method Details
#checkout(transport, ctx, sources = []) ⇒ Object
Run commands via. the transport to check out a given Git remote repository
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/cyclid/plugins/source/git.rb', line 26 def checkout(transport, ctx, sources = []) normalized_sources = normalize_and_dedup(sources) normalized_sources.each do |source| source.symbolize_keys! raise 'invalid git source definition' \ unless source.key? :url # Add any context data (which could include secrets) source = source % ctx url = URI(source[:url]) # If the source includes an OAuth token, add it to the URL as the # username url.user = source[:token] if source.key? :token success = transport.exec("git clone #{url}", path: ctx[:workspace]) return false unless success # If a branch was given, check it out next unless source.key? :branch branch = source[:branch] match = url.path.match(%r{^.*\/([^\.]*)}) source_dir = "#{ctx[:workspace]}/#{match[1]}" success = transport.exec("git fetch origin #{branch}:#{branch}", path: source_dir) return false unless success success = transport.exec("git checkout #{branch}", path: source_dir) return false unless success end return true end |