Module: TeamCity::Client::VCSRoots

Included in:
TeamCity::Client
Defined in:
lib/teamcity/client/vcs_roots.rb

Instance Method Summary collapse

Instance Method Details

#create_vcs_root(options = {}) {|Hash| ... } ⇒ Hashie::Mash

Create VCS Root

Examples:

Create a Git VCS Root that pulls from master that is only shared with it’s project and sub-projecdts and uses the default private key

TeamCity.create_vcs_root(:vcs_name => 'my-git-vcs-root', :vcs_type => 'git', :project_id => 'project2') do |properties|
  properties['branch'] = 'master'
  properties['url'] = '[email protected]:jperry/teamcity-ruby-client.git'
  properties['authMethod'] = 'PRIVATE_KEY_DEFAULT'
  properties['ignoreKnownHosts'] = true
end

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :vcs_name (String)

    Name of the vcs root

  • :vcs_type (String)

    Type of VCS: ‘git’, ‘perforce’, etc

  • :project_id (String)

    to create the vcs root under

Yields:

  • (Hash)

    properties to set on the vcs root, view the page source of the vcs root page for the id and value of a property

Returns:

  • (Hashie::Mash)

    vcs root object that was created



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/teamcity/client/vcs_roots.rb', line 36

def create_vcs_root(options = {}, &block)
  attributes = {
    :name    => options.fetch(:vcs_name),
    :vcsName => "jetbrains.#{options.fetch(:vcs_type)}",
    :projectLocator => options.fetch(:project_id)
  }
  builder = Builder::XmlMarkup.new
  builder.tag!('vcs-root'.to_sym, attributes) do |node|
    node.properties do |p|
      if block_given?
        properties = {}
        yield(properties)
        properties.each do |name, value|
          p.property(:name => name, :value => value)
        end
      end
    end
  end
  post("vcs-roots", :content_type => :xml) do |req|
    req.body = builder.target!
  end
end

#vcs_root_details(vcs_root_id) ⇒ Hashie::Mash

Get VCS Root details

Parameters:

  • vcs_root_id (String, Numeric)

Returns:

  • (Hashie::Mash)


17
18
19
# File 'lib/teamcity/client/vcs_roots.rb', line 17

def vcs_root_details(vcs_root_id)
  get("vcs-roots/id:#{vcs_root_id}")
end

#vcs_rootsArray<Hashie::Mash>?

List of VCS Roots

Returns:

  • (Array<Hashie::Mash>, nil)

    of vcs roots or nil if no vcs roots exist



8
9
10
11
# File 'lib/teamcity/client/vcs_roots.rb', line 8

def vcs_roots
  response = get('vcs-roots')
  response['vcs-root']
end