codebase 3.2.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/cb CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.dirname(__FILE__) + "/../lib/codebase"
3
- Codebase.run(ARGV)
3
+ Codebase.run(ARGV.shift, ARGV)
data/bin/codebase CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.dirname(__FILE__) + "/../lib/codebase"
3
- Codebase.run(ARGV)
3
+ Codebase.run(ARGV.shift, ARGV)
data/lib/codebase.rb CHANGED
@@ -2,48 +2,129 @@ $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  require 'rubygems'
4
4
  require 'json'
5
- require 'highline/import'
6
- HighLine.track_eof = false
7
5
 
8
6
  require 'codebase/command'
9
7
 
10
8
  trap("INT") { puts; exit }
11
9
 
12
10
  module Codebase
13
-
11
+ extend self
14
12
 
15
13
  class Error < RuntimeError; end
16
14
  class NotConfiguredError < StandardError; end
17
15
  class MustBeInRepositoryError < StandardError; end
18
16
 
19
- extend self
20
-
21
- def run(args)
22
- begin
23
- method = args.shift || 'default'
24
- command = Codebase::Command.new
25
-
26
- if command.respond_to?(method)
27
- command.send(method, *args)
28
- else
29
- $stderr.puts "Command Not Found - please check http://docs.codebasehq.com/gem for documentation."
17
+ VERSION = "4.0.0"
18
+
19
+ def run(command, args = [])
20
+ load_commands
21
+ command = 'help' if command.nil?
22
+ if @commands[command]
23
+ options = parse_options(args)
24
+ if args.size < @commands[command][:required_args].to_i
25
+ puts "error: #{@commands[command][:usage]}"
26
+ puts "See 'cb help #{command}' for usage."
30
27
  Process.exit(1)
31
28
  end
32
-
33
- rescue ArgumentError
34
- $stderr.puts "Invalid arguments provided to method. Check documentation."
35
- Process.exit(1)
36
- rescue Codebase::NotConfiguredError
37
- puts "[Error] You have not configured the Codebase gem yet. Run 'cb setup' to run the setup tool."
38
- Process.exit(1)
39
- rescue Codebase::MustBeInRepositoryError
40
- puts "[Error] You must be inside a Codebase repository to run this command."
41
- Process.exit(1)
42
- rescue Codebase::Error => e
43
- $stderr.puts e.message
44
- Process.exit(1)
29
+ @commands[command][:block].call(options, *args)
30
+ else
31
+ puts "Command not found. Check 'cb help' for full information."
45
32
  end
33
+ end
34
+
35
+ def command(command, options = {}, &block)
36
+ @commands = Hash.new if @commands.nil?
37
+ @commands[command] = Hash.new
38
+ @commands[command][:description] = @next_description
39
+ @commands[command][:usage] = @next_usage
40
+ @commands[command][:flags] = @next_flags
41
+ @commands[command][:required_args] = (options[:required_args] || 0)
42
+ @commands[command][:block] = Command.new(block)
43
+ @next_usage, @next_description, @next_flags = nil, nil, nil
44
+ end
45
+
46
+ def commands
47
+ @commands
48
+ end
49
+
50
+ def desc(value)
51
+ @next_description = Array.new if @next_description.nil?
52
+ @next_description << value
53
+ end
54
+
55
+ def usage(value)
56
+ @next_usage = value
57
+ end
58
+
59
+ def flags(key, value)
60
+ @next_flags = Hash.new if @next_flags.nil?
61
+ @next_flags[key] = value
62
+ end
63
+
64
+ def load_commands
65
+ Dir[File.join(File.dirname(__FILE__), 'commands', '*.rb')].each do |path|
66
+ Codebase.module_eval File.read(path), path
67
+ end
68
+ end
69
+
70
+ def parse_options(args)
71
+ idx = 0
72
+ args.clone.inject({}) do |memo, arg|
73
+ case arg
74
+ when /^--(.+?)=(.*)/
75
+ args.delete_at(idx)
76
+ memo.merge($1.to_sym => $2)
77
+ when /^--(.+)/
78
+ args.delete_at(idx)
79
+ memo.merge($1.to_sym => true)
80
+ when "--"
81
+ args.delete_at(idx)
82
+ return memo
83
+ else
84
+ idx += 1
85
+ memo
86
+ end
87
+ end
88
+ end
89
+
90
+ end
46
91
 
