Class: FWToolkit::Ci

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/fwtoolkit/cli/ci.rb

Instance Method Summary collapse

Methods included from Thor::Actions

#run, #run!, #run_base, #template_directory

Instance Method Details

#add(project_name, project_root) ⇒ Object

Raises:

  • (Thor::Error)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fwtoolkit/cli/ci.rb', line 12

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