gitmine 0.1.1 → 0.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.
- data/README.rdoc +8 -4
- data/VERSION +1 -1
- data/gitmine.gemspec +4 -2
- data/lib/gitmine.rb +50 -9
- data/spec/commit_spec.rb +36 -0
- data/spec/gitmine_spec.rb +21 -9
- data/spec/spec_helper.rb +1 -0
- metadata +5 -3
data/README.rdoc
CHANGED
@@ -7,13 +7,17 @@ Gitmine displays the last 10 commits of your repo and their associated redmine t
|
|
7
7
|
|
8
8
|
== Setup
|
9
9
|
Put the config file '.gitmine.yml' at the root of your project. Here is a sample file:
|
10
|
-
|
11
|
-
host: 'https://redmine.yourcompany.com
|
12
|
-
|
13
|
-
|
10
|
+
|
11
|
+
host: 'https://redmine.yourcompany.com
|
12
|
+
# Api key is required for private projects only.
|
13
|
+
api_key: 'your_api_key'
|
14
14
|
|
15
15
|
Then run gitmine at the root of your project.
|
16
16
|
|
17
|
+
== Note on Issues
|
18
|
+
|
19
|
+
* Issues are managed by redmine on http://redmine-gitmine.heroku.com/projects/gitmine
|
20
|
+
* Thanks for reporting issues on http://redmine-gitmine.heroku.com/projects/gitmine/issues/new
|
17
21
|
|
18
22
|
== Note on Patches/Pull Requests
|
19
23
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/gitmine.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gitmine}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
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-07-
|
12
|
+
s.date = %q{2010-07-27}
|
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}
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"gitmine.gemspec",
|
33
33
|
"lib/gitmine.rb",
|
34
34
|
"spec/commit_msg_to_issue_id_spec.rb",
|
35
|
+
"spec/commit_spec.rb",
|
35
36
|
"spec/config.yml",
|
36
37
|
"spec/gitmine_spec.rb",
|
37
38
|
"spec/issue_spec.rb",
|
@@ -44,6 +45,7 @@ Gem::Specification.new do |s|
|
|
44
45
|
s.summary = %q{Git log with status of associated redmine tickets}
|
45
46
|
s.test_files = [
|
46
47
|
"spec/commit_msg_to_issue_id_spec.rb",
|
48
|
+
"spec/commit_spec.rb",
|
47
49
|
"spec/gitmine_spec.rb",
|
48
50
|
"spec/issue_spec.rb",
|
49
51
|
"spec/spec_helper.rb"
|
data/lib/gitmine.rb
CHANGED
@@ -5,25 +5,63 @@ require 'yaml'
|
|
5
5
|
require 'HTTParty'
|
6
6
|
|
7
7
|
class Gitmine
|
8
|
+
# CLI interface
|
8
9
|
def self.run
|
9
10
|
gm = Gitmine.new
|
10
11
|
gm.commits.each do |commit|
|
11
|
-
|
12
|
-
status = issue ? issue.status : 'N/A'
|
12
|
+
status = commit.issue ? commit.issue.status : 'N/A'
|
13
13
|
puts "#{commit.id[0..6]} #{status.ljust(12)} #{commit.committer.name.ljust(15)} #{commit.message[0..50].gsub("\n", '')}"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
def initialize
|
18
18
|
@repo = Grit::Repo.new(ENV['PWD'])
|
19
|
+
@branch = File.read('./.git/HEAD').match(/^ref: refs\/heads\/(.+)/)[1]
|
19
20
|
end
|
20
21
|
|
21
22
|
def commits
|
22
|
-
@repo.commits
|
23
|
+
@repo.commits(@branch).map do |c|
|
24
|
+
Commit.new(c)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
class Commit
|
31
|
+
attr_reader :grit_commit
|
32
|
+
|
33
|
+
# Initialize a new Commit objects that delegates methods to the Grit::Commit object passed in
|
34
|
+
def initialize(grit_commit)
|
35
|
+
@grit_commit = grit_commit
|
36
|
+
end
|
37
|
+
|
38
|
+
# Issue associated with this commit
|
39
|
+
# Return nil if teir is no associated issue
|
40
|
+
def issue
|
41
|
+
@issue ||= Issue.get_for_commit(message)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Delegate #id to Grit::Commit
|
45
|
+
def id
|
46
|
+
@grit_commit.id
|
23
47
|
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
# Delegate methods to Grit::Commit
|
51
|
+
def method_missing(m, *args, &block)
|
52
|
+
return @grit_commit.send(m, args, block) if @grit_commit.respond_to? m
|
53
|
+
super
|
54
|
+
end
|
24
55
|
end
|
25
56
|
|
26
57
|
module CommitMsgToIssueId
|
58
|
+
# Extract the issue_id from a commit message.
|
59
|
+
# Examples:
|
60
|
+
# CommitMsgToIssueId.parse("Message for Issue #123.")
|
61
|
+
# => 123
|
62
|
+
# CommitMsgToIssueId.parse("#123.")
|
63
|
+
# => nil
|
64
|
+
#
|
27
65
|
def self.parse(msg)
|
28
66
|
match = msg.match(/Issue #(\d+)/)
|
29
67
|
match ? match[1] : nil
|
@@ -31,23 +69,29 @@ module CommitMsgToIssueId
|
|
31
69
|
end
|
32
70
|
|
33
71
|
class Issue
|
34
|
-
|
72
|
+
CONFIG_FILE = './.gitmine.yml'
|
73
|
+
|
74
|
+
attr_reader :id, :subject, :status
|
35
75
|
|
76
|
+
# Parse the commit_message and get the associated issue if any.
|
36
77
|
def self.get_for_commit(commit_message)
|
37
78
|
issue_id = CommitMsgToIssueId.parse(commit_message)
|
38
79
|
issue_id ? Issue.get(issue_id) : nil
|
39
80
|
end
|
40
81
|
|
82
|
+
# Get the issue from redmine
|
41
83
|
def self.get(issue_id)
|
42
84
|
Issue.new.tap { |issue|
|
43
85
|
issue.build_via_issue_id(issue_id)
|
44
86
|
}
|
45
87
|
end
|
46
88
|
|
89
|
+
# Config from .gitmine.yml
|
47
90
|
def config
|
48
91
|
@config ||= YAML.load_file(CONFIG_FILE)
|
49
92
|
end
|
50
93
|
|
94
|
+
# Get attributes from redmine and set them all
|
51
95
|
def build_via_issue_id(issue_id)
|
52
96
|
@id = issue_id
|
53
97
|
data = get(issue_id).parsed_response['issue']
|
@@ -57,16 +101,13 @@ class Issue
|
|
57
101
|
|
58
102
|
protected
|
59
103
|
|
104
|
+
# Url to redmine/issues
|
60
105
|
def url(id)
|
61
106
|
"#{config['host']}/issues/#{id}.xml?key=#{config['api_key']}"
|
62
107
|
end
|
63
108
|
|
109
|
+
# http_get the issue using HTTParty
|
64
110
|
def get(issue_id)
|
65
111
|
HTTParty.get(url(issue_id))
|
66
112
|
end
|
67
|
-
|
68
|
-
CONFIG_FILE = './.gitmine.yml'
|
69
|
-
|
70
|
-
def issues_for_commit(commit_id)
|
71
|
-
end
|
72
113
|
end
|
data/spec/commit_spec.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Commit do
|
4
|
+
let(:grit_commit) { Grit::Commit.create(nil, {:message => "Commit message"}) }
|
5
|
+
let(:commit) { Commit.new(grit_commit) }
|
6
|
+
let(:issue) { Issue.new }
|
7
|
+
|
8
|
+
describe "#new" do
|
9
|
+
it "should take a grit_commit object and store it" do
|
10
|
+
commit.grit_commit.should == grit_commit
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should delegate methods to the grit_commit object" do
|
15
|
+
commit.message.should == grit_commit.message
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should delegate #id to the grit_commit object" do
|
19
|
+
commit.id.should == grit_commit.id
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should respond_to :issue" do
|
23
|
+
commit.should respond_to :issue
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return issue via #Issue.get_for_commit" do
|
27
|
+
Issue.should_receive(:get_for_commit).with("Commit message") { issue }
|
28
|
+
commit.issue.should == issue
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should memoize issue" do
|
32
|
+
Issue.should_receive(:get_for_commit).with("Commit message") { issue }.once
|
33
|
+
commit.issue.should == issue
|
34
|
+
commit.issue.should == issue
|
35
|
+
end
|
36
|
+
end
|
data/spec/gitmine_spec.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gitmine do
|
4
|
+
before do
|
5
|
+
File.stub!(:read) { "ref: refs/heads/wip" }
|
6
|
+
end
|
7
|
+
|
4
8
|
let(:gitmine) { Gitmine.new }
|
5
9
|
|
6
10
|
let(:commit_1) do
|
@@ -11,25 +15,33 @@ describe Gitmine do
|
|
11
15
|
)
|
12
16
|
end
|
13
17
|
|
18
|
+
let(:repo) do
|
19
|
+
mock(Grit::Repo, :commits => [commit_1])
|
20
|
+
end
|
21
|
+
|
14
22
|
before do
|
15
|
-
Grit::Repo.stub!(:new) {
|
16
|
-
mock(Grit::Repo, :commits => [commit_1])
|
17
|
-
}
|
23
|
+
Grit::Repo.stub!(:new) { repo }
|
18
24
|
end
|
19
25
|
|
20
26
|
describe "#commits" do
|
21
|
-
it "should return
|
22
|
-
gitmine.commits.should
|
27
|
+
it "should return Gitmine commits" do
|
28
|
+
gitmine.commits.first.should be_a Commit
|
29
|
+
end
|
30
|
+
it "should return commits for the current branch" do
|
31
|
+
repo.should_receive(:commits).with('wip')
|
32
|
+
gitmine.commits
|
23
33
|
end
|
24
34
|
end
|
25
35
|
|
26
36
|
describe "#initialize" do
|
27
|
-
|
28
|
-
|
37
|
+
let(:grit_repo) { mock(:checkout => true)}
|
38
|
+
before do
|
39
|
+
Grit::Repo.stub!(:new) { grit_repo }
|
29
40
|
end
|
30
41
|
|
31
|
-
|
32
|
-
|
42
|
+
it "should check out to the current branch" do
|
43
|
+
Grit::Repo.should_receive(:new).with(ENV['PWD']) { grit_repo }
|
44
|
+
Gitmine.new
|
33
45
|
end
|
34
46
|
end
|
35
47
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Philippe Creux
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-27 00:00:00 -07:00
|
18
18
|
default_executable: gitmine
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- gitmine.gemspec
|
79
79
|
- lib/gitmine.rb
|
80
80
|
- spec/commit_msg_to_issue_id_spec.rb
|
81
|
+
- spec/commit_spec.rb
|
81
82
|
- spec/config.yml
|
82
83
|
- spec/gitmine_spec.rb
|
83
84
|
- spec/issue_spec.rb
|
@@ -114,6 +115,7 @@ specification_version: 3
|
|
114
115
|
summary: Git log with status of associated redmine tickets
|
115
116
|
test_files:
|
116
117
|
- spec/commit_msg_to_issue_id_spec.rb
|
118
|
+
- spec/commit_spec.rb
|
117
119
|
- spec/gitmine_spec.rb
|
118
120
|
- spec/issue_spec.rb
|
119
121
|
- spec/spec_helper.rb
|