Sha256: bc1a29d7f7dce1c0c8f83ee31e70eb110e9f72f8e45c636f2d3b841e48c7b764

Contents?: true

Size: 1.89 KB

Versions: 9

Compression:

Stored size: 1.89 KB

Contents

require 'thor'
require 'net/http'
require 'uri'
require 'fwtoolkit/git_client'
require 'fwtoolkit/config'

module FWToolkit
  class Ci < Thor
    include Thor::Actions

    desc 'add [PROJECT_NAME] [PROJECT_DIR]', 'Add a project to the CI environment'
    def add(project_name, project_root)
      raise Thor::Error, "\"#{project_root}\" doesn't contain a valid git repository" unless repository.initialized?

      if project_exists_on_ci? project_name
        say_status :skip, "There's already a project named \"#{project_name}\" on the ci at #{Config.ci_server_url}"
        return
      end

      remotes = repository.remotes
      raise Thor::Error, "\"#{project_root}\" is a local-only repository" if remotes.to_a.size == 0

      remotes = repository.remotes
      if remotes.keys.count == 1
        remote_name = remotes.values.first
      else
        remote_name = ask 'There\'s more than one remote configured for this repository. Select one:', {:limited_to => remotes.keys }
      end

      remote_url = remotes[remote_name]

      response = Net::HTTP.post_form(URI.parse("#{Config.ci_server_url}/projects"),
                                     {'project[name]' => project_name,
                                      'project[source_control][repository]' => remote_url,
                                      'project[source_control][source_contro]' => 'Git',
                                      'project[source_control][branch]' => 'dev'})
      if response.kind_of? Net::HTTPSuccess
        say_status :add, "Project \"#{project_name}\" successfully added to the CI environment", :green
      elsif
        raise Thor::Error, "Failed to add project \"#{project_name}\" to the CI"
      end

    end

    private
    def project_exists_on_ci?(project_name)
      response = Net::HTTP.request_get URI.parse("#{Config.ci_server_url}/builds/#{project_name}")
      response.kind_if? Net::HTTPSuccess
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fwtoolkit-2.0.2 lib/fwtoolkit/cli/ci.rb
fwtoolkit-2.0.1 lib/fwtoolkit/cli/ci.rb
fwtoolkit-2.0.0 lib/fwtoolkit/cli/ci.rb
fwtoolkit-1.0.6 lib/fwtoolkit/cli/ci.rb
fwtoolkit-1.0.5 lib/fwtoolkit/cli/ci.rb
fwtoolkit-1.0.4 lib/fwtoolkit/cli/ci.rb
fwtoolkit-1.0.3 lib/fwtoolkit/cli/ci.rb
fwtoolkit-1.0.2 lib/fwtoolkit/cli/ci.rb
fwtoolkit-1.0.1 lib/fwtoolkit/cli/ci.rb