92
+ Codebase.desc "Displays this help message"
93
+ Codebase.usage "cb help [command]"
94
+ Codebase.command "help" do |command|
95
+ if command.nil?
96
+ puts "The Codebase Gem allows you to easily access your Codebase account functions from the"
97
+ puts "command line. The functions below outline the options which are currently available."
98
+ puts
99
+ for key, command in Codebase.commands.sort_by{|k,v| k}
100
+ puts " #{key.ljust(15)} #{command[:description].first}"
101
+ end
102
+ puts
103
+ puts "For more information see http://docs.codebasehq.com/gem"
104
+ puts "See 'cb help [command]' for usage information."
105
+ else
106
+ if c = Codebase.commands[command]
107
+ puts c[:description]
108
+ if c[:usage]
109
+ puts
110
+ puts "Usage:"
111
+ puts " #{c[:usage]}"
112
+ end
113
+ if c[:flags]
114
+ puts
115
+ puts "Options:"
116
+ for key, value in c[:flags]
117
+ puts " #{key.ljust(15)} #{value}"
118
+ end
119
+ end
120
+ else
121
+ puts "Command Not Found. Check 'point help' for a full list of commands available to you."
122
+ end
47
123
  end
124
+ end
48
125
 
126
+ Codebase.desc "Displays the current version number"
127
+ Codebase.usage "cb version"
128
+ Codebase.command "version" do
129
+ puts "Codebase Gem Version #{Codebase::VERSION}"
49
130
  end
@@ -1,28 +1,31 @@
1
- require 'codebase/commands/setup'
2
- require 'codebase/commands/clone'
3
- require 'codebase/commands/branches'
4
- require 'codebase/commands/keys'
5
-
6
1
  module Codebase
7
2
  class Command
8
3
 
9
- include Codebase::Commands::Setup
10
- include Codebase::Commands::Clone
11
- include Codebase::Commands::Branches
12
- include Codebase::Commands::Keys
4
+ def initialize(block)
5
+ (class << self;self end).send :define_method, :command, &block
6
+ end
13
7
 
14
- def default
15
- puts "CodebaseHQ"
16
- puts "See http://docs.codebasehq.com/gem for documentation"
17
- if configured?
18
- puts "-> System configured for #{username} at #{domain}"
19
- else
20
- puts "-> Not configured yet. Run 'cb setup' to configure your local computer."
21
- end
8
+ def call(options, *args)
9
+ @options = options
10
+ arity = method(:command).arity
11
+ args << nil while args.size < arity
12
+ send :command, *args
22
13
  end
23
14
 
24
- private
15
+ def use_hirb
16
+ begin
17
+ require 'hirb'
18
+ extend Hirb::Console
19
+ rescue LoadError
20
+ puts "Hirb is not installed. Install hirb using '[sudo] gem install hirb' to get cool ASCII tables"
21
+ Process.exit(1)
22
+ end
23
+ end
25
24
 
25
+ def options
26
+ @options || Hash.new
27
+ end
28
+
26
29
  def configured?
27
30
  domain && username && apikey
28
31
  end
@@ -118,6 +121,6 @@ module Codebase
118
121
  def api(path, data = nil)
119
122
  api_request("http://#{domain}/#{path}", git_config_variable(:username), git_config_variable(:apikey), data)
120
123
  end
121
-
124
+
122
125
  end
