gitmine 0.1.4.pre.1 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4.pre.1
1
+ 0.1.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gitmine}
8
- s.version = "0.1.4.pre.1"
8
+ s.version = "0.1.5"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Philippe Creux"]
12
- s.date = %q{2010-11-16}
12
+ s.date = %q{2010-11-24}
13
13
  s.default_executable = %q{gitmine}
14
14
  s.description = %q{Git log with status of associated redmine tickets}
15
15
  s.email = %q{pcreux@gmail.com}
@@ -2,15 +2,31 @@ module Gitmine
2
2
  class CLI
3
3
  def self.run
4
4
  case ARGV[0]
5
- when nil
5
+ when "log"
6
6
  list
7
- when "branch"
7
+ when "branch", "br"
8
8
  branch
9
+ when "checkout", "co"
10
+ checkout
11
+ when "delete", "del"
12
+ delete
9
13
  else
10
14
  puts <<-EOS
11
15
  Usage:
12
- gitmine: show the 10 latest commits and their associated issue status
13
- gitmine branch [BRANCH_NAME]: create a new branch
16
+ gitmine branch BRANCH_NAME
17
+ Create a new branch, push to origin, add github links to gitmine ticket
18
+ Example: gitmine branch 1234-my-branch
19
+
20
+ gitmine checkout ISSUE_ID
21
+ Checkout remote/local branch starting with ISSUE_ID
22
+ Example: gitmine checkout 1234
23
+
24
+ gitmine delete ISSUE_ID
25
+ Delete remote branch starting with ISSUE_ID
26
+ Example: gitmine delete 1234
27
+
28
+ gitmine log
29
+ Displays latest 10 commits and the status of their associated Redmine tickets
14
30
  EOS
15
31
  end
16
32
  end
@@ -22,5 +38,13 @@ module Gitmine
22
38
  def self.branch
23
39
  Gitmine.branch(ARGV[1])
24
40
  end
41
+
42
+ def self.checkout
43
+ Gitmine.checkout(ARGV[1])
44
+ end
45
+
46
+ def self.delete
47
+ Gitmine.delete(ARGV[1])
48
+ end
25
49
  end
26
50
  end
@@ -20,6 +20,7 @@ module Gitmine
20
20
  end
21
21
 
22
22
 
23
+ # TODO specs
23
24
  def self.branch(branch_name)
24
25
  issue_id = branch_name[/^\d+/]
25
26
  original_branch = File.read('./.git/HEAD').match(/^ref: refs\/heads\/(.+)/)[1]
@@ -43,12 +44,62 @@ module Gitmine
43
44
  note << %{ - "Compare on Github":https://github.com/#{config['github']}/compare/#{original_branch}...#{branch_name}}
44
45
  end
45
46
 
46
- Issue.find(issue_id).add_note(note)
47
+ puts 'Done!' if Issue.find(issue_id).add_note(note)
48
+ end
49
+
50
+ # TODO specs
51
+ def self.checkout(issue_id)
52
+ if local_branch = local_branches.select { |branch| branch[/^#{issue_id}-/] }.first
53
+ run_cmd("git checkout #{local_branch}")
54
+ return
55
+ end
56
+
57
+ if remote_branch = remote_branches.select { |branch| branch[/^#{issue_id}-/] }.first
58
+ run_cmd("git checkout -b #{remote_branch} origin/#{remote_branch}")
59
+ return
60
+ end
61
+
62
+ raise "Can't find branch starting with #{issue_id}"
63
+ end
64
+
65
+ # TODO specs
66
+ def self.delete(issue_id)
67
+ if remote_branch = remote_branches.select { |branch| branch[/^#{issue_id}-/] }.first
68
+ run_cmd("git push origin :#{remote_branch}")
69
+ else
70
+ raise "Can't find branch starting with #{issue_id}"
71
+ end
47
72
  end
48
73
 
49
74
  def self.run_cmd(cmd)
50
75
  puts cmd
51
76
  exit! unless system(cmd)
52
77
  end
78
+
79
+ # TODO specs
80
+ def self.local_branches
81
+ branches = []
82
+ `git branch`.each_line do |line|
83
+ if match = line[/\d+.*$/]
84
+ branches << match
85
+ end
86
+ end
87
+
88
+ branches
89
+ end
90
+
91
+ # TODO specs
92
+ def self.remote_branches
93
+ run_cmd("git fetch")
94
+
95
+ branches = []
96
+ `git branch -r`.each_line do |line|
97
+ if match = line.match(/origin\/(\d+.*)/)
98
+ branches << match[1]
99
+ end
100
+ end
101
+
102
+ branches
103
+ end
53
104
  end
54
105
  end
@@ -44,9 +44,13 @@ module Gitmine
44
44
 
45
45
  # Add a note to the Issue
46
46
  def add_note(note)
47
- p self.class.put(url(self.id),
48
- :query => {:notes => note},
49
- :body => "") # nginx reject requests without body
47
+ response = self.class.put(url(self.id), :query => {:notes => note}, :body => "") # nginx reject requests without body
48
+
49
+ if response.code == 200
50
+ return true
51
+ else
52
+ raise response.response
53
+ end
50
54
  end
51
55
 
52
56
  include HTTParty
@@ -51,9 +51,10 @@ describe Gitmine::Issue do
51
51
  end
52
52
 
53
53
  describe "#add_note" do
54
+ let(:httparty_response) { mock(:http_party_response, :code => 200) }
54
55
  it "should PUT a note" do
55
56
  issue.stub!(:id) { 1 }
56
- issue.class.should_receive(:put).with('/1.xml', :query => {:notes => "Hello"}, :body => "")
57
+ issue.class.should_receive(:put).with('/1.xml', :query => {:notes => "Hello"}, :body => "") { httparty_response }
57
58
  issue.add_note("Hello")
58
59
  end
59
60
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitmine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1923831963
5
- prerelease: true
4
+ hash: 17
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- - pre
11
- - 1
12
- version: 0.1.4.pre.1
9
+ - 5
10
+ version: 0.1.5
13
11
  platform: ruby
14
12
  authors:
15
13
  - Philippe Creux
@@ -17,7 +15,7 @@ autorequire:
17
15
  bindir: bin
18
16
  cert_chain: []
19
17
 
20
- date: 2010-11-16 00:00:00 -08:00
18
+ date: 2010-11-24 00:00:00 -08:00
21
19
  default_executable: gitmine
22
20
  dependencies:
23
21
  - !ruby/object:Gem::Dependency
@@ -118,14 +116,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
116
  required_rubygems_version: !ruby/object:Gem::Requirement
119
117
  none: false
120
118
  requirements:
121
- - - ">"
119
+ - - ">="
122
120
  - !ruby/object:Gem::Version
123
- hash: 25
121
+ hash: 3
124
122
  segments:
125
- - 1
126
- - 3
127
- - 1
128
- version: 1.3.1
123
+ - 0
124
+ version: "0"
129
125
  requirements: []
130
126
 
131
127
  rubyforge_project: