gitmine 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ gem 'rspec', '2.0.0.beta.17'
2
+ gem 'httparty'
3
+ gem 'grit', '2.0.0'
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Philippe Creux
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.
@@ -0,0 +1,30 @@
1
+ = gitmine
2
+
3
+ Gitmine displays the last 10 commits of your repo and their associated redmine ticket status.
4
+
5
+ == Install
6
+ gem install gitmine
7
+
8
+ == Setup
9
+ Put the config file '.gitmine.yml' at the root of your project. Here is a sample file:
10
+ <pre>
11
+ host: 'https://redmine.yourcompany.com
12
+ api_key: 'your_api_key'
13
+ </pre>
14
+
15
+ Then run gitmine at the root of your project.
16
+
17
+
18
+ == Note on Patches/Pull Requests
19
+
20
+ * Fork the project.
21
+ * Make your feature addition or bug fix.
22
+ * Add tests for it. This is important so I don't break it in a
23
+ future version unintentionally.
24
+ * Commit, do not mess with rakefile, version, or history.
25
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
26
+ * Send me a pull request. Bonus points for topic branches.
27
+
28
+ == Copyright
29
+
30
+ Copyright (c) 2010 Philippe Creux. See LICENSE for details.
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "gitmine"
8
+ gem.summary = "Git log with status of associated redmine tickets"
9
+ gem.description = "Git log with status of associated redmine tickets"
10
+ gem.email = "pcreux@gmail.com"
11
+ gem.homepage = "http://github.com/pcreux/gitmine"
12
+ gem.authors = ["Philippe Creux"]
13
+ gem.default_executable = "gitmine"
14
+ gem.executables = ["gitmine"]
15
+ gem.add_dependency "httparty"
16
+ gem.add_dependency "grit"
17
+ gem.add_development_dependency "rspec", ">= 1.2.9"
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+ require 'spec/rake/spectask'
26
+ Spec::Rake::SpecTask.new(:spec) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.spec_files = FileList['spec/**/*_spec.rb']
29
+ end
30
+
31
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
32
+ spec.libs << 'lib' << 'spec'
33
+ spec.pattern = 'spec/**/*_spec.rb'
34
+ spec.rcov = true
35
+ end
36
+
37
+ task :spec => :check_dependencies
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "gitmine #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require "bundler"
3
+ Bundler.load
4
+
5
+ require 'grit'
6
+ require 'yaml'
7
+ require 'HTTParty'
8
+
9
+ require File.dirname(__FILE__) + '/../lib/gitmine'
10
+
11
+ Gitmine.run
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{gitmine}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Philippe Creux"]
12
+ s.date = %q{2010-07-26}
13
+ s.default_executable = %q{gitmine}
14
+ s.description = %q{Git log with status of associated redmine tickets}
15
+ s.email = %q{pcreux@gmail.com}
16
+ s.executables = ["gitmine"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "Gemfile",
25
+ "LICENSE",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "autotest/discover.rb",
30
+ "bin/gitmine",
31
+ "gitmine.gemspec",
32
+ "lib/gitmine.rb",
33
+ "spec/commit_msg_to_issue_id_spec.rb",
34
+ "spec/config.yml",
35
+ "spec/gitmine_spec.rb",
36
+ "spec/issue_spec.rb",
37
+ "spec/spec_helper.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/pcreux/gitmine}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.6}
43
+ s.summary = %q{Git log with status of associated redmine tickets}
44
+ s.test_files = [
45
+ "spec/commit_msg_to_issue_id_spec.rb",
46
+ "spec/gitmine_spec.rb",
47
+ "spec/issue_spec.rb",
48
+ "spec/spec_helper.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
57
+ s.add_runtime_dependency(%q<grit>, [">= 0"])
58
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
59
+ else
60
+ s.add_dependency(%q<httparty>, [">= 0"])
61
+ s.add_dependency(%q<grit>, [">= 0"])
62
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<httparty>, [">= 0"])
66
+ s.add_dependency(%q<grit>, [">= 0"])
67
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
68
+ end
69
+ end
70
+
@@ -0,0 +1,71 @@
1
+ HOST = 'https://redmine.versapay.com'
2
+ PROJECT = 'eft'
3
+ USERNAME = 'philippe.creux'
4
+ PASSWORD = 'temporary_stuff'
5
+
6
+ class Gitmine
7
+ def self.run
8
+ gm = Gitmine.new
9
+ gm.commits.each do |commit|
10
+ issue = Issue.get_for_commit(commit.message)
11
+ status = issue ? issue.status : 'N/A'
12
+ puts "#{commit.id[0..6]} #{status.ljust(12)} #{commit.committer.name.ljust(15)} #{commit.message[0..50].gsub("\n", '')}"
13
+ end
14
+ end
15
+
16
+ def initialize
17
+ @repo = Grit::Repo.new(ENV['PWD'])
18
+ end
19
+
20
+ def commits
21
+ @repo.commits
22
+ end
23
+ end
24
+
25
+ module CommitMsgToIssueId
26
+ def self.parse(msg)
27
+ match = msg.match(/Issue #(\d+)/)
28
+ match ? match[1] : nil
29
+ end
30
+ end
31
+
32
+ class Issue
33
+ attr_accessor :id, :subject, :status
34
+
35
+ def self.get_for_commit(commit_message)
36
+ issue_id = CommitMsgToIssueId.parse(commit_message)
37
+ issue_id ? Issue.get(issue_id) : nil
38
+ end
39
+
40
+ def self.get(issue_id)
41
+ Issue.new.tap { |issue|
42
+ issue.build_via_issue_id(issue_id)
43
+ }
44
+ end
45
+
46
+ def config
47
+ @config ||= YAML.load_file(CONFIG_FILE)
48
+ end
49
+
50
+ def build_via_issue_id(issue_id)
51
+ @id = issue_id
52
+ data = get(issue_id).parsed_response['issue']
53
+ @subject = data['subject']
54
+ @status = data['status']['name']
55
+ end
56
+
57
+ protected
58
+
59
+ def url(id)
60
+ "#{config['host']}/issues/#{id}.xml?key=#{config['api_key']}"
61
+ end
62
+
63
+ def get(issue_id)
64
+ HTTParty.get(url(issue_id))
65
+ end
66
+
67
+ CONFIG_FILE = './.gitmine.yml'
68
+
69
+ def issues_for_commit(commit_id)
70
+ end
71
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe "CommitMsgToIssueId" do
4
+ describe "#parse" do
5
+ [
6
+ ['Commit message Issue #123.', '123'],
7
+ ['Commit message #123.', nil],
8
+ ['Add method #yey Commit message Issue #123.', '123']
9
+ ].each do |msg, id|
10
+ it "should return #{id} for '#{msg}'" do
11
+ CommitMsgToIssueId.parse(msg).should == id
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ host: 'http://localhost:3000'
2
+ project: 'project_name'
3
+ api_key: 'api_key'
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitmine do
4
+ let(:gitmine) { Gitmine.new }
5
+
6
+ let(:commit_1) do
7
+ mock(
8
+ :message => "Commit 1 #1234",
9
+ :committer => "Sam",
10
+ :committed_date => Time.now
11
+ )
12
+ end
13
+
14
+ before do
15
+ Grit::Repo.stub!(:new) {
16
+ mock(Grit::Repo, :commits => [commit_1])
17
+ }
18
+ end
19
+
20
+ describe "#commits" do
21
+ it "should return the last 10 commit messages" do
22
+ gitmine.commits.should == [commit_1]
23
+ end
24
+ end
25
+
26
+ describe "#initialize" do
27
+ context "when not a git repo" do
28
+ it "should raise an exception"
29
+ end
30
+
31
+ context "when git repo" do
32
+ it "should not raise any exception"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Issue do
4
+ let(:issue) { Issue.new }
5
+ [:id, :subject, :status].each do |a|
6
+ it "should have an #{a}" do
7
+ issue.should respond_to a
8
+ end
9
+ end
10
+
11
+ describe "#config" do
12
+ it "should load the config from config.yml" do
13
+ issue.config.should == {"project"=>"project_name", "host"=>"http://localhost:3000", "api_key"=>"api_key"}
14
+ end
15
+ end
16
+
17
+ describe "#url (protected)" do
18
+ it "should build up URL based on the config" do
19
+ issue.send(:url, '123').should == 'http://localhost:3000/issues/123.xml?key=api_key'
20
+ end
21
+
22
+ end
23
+
24
+
25
+ describe "#get_for_commit" do
26
+ it "should parse the commit message to find a commit_id and call #get" do
27
+ commit_msg = 'A commit msg Issue #123'
28
+ CommitMsgToIssueId.should_receive(:parse).with(commit_msg)
29
+ Issue.get_for_commit(commit_msg)
30
+ end
31
+ end
32
+
33
+ describe "#get (class method)" do
34
+ it "should build_via_issue_id" do
35
+ issue = Issue.new
36
+ Issue.should_receive(:new) { issue }
37
+ issue.should_receive(:build_via_issue_id)
38
+ Issue.get(123)
39
+ end
40
+ end
41
+
42
+ describe "#build_via_issue_id" do
43
+ before do
44
+ @httparty = mock(:http_party_response, :parsed_response => {'issue' => { 'subject' => 'A subject', 'status' => {'name' => 'Completed'}}})
45
+ issue.stub!(:get) { @httparty }
46
+ end
47
+
48
+ it "should get issue data and load attributes" do
49
+ issue.should_receive(:build_via_issue_id).with(123) { @httparty }
50
+ issue.build_via_issue_id(123)
51
+ end
52
+
53
+ it "should load attributes" do
54
+ issue.build_via_issue_id(123)
55
+ issue.id.should == 123
56
+ issue.subject.should == 'A subject'
57
+ issue.status.should == 'Completed'
58
+ end
59
+ end
60
+
61
+ describe "#get (protected instance method)" do
62
+ it "should create a new issue via HTTParty" do
63
+ issue.stub!(:url) { 'the_url' }
64
+ HTTParty.should_receive(:get).with('the_url')
65
+ issue.send(:get, 123)
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ #ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'rubygems'
7
+ require "bundler"
8
+ Bundler.require
9
+
10
+ require 'gitmine'
11
+
12
+ Rspec.configure do |config|
13
+ config.mock_with :rspec
14
+ end
15
+
16
+ Issue::CONFIG_FILE = File.join(File.dirname(__FILE__), 'config.yml')
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitmine
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Philippe Creux
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-26 00:00:00 -07:00
18
+ default_executable: gitmine
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: httparty
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: grit
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: rspec
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 1
53
+ - 2
54
+ - 9
55
+ version: 1.2.9
56
+ type: :development
57
+ version_requirements: *id003
58
+ description: Git log with status of associated redmine tickets
59
+ email: pcreux@gmail.com
60
+ executables:
61
+ - gitmine
62
+ extensions: []
63
+
64
+ extra_rdoc_files:
65
+ - LICENSE
66
+ - README.rdoc
67
+ files:
68
+ - .document
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.rdoc
73
+ - Rakefile
74
+ - VERSION
75
+ - autotest/discover.rb
76
+ - bin/gitmine
77
+ - gitmine.gemspec
78
+ - lib/gitmine.rb
79
+ - spec/commit_msg_to_issue_id_spec.rb
80
+ - spec/config.yml
81
+ - spec/gitmine_spec.rb
82
+ - spec/issue_spec.rb
83
+ - spec/spec_helper.rb
84
+ has_rdoc: true
85
+ homepage: http://github.com/pcreux/gitmine
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --charset=UTF-8
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.3.6
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Git log with status of associated redmine tickets
114
+ test_files:
115
+ - spec/commit_msg_to_issue_id_spec.rb
116
+ - spec/gitmine_spec.rb
117
+ - spec/issue_spec.rb
118
+ - spec/spec_helper.rb