123
- end
126
+ end
@@ -0,0 +1,28 @@
1
+ desc "Create a new branch locally and on the remote"
2
+ usage "cb mkbranch [new_branch_name] (source_branch)"
3
+ flags "--origin", "The origin to use when pushing to remote"
4
+ command "mkbranch", :required_args => 1 do |branch_name, source_branch|
5
+ source_branch = "master" if source_branch.nil?
6
+ remote_origin = "origin" if @options[:origin].nil?
7
+ commands = []
8
+ commands << "git push origin #{source_branch}:refs/heads/#{branch_name}"
9
+ commands << "git fetch origin"
10
+ commands << "git branch --track #{branch_name} origin/#{branch_name}"
11
+ commands << "git checkout #{branch_name}"
12
+ execute_commands(commands)
13
+ end
14
+
15
+ desc "Remove a branch from the remote service and remove it locally if it exists."
16
+ usage "cb rmbranch [branch_name]"
17
+ command "rmbranch", :required_args => 1 do |branch_name|
18
+ commands = []
19
+ commands << "git push origin :#{branch_name}"
20
+ unless `git for-each-ref refs/heads/#{branch_name}`.empty?
21
+ current_branch = `git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`.chomp.split(/\s+/).last
22
+ if branch_name == current_branch
23
+ commands << "git checkout master" ## assume master...
24
+ end
25
+ commands << "git branch -d #{branch_name}"
26
+ end
27
+ execute_commands(commands)
28
+ end
@@ -0,0 +1,66 @@
1
+ desc "Clone a repository."
2
+ desc "The application will ask you to choose a project & repository before cloning the repository to your clone computer."
3
+ usage "cb clone"
4
+ flags "--path", "The path to export your repository to (optional)"
5
+ command "clone" do
6
+ require 'rubygems'
7
+ require 'json'
8
+ require 'highline/import'
9
+ HighLine.track_eof = false
10
+
11
+ raise Codebase::NotConfiguredError unless configured?
12
+
13
+ projects = JSON.parse(api('projects'))
14
+ projects = projects.select{|p| p["project"]["status"].first == 'active'}.map{|p| p['project']}
15
+
16
+ ## Please somebody tell me there is a better way to do this using highline...
17
+ project_hash = {}
18
+ project_id = choose do |menu|
19
+ menu.select_by = :index
20
+ menu.prompt = "Please select a project: "
21
+ count = 0
22
+ for project in projects
23
+ project_hash[project['name']] = project['permalink']
24
+ menu.choice(project['name'])
25
+ end
26
+ end
27
+
28
+ project = project_hash[project_id]
29
+
30
+ repositories = JSON.parse(api("#{project}/repositories"))
31
+ repositories = repositories.map{|r| r['repository']}
32
+
33
+ repos_hash = {}
34
+ repo_id = choose do |menu|
35
+ menu.select_by = :index
36
+ menu.prompt = "Please select a repository:"
37
+ for repository in repositories
38
+ repos_hash[repository['name']] = repository
39
+ menu.choice(repository['name'])
40
+ end
41
+ end
42
+
43
+ repository = repos_hash[repo_id]['permalink']
44
+ clone_url = repos_hash[repo_id]['clone_url']
45
+ scm = repos_hash[repo_id]['scm']
46
+
47
+ if @options[:path]
48
+ export_path = @options[:path]
49
+ else
50
+ export_path = File.join(project, repository)
51
+ folder = ask("Where would you like to clone this repository to? (default: #{export_path})")
52
+ unless folder.nil? || folder.empty?
53
+ export_path = folder
54
+ end
55
+ end
56
+
57
+ system("mkdir -p #{export_path}")
58
+
59
+ case scm
60
+ when 'git' then exec("git clone #{clone_url} #{export_path}")
61
+ when 'hg' then exec("hg clone ssh://#{clone_url} #{export_path}")
62
+ when 'svn' then exec("svn checkout #{clone_url} #{export_path}")
63
+ else
64
+ puts "Unsupported SCM."
65
+ end
66
+ end
@@ -0,0 +1,30 @@
1
+ desc "View a list of all keys assigned to your user account. All keys are displayed in a table."
2
+ usage "cb keys"
3
+ command "keys" do
4
+ require 'rubygems'
5
+ use_hirb
6
+
7
+ keys = api("users/#{username}/public_keys")
8
+ keys = JSON.parse(keys).map{|k| k['public_key_join']}
9
+ keys = keys.map{|k| {:description => k['description'], :key => k['key'][0, 50] + '...' }}
10
+ table keys, :fields => [:description, :key], :headers => {:description => 'Description', :key => 'Key'}
11
+ end
12
+
13
+ desc "Add a new key to your Codebase user account. "
14
+ desc "By default, it will use the key located in '~/.ssh/id_rsa.pub' otherwise it'll use the key you specify."
15
+ flags "--description", "Description to use when uploading the key. Defaults to 'Key'"
16
+ usage "cb keys:add (path/to/key)"
17
+ command "keys:add" do |path|
18
+ path = File.expand_path(".ssh/id_rsa.pub", "~") if path.nil?
19
+ unless File.exist?(path)
20
+ puts "Key file not found at '#{path}'"
21
+ Process.exit(1)
22
+ end
23
+
24
+ data = {'public_key' => {'description' => (options[:description] || "Key"), 'key' => File.read(path)}}.to_json
25
+ if api("users/#{username}/public_keys", data)
26
+ puts "Successfully added key."
27
+ else
28
+ puts "An error occured while adding your key."
29
+ end
30
+ end
@@ -0,0 +1,66 @@
1
+ desc "Setup the Codebase gem for your user account"
2
+ desc "This tool will automatically prompt you for your login details and then download your"
3
+ desc "details (including API key) and configure your local computer to use them."
4
+ usage "cb setup"
5
+ command "setup" do
6
+
7
+ require 'highline/import'
8
+
9
+ ## We need git...
10
+ unless `which git` && $?.success?
11
+ puts "To use the Codebase gem you must have Git installed on your local computer. Git is used to store"
12
+ puts "important configuration variables which allow the gem to function."
13
+ Process.exit(1)
14
+ end
15
+
16
+ puts "\e[33;44mWelcome to the CodebaseHQ Initial Setup Tool\e[0m"
17
+ puts "This tool will get your local computer configured to use your codebase account. It will automatically configure"
18
+ puts "the gem for API access so you can use many of the gem functions."
19
+ puts
20
+
21
+ ## Are you in a repository?
22
+ global = '--global'
23
+ if in_repository?
24
+ puts "You are currently in a repository directory."
25
+ if agree("Would you like to only apply configuration to actions carried out from within this directory?")
26
+ global = ''
27
+ puts "OK, we'll add your API details to this repository only."
28
+ else
29
+ puts "OK, we'll configure your API details for your whole user account."
30
+ end
31
+ end
32
+
33
+ ## Is this configured?
34
+ if configured? && !global.empty?
35
+ puts
36
+ puts "This system is already configured as \e[32m#{username}\e[0m."
37
+ unless agree("Do you wish to continue?")
38
+ Process.exit(0)
39
+ end
40
+ end
41
+
42
+ puts
43
+
44
+ ## Get some details
45
+ domain = ask("CodebaseHQ domain (e.g. widgetinc.codebasehq.com): ") { |q| q.validate = /\A(\w+).(codebasehq|cbhqdev).(com|local)\z/ }
46
+ username = ask("Username: ") { |q| q.validate = /[\w\.]+/ }
47
+ password = ask("Password: ") { |q| q.echo = false }
48
+
49
+ ## Get the API key and save it...
50
+ user_properties = api_request("https://#{domain}/profile", username, password)
51
+
52
+ if user_properties
53
+ user = JSON.parse(user_properties)["user"]
54
+ system("git config #{global} codebase.username #{username}")
55
+ system("git config #{global} codebase.apikey #{user['api_key']}")
56
+ system("git config #{global} codebase.domain #{domain}")
57
+ system("git config #{global} user.name '#{user['first_name']} #{user['last_name']}'")
58
+ puts "Set user.name to '#{user['first_name']} #{user['last_name']}'"
59
+ system("git config #{global} user.email #{user['email_address']}")
60
+ puts "Set user.email to '#{user['email_address']}'"
61
+ puts "\e[32mConfigured Codebase API authentication properties successfully.\e[0m"
62
+ else
63
+ puts "\e[37;41mAccess Denied. Please ensure you have entered your username & password correctly and try again.\e[0m"
64
+ return
65
+ end
66
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebase
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-27 00:00:00 +00:00
12
+ date: 2009-10-28 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.1.5
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hirb
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.2.7
44
+ version:
35
45
  description:
