codebase 4.0.8 → 4.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ module Codebase
14
14
  class NotConfiguredError < StandardError; end
15
15
  class MustBeInRepositoryError < StandardError; end
16
16
 
17
- VERSION = "4.0.8"
17
+ VERSION = "4.0.9"
18
18
 
19
19
  def run(command, args = [])
20
20
  load_commands
@@ -100,7 +100,7 @@ Codebase.command "help" do |command|
100
100
  puts " #{key.ljust(15)} #{command[:description].first}"
101
101
  end
102
102
  puts
103
- puts "For more information see http://docs.codebasehq.com/gem"
103
+ puts "For more information see http://docs.atechmedia.com/codebase/gem"
104
104
  puts "See 'cb help [command]' for usage information."
105
105
  else
106
106
  if c = Codebase.commands[command]
@@ -115,6 +115,11 @@ module Codebase
115
115
  case res
116
116
  when Net::HTTPSuccess
117
117
  return res.body
118
+ when Net::HTTPFound
119
+ if res.body =~ /http:\/\/api3.codebasehq.com/ && url.include?('https://')
120
+ puts "Falling back to non SSL"
121
+ api_request(url.gsub("https://", "http://"), username, password)
122
+ end
118
123
  when Net::HTTPServiceUnavailable
119
124
  puts "The API is currently unavailable. Please check your codebase account has been enabled for API access."
120
125
  Process.exit(1)
@@ -1,4 +1,66 @@
1
1
  Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ def git_config_variable(name)
4
+ if name.is_a?(Symbol)
5
+ r = `git config codebase.#{name.to_s}`.chomp
6
+ else
7
+ r = `git config #{name.to_s}`.chomp
8
+ end
9
+ r.empty? ? nil : r
10
+ end
11
+
12
+ def new_username?
13
+ git_config_variable(:username).match(/(.+)\/(.+)/)
14
+ end
15
+
16
+ def domain
17
+ @domain ||= new_username? ? "#{new_username?[1]}.codebasehq.com" : git_config_variable(:domain)
18
+ end
19
+
20
+ def username
21
+ @username ||= new_username? ? new_username?[2] : git_config_variable(:username)
22
+ end
23
+
24
+ def api_username
25
+ @api_username = "#{domain.split('.').first}/#{username}"
26
+ end
27
+
28
+ def api_key
29
+ @api_key ||= git_config_variable(:apikey)
30
+ end
31
+
32
+ def api_request(url, data)
33
+ require 'net/http'
34
+ require 'net/https'
35
+ require 'uri'
36
+
37
+ puts " - URL..........: #{url}"
38
+
39
+ uri = URI.parse(url)
40
+
41
+ req = Net::HTTP::Post.new(uri.path)
42
+ req.basic_auth(api_username, api_key)
43
+ req.add_field('Content-type', 'application/xml')
44
+ req.add_field('Accept', 'application/xml')
45
+
46
+ res = Net::HTTP.new(uri.host, uri.port)
47
+ if url.include?('https://')
48
+ res.use_ssl = true
49
+ res.verify_mode = OpenSSL::SSL::VERIFY_NONE
50
+ end
51
+ res = res.request(req, data)
52
+
53
+ case res
54
+ when Net::HTTPCreated then puts " * \e[32mAdded deployment to Codebase\e[0m"
55
+ when Net::HTTPFound
56
+ if res.body =~ /http:\/\/api3.codebasehq.com/ && url.include?('https://')
57
+ puts " - Status.......: Falling back to non SSL"
58
+ api_request(url.gsub("https://", "http://"), data)
59
+ end
60
+ else
61
+ puts " * \e[31mSorry, your deployment was not logged in Codebase - please check your config above.\e[0m"
62
+ end
63
+ end
2
64
 
3
65
  after "deploy:symlink", 'codebase:deploy'
4
66
 
@@ -19,10 +81,8 @@ Capistrano::Configuration.instance(:must_exist).load do
19
81
 
20
82
  desc 'Log a deployment in Codebase'
21
83
  task :deploy do
22
- username = `git config codebase.username`.chomp.strip
23
- api_key = `git config codebase.apikey`.chomp.strip
24
-
25
- if username == '' || api_key == ''
84
+
85
+ if api_username == '' || api_key == ''
26
86
  puts " * Codebase is not configured on your computer. Run 'codebase setup' to auto configure it."
27
87
  puts " * Deployments will not be tracked."
28
88
  next
@@ -36,9 +96,14 @@ Capistrano::Configuration.instance(:must_exist).load do
36
96
  project = m[3]
37
97
  repository = m[4]
38
98
 
99
+ unless respond_to?(:branch)
100
+ branch = 'HEAD'
101
+ end
102
+
103
+
39
104
  puts " * \e[44;33mAdding Deployment to your CodebaseHQ account\e[0m"
40
105
  puts " - Account......: #{url}"
41
- puts " - Username.....: #{username}"
106
+ puts " - Username.....: #{api_username}"
42
107
  puts " - API Key......: #{api_key[0,10]}..."
43
108
 
44
109
  puts " - Project......: #{project}"
@@ -71,28 +136,13 @@ Capistrano::Configuration.instance(:must_exist).load do
71
136
  xml << "<environment>#{environment_to_send}</environment>"
72
137
  xml << "<branch>#{branch}</branch>"
73
138
  xml << "</deployment>"
74
-
75
- require 'net/http'
76
- require 'uri'
77
-
139
+
78
140
  # URL should be in this format to be compatible with the new API
79
141
  # http://api3.codebasehq.com/PROJECTNAME/REPO/deployments
142
+
143
+ real_url = "https://api3.codebasehq.com/#{project}/#{repository}/deployments"
144
+ api_request(real_url, xml.join)
80
145
 
81
- real_url = "http://api3.codebasehq.com/#{project}/#{repository}/deployments"
82
- puts " - URL..........: #{real_url}"
83
-
84
- url = URI.parse(real_url)
85
-
86
- req = Net::HTTP::Post.new(url.path)
87
- req.basic_auth(username, api_key)
88
- req.add_field('Content-type', 'application/xml')
89
- req.add_field('Accept', 'application/xml')
90
- res = Net::HTTP.new(url.host, url.port).start { |http| http.request(req, xml.join) }
91
- case res
92
- when Net::HTTPCreated then puts " * \e[32mAdded deployment to Codebase\e[0m"
93
- else
94
- puts " * \e[31mSorry, your deployment was not logged in Codebase - please check your config above.\e[0m"
95
- end
96
146
  end
97
147
  end
98
148
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: codebase
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 4.0.8
5
+ version: 4.0.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Adam Cooke
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-17 00:00:00 +01:00
13
+ date: 2011-05-23 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency