codebase 4.0.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/codebase/recipes.rb +76 -0
  2. metadata +2 -1
@@ -0,0 +1,76 @@
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
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: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
@@ -55,6 +55,7 @@ files:
55
55
  - bin/cb
56
56
  - bin/codebase
57
57
  - lib/codebase/command.rb
58
+ - lib/codebase/recipes.rb
58
59
  - lib/codebase.rb
59
60
  - lib/commands/branches.rb
60
61
  - lib/commands/clone.rb