36
46
  email: adam@atechmedia.com
37
47
  executables:
@@ -45,12 +55,11 @@ files:
45
55
  - bin/cb
46
56
  - bin/codebase
47
57
  - lib/codebase/command.rb
48
- - lib/codebase/commands/branches.rb
49
- - lib/codebase/commands/clone.rb
50
- - lib/codebase/commands/keys.rb
51
- - lib/codebase/commands/setup.rb
52
- - lib/codebase/recipes.rb
53
58
  - lib/codebase.rb
59
+ - lib/commands/branches.rb
60
+ - lib/commands/clone.rb
61
+ - lib/commands/keys.rb
62
+ - lib/commands/setup.rb
54
63
  has_rdoc: true
55
64
  homepage: http://www.codebasehq.com
56
65
  licenses: []
@@ -78,6 +87,6 @@ rubyforge_project:
78
87
  rubygems_version: 1.3.5
79
88
  signing_key:
80
89
  specification_version: 3
81
- summary: Provides easy access to the Codebase interface by adding some launchy options. Also, includes the default Capistrano recipe for tracking deployments.
90
+ summary: Gem companion for your Codebase account. Including interactive cloning, key management and more
82
91
  test_files: []
83
92
 
@@ -1,27 +0,0 @@
1
- module Codebase
2
- module Commands
3
- module Branches
4
-
5
- ## =========================================================================================================
6
- ## Remote Branch Management
7
- ## =========================================================================================================
8
-
9
- def mkbranch(branch_name, source_branch = 'master')
10
- commands = []
11
- commands << "git push origin #{source_branch}:refs/heads/#{branch_name}"
12
- commands << "git fetch origin"
13
- commands << "git branch --track #{branch_name} origin/#{branch_name}"
14
- commands << "git checkout #{branch_name}"
15
- execute_commands(commands)
16
- end
17
-
18
- def rmbranch(branch_name)
19
- commands = []
20
- commands << "git push origin :#{branch_name}"
21
- commands << "git branch -d #{branch_name}"
22
- execute_commands(commands)
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,65 +0,0 @@
1
- module Codebase
2
- module Commands
3
- module Clone
4
-
5
- ## =========================================================================================================
6
- ## Interactive Clone
7
- ## =========================================================================================================
8
-
9
- def clone
10
- raise Codebase::NotConfiguredError unless configured?
11
-
12
- projects = JSON.parse(api('projects'))
13
- projects = projects.select{|p| p["project"]["status"].first == 'active'}.map{|p| p['project']}
14
-
15
- ## Please somebody tell me there is a better way to do this using highline...
16
- project_hash = {}
17
- project_id = choose do |menu|
18
- menu.select_by = :index
19
- menu.prompt = "Please select a project: "
20
- count = 0
21
- for project in projects
22
- project_hash[project['name']] = project['permalink']
23
- menu.choice(project['name'])
24
- end
25
- end
26
-
27
- project = project_hash[project_id]
28
-
29
- repositories = JSON.parse(api("#{project}/repositories"))
30
- repositories = repositories.map{|r| r['repository']}
31
-
32
- repos_hash = {}
33
- repo_id = choose do |menu|
34
- menu.select_by = :index
35
- menu.prompt = "Please select a repository:"
36
- for repository in repositories
37
- repos_hash[repository['name']] = repository
38
- menu.choice(repository['name'])
39
- end
40
- end
41
-
42
- repository = repos_hash[repo_id]['permalink']
43
- clone_url = repos_hash[repo_id]['clone_url']
44
- scm = repos_hash[repo_id]['scm']
45
-
46
- export_path = File.join(project, repository)
47
- folder = ask("Where would you like to clone this repository to? (default: #{export_path})")
48
- unless folder.nil? || folder.empty?
49
- export_path = folder
50
- end
51
-
52
- system("mkdir -p #{export_path}")
53
-
54
- case scm
55
- when 'git' then exec("git clone #{clone_url} #{export_path}")
56
- when 'hg' then exec("hg clone ssh://#{clone_url} #{export_path}")
57
- when 'svn' then exec("svn checkout #{clone_url} #{export_path}")
58
- else
59
- puts "Unsupported SCM."
60
- end
61
- end
62
-
63
- end
64
- end
65
- end
@@ -1,36 +0,0 @@
1
- module Codebase
2
- module Commands
3
- module Keys
4
-
5
- ## =========================================================================================================
6
- ## Keys
7
- ## =========================================================================================================
8
-
9
- require 'hirb'
10
- include Hirb::Console
11
-
12
- def keys
13
- keys = api("users/#{username}/public_keys")
14
- keys = JSON.parse(keys).map{|k| k['public_key_join']}
15
- keys = keys.map{|k| {:description => k['description'], :key => k['key'][0, 50] + '...' }}
16
- table keys, :fields => [:description, :key], :headers => {:description => 'Description', :key => 'Key'}
17
- end
18
-
19
- def add_key(path = nil)
20
- path = File.expand_path(".ssh/id_rsa.pub", "~") if path.nil?
21
- unless File.exist?(path)
22
- puts "Key file not found at '#{path}'"
23
- Process.exit(1)
24
- end
25
-
26
- data = {'public_key' => {'description' => "Key", 'key' => File.read(path)}}.to_json
27
- if api("users/#{username}/public_keys", data)
28
- puts "Successfully added key."
29
- else
30
- puts "An error occured while adding your key."
31
- end
32
- end
33
-
34
- end
35
- end
36
- end
@@ -1,88 +0,0 @@
1
- module Codebase
2
- module Commands
3
- module Setup
4
-
5
- ## =========================================================================================================
6
- ## API Setup Tools
7
- ## =========================================================================================================
8
-
9
- def setup
10
-
11
- ## We need git...
12
- unless `which git` && $?.success?
13
- puts "To use the Codebase gem you must have Git installed on your local computer. Git is used to store"
14
- puts "important configuration variables which allow the gem to function."
15
- Process.exit(1)
16
- end
17
-
18
- puts "\e[33;44mWelcome to the CodebaseHQ Initial Setup Tool\e[0m"
19
- puts "This tool will get your local computer configured to use your codebase account. It will automatically configure"
20
- puts "the gem for API access so you can use many of the gem functions."
21
- puts
22
-
23
- ## Are you in a repository?
24
- global = '--global'
25
- if in_repository?
26
- puts "You are currently in a repository directory."
27
- if agree("Would you like to only apply configuration to actions carried out from within this directory?")
28
- global = ''
29
- puts "OK, we'll add your API details to this repository only."
30
- else
31
- puts "OK, we'll configure your API details for your whole user account."
32
- end
33
- end
34
-
35
- ## Is this configured?
36
- if configured? && !global.empty?
37
- puts
38
- puts "This system is already configured as \e[32m#{username}\e[0m."
39
- unless agree("Do you wish to continue?")
40
- Process.exit(0)
41
- end
42
- end
43
-
44
- puts
45
-
46
- ## Get some details
47
- domain = ask_with_validation("CodebaseHQ domain (e.g. widgetinc.codebasehq.com): ", /\A(\w+).(codebasehq|cbhqdev).(com|local)\z/)
48
- username = ask_with_validation("Username: ", /[\w\.]+/)
49
- password = ask("Password: ") { |q| q.echo = false }
50
-
51
- ## Get the API key and save it...
52
- user_properties = api_request("https://#{domain}/profile", username, password)
53
-
54
- if user_properties
55
- user = JSON.parse(user_properties)["user"]
56
- system("git config #{global} codebase.username #{username}")
57
- system("git config #{global} codebase.apikey #{user['api_key']}")
58
- system("git config #{global} codebase.domain #{domain}")
59
- system("git config #{global} user.name '#{user['first_name']} #{user['last_name']}'")
60
- puts "Set user.name to '#{user['first_name']} #{user['last_name']}'"
61
- system("git config #{global} user.email #{user['email_address']}")
62
- puts "Set user.email to '#{user['email_address']}'"
63
- puts "\e[32mConfigured Codebase API authentication properties successfully.\e[0m"
64
- else
65
- puts "\e[37;41mAccess Denied. Please ensure you have entered your username & password correctly and try again.\e[0m"
66
- return
67
- end
68
-
69
- end
70
-
71
- def unsetup
72
- ['', '--global'].each do |type|
73
- system("git config #{type} --unset codebase.username")
74
- system("git config #{type} --unset codebase.apikey")
75
- system("git config #{type} --unset codebase.domain")
76
- end
77
- puts "System has been unsetup. API details have been removed from your configuration."
78
- end
79
-
80
- private
81
-
82
- def ask_with_validation(question, regex)
83
- ask(question) { |q| q.validate = regex }
84
- end
85
-
86
- end
87
- end
88
- end
@@ -1,76 +0,0 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
-
3
- after "deploy:symlink", :add_deployment_to_codebase
4
-
5
- task :add_deployment_to_codebase do
6
-
7
- username = `git config codebase.username`.chomp.strip
8
- api_key = `git config codebase.apikey`.chomp.strip
9
-
10
- regex = /git\@(gitbase|codebasehq)\.com:(.*)\/(.*)\/(.*)\.git/
11
- unless m = repository.match(regex)
12
- puts " * \e[31mYour repository URL does not a match a valid CodebaseHQ Clone URL\e[0m"
13
- else
14
- url = "#{m[2]}.codebasehq.com"
15
- project = m[3]
16
- repository = m[4]
17
-
18
- puts " * \e[44;33mAdding Deployment to your CodebaseHQ account\e[0m"
19
- puts " - Account......: #{url}"
20
- puts " - Username.....: #{username}"
21
- puts " - API Key......: #{api_key[0,10]}..."
22
-
23
- puts " - Project......: #{project}"
24
- puts " - Repository...: #{repository}"
25
-
26
-
27
- environment_to_send = begin
28
- env = (self.environment rescue self.rails_env).dup
29
- env.gsub!(/\W+/, ' ')
30
- env.strip!
31
- env.downcase!
32
- env.gsub!(/\ +/, '-')
33
-
34
- puts " - Environment..: #{env}" unless env.blank?
35
-
36
- env
37
- rescue
38
- ''
39
- end
40
-
41
- servers = roles.values.collect{|r| r.servers}.flatten.collect{|s| s.host}.uniq.join(', ') rescue ''
42
-
43
- puts " - Servers......: #{servers}"
44
- puts " - Revision.....: #{real_revision}"
45
- puts " - Branch.......: #{branch}"
46
-
47
- xml = []
48
- xml << "<deployment>"
49
- xml << "<servers>#{servers}</servers>"
50
- xml << "<revision>#{real_revision}</revision>"
51
- xml << "<environment>#{environment_to_send}</environment>"
52
- xml << "<branch>#{branch}</branch>"
53
- xml << "</deployment>"
54
-
55
- require 'net/http'
56
- require 'uri'
57
-
58
- real_url = "http://#{url}/#{project}/#{repository}/deployments"
59
- puts " - URL..........: #{real_url}"
60
-
61
- url = URI.parse(real_url)
62
-
63
- req = Net::HTTP::Post.new(url.path)
64
- req.basic_auth(username, api_key)
65
- req.add_field('Content-type', 'application/xml')
66
- req.add_field('Accept', 'application/xml')
67
- res = Net::HTTP.new(url.host, url.port).start { |http| http.request(req, xml.join) }
68
- case res
69
- when Net::HTTPCreated then puts " * \e[32mAdded deployment to Codebase\e[0m"
70
- else
71
- puts " * \e[31mSorry, your deployment was not logged in Codebase - please check your config above.\e[0m"
72
- end
73
- end
74
-
75
- end
76
- end