codebase 3.1.1 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  require 'codebase/commands/launchers'
2
2
  require 'codebase/commands/branches'
3
3
  require 'codebase/commands/setup'
4
+ require 'codebase/commands/deployments'
4
5
 
5
6
  module Codebase
6
7
  class Command
@@ -8,6 +9,7 @@ module Codebase
8
9
  include Codebase::Commands::Launchers
9
10
  include Codebase::Commands::Branches
10
11
  include Codebase::Commands::Setup
12
+ include Codebase::Commands::Deployments
11
13
 
12
14
  attr_reader :directory, :args
13
15
 
@@ -43,5 +45,35 @@ module Codebase
43
45
  end
44
46
  end
45
47
 
48
+ def git_config_variable(name)
49
+ r = `git config --global codebase.#{name.to_s}`.chomp
50
+ r.empty? ? nil : r
51
+ end
52
+
53
+ def api_request(url, username, password, data = nil)
54
+ require 'uri'
55
+ require 'net/http'
56
+ require 'net/https'
57
+ uri = URI.parse(url)
58
+ if data
59
+ req = Net::HTTP::Post.new(uri.path)
60
+ else
61
+ req = Net::HTTP::Get.new(uri.path)
62
+ end
63
+
64
+ req.basic_auth(username, password)
65
+ req.add_field("Accept", "application/xml")
66
+ req.add_field("Content-type", "application/xml")
67
+ res = Net::HTTP.new(uri.host, uri.port)
68
+ res = res.request(req, data)
69
+ case res
70
+ when Net::HTTPSuccess
71
+ return res.body
72
+ else
73
+ puts res.body
74
+ return false
75
+ end
76
+ end
77
+
46
78
  end
47
79
  end
@@ -0,0 +1,33 @@
1
+ module Codebase
2
+ module Commands
3
+ module Deployments
4
+
5
+ def track_deploy(revision)
6
+
7
+ unless directory.repository?
8
+ puts "This is not a valid Codebase repository. Ensure you are currently in the directory of the repository you wish to track."
9
+ return
10
+ end
11
+
12
+ xml = []
13
+ xml << "<deployment>"
14
+ xml << "<servers>#{ENV['CBSERVERS']}</servers>"
15
+ xml << "<revision>#{revision}</revision>"
16
+ xml << "<environment>#{ENV['CBENVIRONMENT']}</environment>"
17
+ xml << "<branch>#{ENV['CBBRANCH']}</branch>"
18
+ xml << "</deployment>"
19
+
20
+ username = git_config_variable(:username)
21
+ password = git_config_variable(:apikey)
22
+
23
+ if api_request("http://#{directory.account}.codebasehq.com/#{directory.project}/#{directory.repository}/deployments", username, password, xml.join)
24
+ puts "\e[32mDeployment tracked successfully.\e[0m"
25
+ else
26
+ puts "\e[31mDeployment was not successfully tracked.\e[0m"
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -29,9 +29,9 @@ module Codebase
29
29
  password = ask_for_password('Password: ')
30
30
 
31
31
  ## Get the API key and save it...
32
- user_properties_xml = api_request("http://#{domain}/users/#{username}", username, password)
33
- if user_properties_xml && user_properties_xml.match(/\<api-key\>(\w{40})\<\/api-key>/)
34
- api_key = $1
32
+ api_key = api_request("https://#{domain}/apikey", username, password)
33
+ if api_key
34
+ api_key = api_key.chomp
35
35
  system("git config --global codebase.username #{username}")
36
36
  system("git config --global codebase.apikey #{api_key}")
37
37
  system("git config --global codebase.domain #{domain}")
@@ -68,11 +68,6 @@ module Codebase
68
68
 
69
69
  private
70
70
 
71
- def git_config_variable(name)
72
- r = `git config --global codebase.#{name.to_s}`.chomp
73
- r.empty? ? nil : r
74
- end
75
-
76
71
  def ask_with_validation(question, regex)
77
72
  ask(question) { |q| q.validate = regex }
78
73
  end
@@ -85,31 +80,6 @@ module Codebase
85
80
  password
86
81
  end
87
82
 
88
- def api_request(url, username, password, data = nil)
89
- require 'uri'
90
- require 'net/http'
91
- require 'net/https'
92
- uri = URI.parse(url)
93
- if data
94
- req = Net::HTTP::Post.new(uri.path)
95
- else
96
- req = Net::HTTP::Get.new(uri.path)
97
- end
98
-
99
- req.basic_auth(username, password)
100
- req.add_field("Accept", "application/xml")
101
- req.add_field("Content-type", "application/xml")
102
- res = Net::HTTP.new(uri.host, uri.port)
103
- res = res.request(req, data)
104
- case res
105
- when Net::HTTPSuccess
106
- return res.body
107
- else
108
- puts res.body
109
- return false
110
- end
111
- end
112
-
113
83
  def machine_hostname
114
84
  require 'socket'
115
85
  Socket.gethostname
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.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
@@ -36,6 +36,7 @@ files:
36
36
  - bin/codebase
37
37
  - lib/codebase/command.rb
38
38
  - lib/codebase/commands/branches.rb
39
+ - lib/codebase/commands/deployments.rb
39
40
  - lib/codebase/commands/launchers.rb
40
41
  - lib/codebase/commands/setup.rb
41
42
  - lib/codebase/directory.rb