Sha256: 2a040ddebedf382e01386a5f081a55627287826f69c77925666f7ecdaa70e8e0

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

module TeamcityRuby
  class VcsRoot
    extend TeamcityRuby::Resource

    VCS_TYPES = { :git => 'jetbrains.git', :svn => 'svn' }

    DEFAULT_PROJECT = "_Root"
    DEFAULT_VCS_TYPE = "jetbrains.git"

    attr_reader :teamcity_id, :name, :parent_id, :vcs_type, :properties

    url_path "/vcs-roots"
    resource_name "vcs-root"

    def self.create(options = {}, &block)
      vcs_type = if options[:vcs_type]
        VCS_TYPES[options[:vcs_type]] || options[:vcs_type]
      else
        DEFAULT_VCS_TYPE
      end

      project_id = options.fetch(:project_id) { DEFAULT_PROJECT }

      attributes = {
        "name" => options[:name],
        "vcsName" => vcs_type,
        "projectLocator" => "id:#{project_id}"
      }

      builder = TeamCity::ElementBuilder.new(attributes, &block)

      response = client.post("/vcs-roots", :body => builder.to_request_body)
      VcsRoot.find(:id => response["id"])
    end

    def initialize(options = {})
      @teamcity_id = options["id"]
      @name = options["name"]
      @vcs_type = options["vcsName"]
      @properties = flat_properties(options["properties"]) if options["properties"]
    end

    def destroy!
      client.delete("/vcs-roots/id:#{self.teamcity_id}")
    end

    def flat_properties(properties)
      properties.delete("property").map do |p|
        { p["name"] => p["value"] }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
teamcity_ruby-0.0.6 lib/teamcity_ruby/vcs_root.rb