codebase 3.0.9 → 3.1.0
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.
- data/lib/codebase.rb +5 -4
- data/lib/{codebase_helpers/command_base.rb → codebase/command.rb} +12 -4
- data/lib/codebase/commands/branches.rb +27 -0
- data/lib/codebase/commands/launchers.rb +70 -0
- data/lib/codebase/commands/setup.rb +122 -0
- data/lib/{codebase_helpers → codebase}/directory.rb +1 -1
- metadata +7 -5
- data/lib/codebase_helpers/command.rb +0 -124
data/lib/codebase.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require 'codebase_helpers/directory'
|
3
|
+
require 'codebase/command'
|
4
|
+
require 'codebase/directory'
|
6
5
|
|
7
6
|
module Codebase
|
8
7
|
|
@@ -18,8 +17,10 @@ module Codebase
|
|
18
17
|
if command.respond_to?(method)
|
19
18
|
command.send(method, *args)
|
20
19
|
else
|
21
|
-
$stderr.puts "Command Not Found - please check http://
|
20
|
+
$stderr.puts "Command Not Found - please check http://docs.codebasehq.com/gem for documentation."
|
22
21
|
end
|
22
|
+
rescue ArgumentError
|
23
|
+
$stderr.puts "Invalid arguments provided to method. Check documentation."
|
23
24
|
rescue Codebase::Error => e
|
24
25
|
$stderr.puts e.message
|
25
26
|
end
|
@@ -1,6 +1,14 @@
|
|
1
|
+
require 'codebase/commands/launchers'
|
2
|
+
require 'codebase/commands/branches'
|
3
|
+
require 'codebase/commands/setup'
|
4
|
+
|
1
5
|
module Codebase
|
2
|
-
class
|
3
|
-
|
6
|
+
class Command
|
7
|
+
|
8
|
+
include Codebase::Commands::Launchers
|
9
|
+
include Codebase::Commands::Branches
|
10
|
+
include Codebase::Commands::Setup
|
11
|
+
|
4
12
|
attr_reader :directory, :args
|
5
13
|
|
6
14
|
def initialize(directory, args)
|
@@ -11,12 +19,12 @@ module Codebase
|
|
11
19
|
|
12
20
|
def launch(*args)
|
13
21
|
begin
|
14
|
-
|
22
|
+
require 'rubygems'
|
15
23
|
require 'launchy'
|
16
24
|
url = "http://#{directory.domain}/" + args.join('/').gsub(/\?\z/, "")
|
17
25
|
Launchy::Browser.new.visit(url)
|
18
26
|
rescue Gem::LoadError
|
19
|
-
raise Codebase::Error, "Sorry, you need to install launchy to do that - give 'gem install launchy' a go."
|
27
|
+
raise Codebase::Error, "Sorry, you need to install launchy to do that - give '[sudo] gem install launchy' a go."
|
20
28
|
end
|
21
29
|
end
|
22
30
|
|
@@ -0,0 +1,27 @@
|
|
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
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Codebase
|
2
|
+
module Commands
|
3
|
+
module Launchers
|
4
|
+
|
5
|
+
## =========================================================================================================
|
6
|
+
## Launchers
|
7
|
+
## =========================================================================================================
|
8
|
+
|
9
|
+
def default
|
10
|
+
if directory.repository?
|
11
|
+
launch directory.project
|
12
|
+
else
|
13
|
+
launch
|
14
|
+
end
|
15
|
+
end
|
16
|
+
alias_method :dashboard, :default
|
17
|
+
|
18
|
+
def messages
|
19
|
+
launch 'messages'
|
20
|
+
end
|
21
|
+
alias_method :me, :messages
|
22
|
+
|
23
|
+
def tickets
|
24
|
+
launch directory.project, 'tickets'
|
25
|
+
end
|
26
|
+
alias_method :ti, :tickets
|
27
|
+
|
28
|
+
def new_ticket
|
29
|
+
launch directory.project, 'tickets', 'new'
|
30
|
+
end
|
31
|
+
alias_method :nti, :new_ticket
|
32
|
+
|
33
|
+
def milestones
|
34
|
+
launch directory.project, 'milestones'
|
35
|
+
end
|
36
|
+
alias_method :mi, :milestones
|
37
|
+
|
38
|
+
def time
|
39
|
+
launch directory.project, 'time'
|
40
|
+
end
|
41
|
+
alias_method :tm, :time
|
42
|
+
|
43
|
+
def wiki
|
44
|
+
launch directory.project, 'wiki'
|
45
|
+
end
|
46
|
+
alias_method :wi, :wiki
|
47
|
+
|
48
|
+
def browser
|
49
|
+
launch directory.project, directory.repository, 'tree', directory.working_branch
|
50
|
+
end
|
51
|
+
alias_method :br, :browser
|
52
|
+
|
53
|
+
def commits
|
54
|
+
launch directory.project, directory.repository, 'commits', directory.working_branch
|
55
|
+
end
|
56
|
+
alias_method :co, :commits
|
57
|
+
|
58
|
+
def deployments
|
59
|
+
launch directory.project, directory.repository, 'deployments'
|
60
|
+
end
|
61
|
+
alias_method :de, :deployments
|
62
|
+
|
63
|
+
def tasks
|
64
|
+
launch directory.project, directory.repository, 'tasks', directory.working_branch
|
65
|
+
end
|
66
|
+
alias_method :ta, :tasks
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module Codebase
|
2
|
+
module Commands
|
3
|
+
module Setup
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'highline/import'
|
7
|
+
|
8
|
+
def setup
|
9
|
+
puts "\e[33;44mWelcome to the CodebaseHQ Initial Setup Tool\e[0m"
|
10
|
+
puts "This tool will get your local computer configured to use your codebase account. It will automatically configure"
|
11
|
+
puts "the gem for API access as well as uploading your public key file to your Codebase user account."
|
12
|
+
puts
|
13
|
+
|
14
|
+
## Is this configured?
|
15
|
+
if u = git_config_variable(:username)
|
16
|
+
puts "This system is already configured as \e[32m#{u}\e[0m."
|
17
|
+
domain = git_config_variable(:domain)
|
18
|
+
username = u
|
19
|
+
api_key = git_config_variable(:apikey)
|
20
|
+
|
21
|
+
unless agree("Are you sure you wish to continue with uploading your public keys?")
|
22
|
+
puts "OK, no problem."
|
23
|
+
return
|
24
|
+
end
|
25
|
+
else
|
26
|
+
## Get some details
|
27
|
+
domain = ask_with_validation("CodebaseHQ domain (e.g. widgetinc.codebasehq.com): ", /\A(\w+).(codebasehq|cbhqdev).(com|local)\z/)
|
28
|
+
username = ask_with_validation("Username: ", /[\w\.]+/)
|
29
|
+
password = ask_for_password('Password: ')
|
30
|
+
|
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
|
35
|
+
system("git config --global codebase.username #{username}")
|
36
|
+
system("git config --global codebase.apikey #{api_key}")
|
37
|
+
system("git config --global codebase.domain #{domain}")
|
38
|
+
puts "\e[32mConfigured Codebase API authentication properties.\e[0m"
|
39
|
+
else
|
40
|
+
puts "\e[37;41mAccess Denied. Please ensure you have entered your username & password correctly and try again.\e[0m"
|
41
|
+
return
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
## Send the user's public key to the server if they don't already have keys...
|
46
|
+
key_file = File.expand_path(File.join('~', '.ssh', 'id_rsa.pub'))
|
47
|
+
if File.exist?(key_file)
|
48
|
+
key = File.read(key_file)
|
49
|
+
description = "Key from #{machine_hostname}"
|
50
|
+
if api_request("http://#{domain}/users/#{username}/public_keys", username, api_key, "<public-key><description>#{description}</description><key>#{key}</key></public-key>")
|
51
|
+
puts "\e[32mPublic key from #{key_file} uploaded to your Codebase account on #{domain}.\e[0m"
|
52
|
+
else
|
53
|
+
puts "\e[37;41mWe couldn't upload your public key at this file. Please try later and verify your API key is correct.\e[0m"
|
54
|
+
end
|
55
|
+
|
56
|
+
else
|
57
|
+
puts "No key file found at #{key_file}. Nothing to upload to Codebase."
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def unsetup
|
63
|
+
system("git config --global --unset codebase.username")
|
64
|
+
system("git config --global --unset codebase.apikey")
|
65
|
+
system("git config --global --unset codebase.domain")
|
66
|
+
puts "System has been unsetup. API details have been removed from your configuration."
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
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
|
+
def ask_with_validation(question, regex)
|
77
|
+
ask(question) { |q| q.validate = regex }
|
78
|
+
end
|
79
|
+
|
80
|
+
def ask_for_password(question)
|
81
|
+
system("stty -echo")
|
82
|
+
password = ask(question)
|
83
|
+
system("stty echo")
|
84
|
+
puts
|
85
|
+
password
|
86
|
+
end
|
87
|
+
|
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
|
+
def machine_hostname
|
114
|
+
require 'socket'
|
115
|
+
Socket.gethostname
|
116
|
+
rescue
|
117
|
+
"local computer"
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
122
|
+
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.0
|
4
|
+
version: 3.1.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-
|
12
|
+
date: 2009-10-26 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -25,11 +25,13 @@ extra_rdoc_files: []
|
|
25
25
|
files:
|
26
26
|
- bin/cb
|
27
27
|
- bin/codebase
|
28
|
+
- lib/codebase/command.rb
|
29
|
+
- lib/codebase/commands/branches.rb
|
30
|
+
- lib/codebase/commands/launchers.rb
|
31
|
+
- lib/codebase/commands/setup.rb
|
32
|
+
- lib/codebase/directory.rb
|
28
33
|
- lib/codebase/recipes.rb
|
29
34
|
- lib/codebase.rb
|
30
|
-
- lib/codebase_helpers/command.rb
|
31
|
-
- lib/codebase_helpers/command_base.rb
|
32
|
-
- lib/codebase_helpers/directory.rb
|
33
35
|
has_rdoc: true
|
34
36
|
homepage: http://www.codebasehq.com
|
35
37
|
licenses: []
|
@@ -1,124 +0,0 @@
|
|
1
|
-
module Codebase
|
2
|
-
class Command < CommandBase
|
3
|
-
|
4
|
-
## =========================================================================================================
|
5
|
-
## Launchers
|
6
|
-
## =========================================================================================================
|
7
|
-
|
8
|
-
def default
|
9
|
-
if directory.repository?
|
10
|
-
launch directory.project
|
11
|
-
else
|
12
|
-
launch
|
13
|
-
end
|
14
|
-
end
|
15
|
-
alias_method :dashboard, :default
|
16
|
-
|
17
|
-
def messages
|
18
|
-
launch 'messages'
|
19
|
-
end
|
20
|
-
alias_method :me, :messages
|
21
|
-
|
22
|
-
def tickets
|
23
|
-
launch directory.project, 'tickets'
|
24
|
-
end
|
25
|
-
alias_method :ti, :tickets
|
26
|
-
|
27
|
-
def new_ticket
|
28
|
-
launch directory.project, 'tickets', 'new'
|
29
|
-
end
|
30
|
-
alias_method :nti, :new_ticket
|
31
|
-
|
32
|
-
def milestones
|
33
|
-
launch directory.project, 'milestones'
|
34
|
-
end
|
35
|
-
alias_method :mi, :milestones
|
36
|
-
|
37
|
-
def time
|
38
|
-
launch directory.project, 'time'
|
39
|
-
end
|
40
|
-
alias_method :tm, :time
|
41
|
-
|
42
|
-
def wiki
|
43
|
-
launch directory.project, 'wiki'
|
44
|
-
end
|
45
|
-
alias_method :wi, :wiki
|
46
|
-
|
47
|
-
def browser
|
48
|
-
launch directory.project, directory.repository, 'tree', directory.working_branch
|
49
|
-
end
|
50
|
-
alias_method :br, :browser
|
51
|
-
|
52
|
-
def commits
|
53
|
-
launch directory.project, directory.repository, 'commits', directory.working_branch
|
54
|
-
end
|
55
|
-
alias_method :co, :commits
|
56
|
-
|
57
|
-
def deployments
|
58
|
-
launch directory.project, directory.repository, 'deployments'
|
59
|
-
end
|
60
|
-
alias_method :de, :deployments
|
61
|
-
|
62
|
-
def tasks
|
63
|
-
launch directory.project, directory.repository, 'tasks', directory.working_branch
|
64
|
-
end
|
65
|
-
alias_method :ta, :tasks
|
66
|
-
|
67
|
-
## =========================================================================================================
|
68
|
-
## Remote Branch Management
|
69
|
-
## =========================================================================================================
|
70
|
-
|
71
|
-
def mkbranch(branch_name, source_branch = 'master')
|
72
|
-
commands = []
|
73
|
-
commands << "git push origin #{source_branch}:refs/heads/#{branch_name}"
|
74
|
-
commands << "git fetch origin"
|
75
|
-
commands << "git branch --track #{branch_name} origin/#{branch_name}"
|
76
|
-
commands << "git checkout #{branch_name}"
|
77
|
-
execute_commands(commands)
|
78
|
-
end
|
79
|
-
|
80
|
-
def rmbranch(branch_name)
|
81
|
-
commands = []
|
82
|
-
commands << "git push origin :#{branch_name}"
|
83
|
-
commands << "git branch -d #{branch_name}"
|
84
|
-
execute_commands(commands)
|
85
|
-
end
|
86
|
-
|
87
|
-
## =========================================================================================================
|
88
|
-
## Commit Logger
|
89
|
-
## =========================================================================================================
|
90
|
-
|
91
|
-
def log(message)
|
92
|
-
current = directory.send(:git, :config, 'codebase.log').split("\\n")
|
93
|
-
current << message
|
94
|
-
directory.send(:git, :config, 'codebase.log', "\"#{current.join("\n")}\"")
|
95
|
-
end
|
96
|
-
|
97
|
-
def showlog
|
98
|
-
output = directory.send(:git, :config, 'codebase.log').split("\n").map{|line| " * #{line}\n"}
|
99
|
-
if output.empty?
|
100
|
-
$stderr.puts "There is nothing in the Codebase Log at the moment. Add something using 'cb log \"My Message Here\"'"
|
101
|
-
Process.exit(1)
|
102
|
-
else
|
103
|
-
puts output
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def clearlog
|
108
|
-
directory.send(:git, :config, '--unset', 'codebase.log')
|
109
|
-
puts "Codebase log cleared."
|
110
|
-
end
|
111
|
-
|
112
|
-
def commit(message = '')
|
113
|
-
output = directory.send(:git, :config, 'codebase.log').split("\n").map{|line| " * #{line}\n"}
|
114
|
-
if output.empty? || message.nil? || message == ''
|
115
|
-
$stderr.puts "You haven't added a message and/or added log entries. You may want to use a normal commit using 'git commit -m ...'"
|
116
|
-
Process.exit(1)
|
117
|
-
else
|
118
|
-
system("git commit -m '#{message}\n\n#{output}'")
|
119
|
-
clearlog
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
end
|