codebase 3.0.8

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/bin/cb ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + "/../lib/codebase"
3
+ Codebase.run(ARGV)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + "/../lib/codebase"
3
+ Codebase.run(ARGV)
@@ -0,0 +1,29 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'codebase_helpers/command_base'
4
+ require 'codebase_helpers/command'
5
+ require 'codebase_helpers/directory'
6
+
7
+ module Codebase
8
+
9
+ class Error < RuntimeError; end
10
+
11
+ extend self
12
+
13
+ def run(args)
14
+ begin
15
+ repository = Directory.new
16
+ method = args.shift || 'default'
17
+ command = Codebase::Command.new(repository, args)
18
+ if command.respond_to?(method)
19
+ command.send(method, *args)
20
+ else
21
+ $stderr.puts "Command Not Found - please check http://help.codebasehq.com for documentation."
22
+ end
23
+ rescue Codebase::Error => e
24
+ $stderr.puts e.message
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -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
@@ -0,0 +1,124 @@
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
@@ -0,0 +1,39 @@
1
+ module Codebase
2
+ class CommandBase
3
+
4
+ attr_reader :directory, :args
5
+
6
+ def initialize(directory, args)
7
+ @directory, @args = directory, args
8
+ end
9
+
10
+ private
11
+
12
+ def launch(*args)
13
+ begin
14
+ gem 'launchy'
15
+ require 'launchy'
16
+ url = "http://#{directory.domain}/" + args.join('/').gsub(/\?\z/, "")
17
+ Launchy::Browser.new.visit(url)
18
+ rescue Gem::LoadError
19
+ raise Codebase::Error, "Sorry, you need to install launchy to do that - give 'gem install launchy' a go."
20
+ end
21
+ end
22
+
23
+ def execute_commands(array)
24
+ for command in array
25
+ puts "\e[44;33m" + command + "\e[0m"
26
+ exit_code = 0
27
+ IO.popen(command) do |f|
28
+ output = f.read
29
+ exit_code = Process.waitpid2(f.pid)[1]
30
+ end
31
+ if exit_code != 0
32
+ $stderr.puts "An error occured running: #{command}"
33
+ Process.exit(1)
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,73 @@
1
+ module Codebase
2
+
3
+ ## A directory represents the directory the user is currently within.
4
+
5
+ class Directory
6
+
7
+ attr_reader :permalink, :account
8
+
9
+ def initialize
10
+ get_properties
11
+ end
12
+
13
+ def repository?
14
+ working_branch
15
+ end
16
+
17
+ def working_branch
18
+ @working_branch ||= git(:status).split("\n").first.split(" ").last rescue nil
19
+ end
20
+
21
+ def domain
22
+ if @account
23
+ "#{@account}.codebasehq.com"
24
+ else
25
+ git(:config, 'codebase.domain')
26
+ end
27
+ end
28
+
29
+ def project
30
+ raise Codebase::Error, "This is not a valid Codebase repository" unless repository?
31
+ @project
32
+ end
33
+
34
+ def repository
35
+ raise Codebase::Error, "This is not a valid Codebase repository" unless repository?
36
+ @repository
37
+ end
38
+
39
+ def path
40
+ File.dirname(__FILE__)
41
+ end
42
+
43
+ private
44
+
45
+ def codebase_remote_name
46
+ configured = git(:config, 'codebase.remote')
47
+ if configured.empty?
48
+ 'origin'
49
+ else
50
+ configured
51
+ end
52
+ end
53
+
54
+ ## Returns the project an repository names base on the git remote URL
55
+ def get_properties
56
+ return unless repository?
57
+ remote_url = git(:config, "remote.#{codebase_remote_name}.url")
58
+ if m = remote_url.match(/git\@(gitbase|codebasehq)\.com:(.*)\/(.*)\/(.*)\.git/)
59
+ @account = m[2]
60
+ @project = m[3]
61
+ @repository = m[4]
62
+ else
63
+ raise Codebase::Error, "This is not a valid Codebase repository - #{remote_url} as '#{codebase_remote_name}'"
64
+ end
65
+ end
66
+
67
+ def git(cmd, *args)
68
+ `git #{cmd} #{args.join(' ')} 2> /dev/null`.strip.chomp
69
+ end
70
+
71
+
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codebase
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.8
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cooke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-26 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: adam@atechmedia.com
18
+ executables:
19
+ - codebase
20
+ - cb
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - bin/cb
27
+ - bin/codebase
28
+ - lib/codebase/recipes.rb
29
+ - lib/codebase.rb
30
+ - lib/codebase_helpers/command.rb
31
+ - lib/codebase_helpers/command_base.rb
32
+ - lib/codebase_helpers/directory.rb
33
+ has_rdoc: true
34
+ homepage: http://www.atechmedia.com
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.3.5
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: The codebase gem to make using codebase easier (duh?)
61
+ test_files: []
62
+