guitsaru-lighthouse_branch 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ lighthouse_account.yml
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Matt Pruitt
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,36 @@
1
+ = lighthouse_branch
2
+
3
+ = Setup
4
+
5
+ Add your Lighthouse project settings to your repo's git config.
6
+
7
+ git config lighthouse.account [lighthouse account subdomain]
8
+ git config lighthouse.token [lighthouse API token]
9
+ git config lighthouse.project [lighthouse project id]
10
+
11
+ = Usage
12
+
13
+ lh-branch [ticket_id]: Creates a branch based on the ticket name.
14
+ lh-branch 1 #=> git checkout -b 1-ticket-title
15
+
16
+ lh-branch push [ticket_id] [remote name]: Pushes the ticket's branch to the named remote.
17
+ lh-branch 1 origin #=> git push origin 1-ticket-title
18
+
19
+ lh-branch pull [ticket_id] [remote name]: Pulls the ticket's branch from the named remote.
20
+ lh-branch 1 origin #=> git pull origin 1-ticket-title
21
+
22
+ lh-branch merge [ticket_id]: Merges the ticket's branch with the current branch.
23
+ lh-branch merge 1 #=> git merge 1-ticket-title
24
+
25
+ lh-branch checkout [ticket_id]: Checks out the ticket's branch, making it the current branch.
26
+ lh-branch checkout 1 #=> git checkout 1-ticket-title
27
+
28
+ lh-branch delete [ticket_id]: Deletes the ticket's branch.
29
+ lh-branch delete 1 #=> git branch -d 1-ticket-title
30
+
31
+ lh-branch resolve 1 [message]: Creates a commit that will mark the ticket resolved.
32
+ lh-branch resolve 1 "Fixed the bug." #=> git commit -a -m "Fixed the bug\n\n[#1 state:resolved]"
33
+
34
+ == Copyright
35
+
36
+ Copyright (c) 2009 Matt Pruitt. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "lighthouse_branch"
8
+ gem.summary = %Q{Easily manage branches based off lighthouse tickets.}
9
+ gem.email = "guitsaru@gmail.com"
10
+ gem.homepage = "http://github.com/guitsaru/lighthouse_branch"
11
+ gem.authors = ["Matt Pruitt"]
12
+ gem.rubyforge_project = "lighthouse_branch"
13
+ gem.add_dependency('grit', '>= 1.1.1')
14
+ gem.add_dependency('Caged-lighthouse-api', '>= 1.0.0')
15
+ end
16
+
17
+ Jeweler::RubyforgeTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/*_test.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/*_test.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ if File.exist?('VERSION.yml')
48
+ config = YAML.load(File.read('VERSION.yml'))
49
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
50
+ else
51
+ version = ""
52
+ end
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "lighthouse_branch #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
59
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/bin/lh-branch ADDED
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'lighthouse_branch')
5
+ require 'grit'
6
+
7
+ def get_command(args)
8
+ case args[0]
9
+ when nil
10
+ return nil
11
+ when /push/i
12
+ args.shift
13
+ return 'push'
14
+ when /pull/i
15
+ args.shift
16
+ return 'pull'
17
+ when /merge/i
18
+ args.shift
19
+ return 'merge'
20
+ when /checkout/i
21
+ args.shift
22
+ return 'checkout'
23
+ when /delete/i
24
+ args.shift
25
+ return 'delete'
26
+ when /resolve/i
27
+ args.shift
28
+ return 'resolve'
29
+ else return 'branch'
30
+ end
31
+ end
32
+
33
+ def get_lighthouse_branch
34
+ repo = Grit::Repo.new(Dir.pwd)
35
+
36
+ lighthouse_account = repo.config["lighthouse.account"]
37
+ lighthouse_token = repo.config["lighthouse.token"]
38
+ lighthouse_project = repo.config["lighthouse.project"]
39
+
40
+ if lighthouse_account.nil? || lighthouse_token.nil? || lighthouse_project.nil?
41
+ puts "You must add your lighthouse account info to git config:"
42
+ puts "git config lighthouse.account [lighthouse account subdomain]"
43
+ puts "git config lighthouse.token [lighthouse API token]"
44
+ puts "git config lighthouse.project [lighthouse project id]"
45
+ exit
46
+ end
47
+
48
+ return LighthouseBranch.new(lighthouse_account, lighthouse_token, lighthouse_project)
49
+ end
50
+
51
+ args = ARGV
52
+
53
+ command = get_command(args)
54
+ ticket_id = args.shift.to_i
55
+ command = nil if ticket_id == 0
56
+
57
+ lighthouse_branch = get_lighthouse_branch
58
+
59
+ case command
60
+ when nil
61
+ puts "Usage:"
62
+ puts "lh-branch [ticket_id]"
63
+ puts "lh-branch push [ticket_id] [remote name]"
64
+ puts "lh-branch pull [ticket_id] [remote name]"
65
+ puts "lh-branch merge [ticket_id]"
66
+ puts "lh-branch checkout [ticket_id]"
67
+ puts "lh-branch delete [ticket_id]"
68
+ puts "lh-branch resolve 1 [message]"
69
+ when 'branch'
70
+ if args.size != 0
71
+ puts "Usage: lh-branch [ticket_id]"
72
+ exit
73
+ end
74
+ system("git checkout -b #{lighthouse_branch.branch_name(ticket_id)}")
75
+ when 'delete'
76
+ if args.size != 0
77
+ puts "Usage: lh-branch delete [ticket_id]"
78
+ exit
79
+ end
80
+ system("git branch -d #{lighthouse_branch.branch_name(ticket_id)}")
81
+ when 'push'
82
+ if args.size != 1
83
+ puts "Usage: lh-branch push [ticket_id] [remote name]"
84
+ exit
85
+ end
86
+ system("git push #{args.shift} #{lighthouse_branch.branch_name(ticket_id)}")
87
+ when 'pull'
88
+ if args.size != 1
89
+ puts "Usage: lh-branch pull [ticket_id] [remote name]"
90
+ exit
91
+ end
92
+ system("git pull #{args.shift} #{lighthouse_branch.branch_name(ticket_id)}")
93
+ when 'checkout'
94
+ if args.size != 0
95
+ puts "Usage: lh-branch checkout [ticket_id]"
96
+ exit
97
+ end
98
+ system("git checkout #{lighthouse_branch.branch_name(ticket_id)}")
99
+ when 'merge'
100
+ if args.size != 0
101
+ puts "Usage: lh-branch merge [ticket_id]"
102
+ exit
103
+ end
104
+ system("git merge #{lighthouse_branch.branch_name(ticket_id)}")
105
+ when 'resolve'
106
+ if args.size != 1
107
+ puts "Usage: lh-branch resolve 1 [message]"
108
+ exit
109
+ end
110
+ system("git commit -a -m \"#{args.shift}\n\n[##{ticket_id} state:resolved]\"")
111
+ end
@@ -0,0 +1,17 @@
1
+ require 'lighthouse-api'
2
+
3
+ class LighthouseBranch
4
+ def initialize(account, token, project_id)
5
+ Lighthouse.account = account
6
+ Lighthouse.token = token
7
+ @project = Lighthouse::Project.find(project_id)
8
+ end
9
+
10
+ def ticket(id)
11
+ Lighthouse::Ticket.find(id, :params => { :project_id => @project.id })
12
+ end
13
+
14
+ def branch_name(id)
15
+ "#{id}-#{ticket(id).title.gsub(/[^\w ]/, '').gsub(/[^a-z0-9]+/i, '-').downcase}"
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'lighthouse_branch'
8
+
9
+ LIGHTHOUSE_ACCOUNT = YAML::load(File.open(File.join(File.dirname(__FILE__), 'lighthouse_account.yml')))
10
+
11
+ class Test::Unit::TestCase
12
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class TestLighthouseBranch < Test::Unit::TestCase
4
+ context "Tests" do
5
+ setup do
6
+ @lighthouse_branch = LighthouseBranch.new(
7
+ LIGHTHOUSE_ACCOUNT["account"],
8
+ LIGHTHOUSE_ACCOUNT["token"],
9
+ LIGHTHOUSE_ACCOUNT["project"])
10
+
11
+ @ticket_id = LIGHTHOUSE_ACCOUNT["ticket"]
12
+ end
13
+
14
+ should "initialize" do
15
+ assert_not_nil(@lighthouse_branch)
16
+ end
17
+
18
+ should "return a ticket" do
19
+ assert_not_nil(@lighthouse_branch.ticket(@ticket_id))
20
+ assert_equal(Lighthouse::Ticket, @lighthouse_branch.ticket(@ticket_id).class)
21
+ end
22
+
23
+ should "give a branch name for the ticket" do
24
+ assert_match(/#{LIGHTHOUSE_ACCOUNT["ticket"]}-[\w-]*/, @lighthouse_branch.branch_name(@ticket_id))
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guitsaru-lighthouse_branch
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Pruitt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-20 00:00:00 -07:00
13
+ default_executable: lh-branch
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: grit
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: Caged-lighthouse-api
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ version:
35
+ description:
36
+ email: guitsaru@gmail.com
37
+ executables:
38
+ - lh-branch
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - bin/lh-branch
52
+ - lib/lighthouse_branch.rb
53
+ - test/test_helper.rb
54
+ - test/test_lighthouse_branch.rb
55
+ has_rdoc: false
56
+ homepage: http://github.com/guitsaru/lighthouse_branch
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project: lighthouse_branch
77
+ rubygems_version: 1.2.0
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Easily manage branches based off lighthouse tickets.
81
+ test_files:
82
+ - test/test_helper.rb
83
+ - test/test_lighthouse_branch.rb