tracker-git 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - jruby-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tracker-git.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,46 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara request specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
25
+
26
+ guard 'rspec', :version => 2 do
27
+ watch(%r{^spec/.+_spec\.rb$})
28
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
29
+ watch('spec/spec_helper.rb') { "spec" }
30
+
31
+ # Rails example
32
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
33
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
34
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
35
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
36
+ watch('config/routes.rb') { "spec/routing" }
37
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
38
+
39
+ # Capybara request specs
40
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
41
+
42
+ # Turnip features and steps
43
+ watch(%r{^spec/acceptance/(.+)\.feature$})
44
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
45
+ end
46
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Robbie Clutton
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Tracker::Git
2
+
3
+ Update Pivotal Tracker depending on your local Git repository.
4
+
5
+ This gem finds all finished stories and bugs and if it finds the story id in a Git commit, marks that story as delivery.
6
+
7
+ This has proved useful as part of a 'deploy to staging' strategy. If you automatically deploy to a staging environment after a successful continuous integration build, and want to update a story from 'finished' to 'delivered', then this Gem is for you.
8
+
9
+ ## CI
10
+
11
+ [![Build Status](https://secure.travis-ci.org/robb1e/tracker-git.png)](http://travis-ci.org/robb1e/tracker-git)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'tracker-git'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install tracker-git
26
+
27
+ ## Usage
28
+
29
+ This gem will create a 'tracker' binary. Call that in your deploy script with the following environment variables set, and your finished stories will be updated to delivered.
30
+
31
+ export tracker_token=abc123
32
+ export tracker_project_id=123456
33
+
34
+ ## Known Issues
35
+
36
+ - [Restarting stories](https://github.com/robb1e/tracker-git/issues/1)
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ task :rspec do
5
+ if system("bundle exec rspec spec")
6
+ puts "Specs passed!"
7
+ else
8
+ puts "Specs failed!!!"
9
+ exit(1)
10
+ end
11
+ end
12
+
13
+ task :default => [:rspec]
data/bin/tracker ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require 'tracker-git'
4
+ rescue LoadError
5
+ require 'rubygems'
6
+ require 'tracker-git'
7
+ end
8
+
9
+ tracker_token = ENV['tracker_token']
10
+ project_id = ENV['tracker_project_id']
11
+
12
+ project = Tracker::Project.new(tracker_token, project_id)
13
+ git = Tracker::Git.new
14
+ deliverer = Tracker::Deliverer.new(project, git)
15
+
16
+ deliverer.mark_as_delivered
@@ -0,0 +1,5 @@
1
+ require "tracker-git/version"
2
+ require "tracker-git/project"
3
+ require "tracker-git/git"
4
+ require "tracker-git/deliverer"
5
+
@@ -0,0 +1,17 @@
1
+ module Tracker
2
+ class Deliverer
3
+ attr_reader :project, :git
4
+ def initialize(project, git)
5
+ @project = project
6
+ @git = git
7
+ end
8
+
9
+ def mark_as_delivered
10
+ project.finished.each do |story|
11
+ if git.contains?(story.id)
12
+ project.deliver(story)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Tracker
2
+ class Git
3
+ def contains?(message, options = {})
4
+ branch = options.fetch(:branch, "master")
5
+ result = `git log --grep '#{message}' #{branch}`
6
+ result.length > 0
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ require 'pivotal-tracker'
2
+
3
+ module Tracker
4
+ class Project
5
+
6
+ attr_reader :tracker_token, :project_id
7
+
8
+ def initialize(tracker_token, project_id)
9
+ @tracker_token = tracker_token
10
+ @project_id = project_id
11
+
12
+ PivotalTracker::Client.token = tracker_token
13
+ PivotalTracker::Client.use_ssl = true
14
+ end
15
+
16
+ def finished
17
+ _project.stories.all(state: "finished", story_type: ['bug', 'feature'])
18
+ end
19
+
20
+ def deliver(story)
21
+ story.update(current_state: "delivered")
22
+ end
23
+
24
+ private
25
+ def _project
26
+ @project ||= PivotalTracker::Project.find(project_id)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Tracker
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tracker::Deliverer do
4
+
5
+ let(:tracker_token) { stub }
6
+ let(:project_id) { stub }
7
+ let(:commited_story) { stub(id: 1) }
8
+ let(:uncommited_story) { stub(id: 2) }
9
+ let(:finished_stories) { [commited_story, uncommited_story] }
10
+ let(:project) { stub }
11
+ let(:git) { stub }
12
+ let(:deliverer) { Tracker::Deliverer.new(project, git) }
13
+
14
+ describe "mark_as_delivered" do
15
+ it("should mark stories as delivered") do
16
+ project.should_receive(:finished) { finished_stories }
17
+ git.should_receive(:contains?).with(1) { true }
18
+ git.should_receive(:contains?).with(2) { false }
19
+ project.should_receive(:deliver).with(commited_story)
20
+ project.should_not_receive(:deliver).with(uncommited_story)
21
+
22
+ deliverer.mark_as_delivered
23
+ end
24
+ end
25
+
26
+ end
data/spec/git_spec.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tracker::Git do
4
+ describe "#search" do
5
+ let(:message) { "[Finishes #123456]" }
6
+ let(:branch) { "master" }
7
+ let(:query) { "git log --grep '#{message}' #{branch}"}
8
+ let(:result) { "Some git message" }
9
+
10
+ before do
11
+ git.should_receive(:`).with(query) { result }
12
+ end
13
+ let(:git) { Tracker::Git.new }
14
+
15
+ context "defaults" do
16
+ it "searches via system calls using default branch" do
17
+ git.contains?(message).should == true
18
+ end
19
+ end
20
+
21
+ context "passing branch" do
22
+ let(:branch) { "test" }
23
+ it "searches via system calls using given branch" do
24
+ git.contains?(message, branch: branch).should == true
25
+ end
26
+ end
27
+
28
+ context "no result found" do
29
+ let(:result) { "" }
30
+ it "returns false" do
31
+ git.contains?(message).should == false
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tracker::Project do
4
+
5
+ let(:tracker_token) { stub }
6
+ let(:project_id) { stub }
7
+ let(:the_project) { stub }
8
+ let(:feature) { stub }
9
+ let(:bug) { stub }
10
+
11
+ describe "#initialize" do
12
+ it "initializes the project class" do
13
+ project = Tracker::Project.new(tracker_token, project_id)
14
+ project.should be
15
+ project.tracker_token.should == tracker_token
16
+ project.project_id.should == project_id
17
+ end
18
+ end
19
+
20
+ describe "#finished" do
21
+
22
+ let(:query) { stub }
23
+
24
+ before do
25
+ PivotalTracker::Project.should_receive(:find).with(project_id) { the_project }
26
+ the_project.should_receive(:stories) { query }
27
+ query.should_receive(:all).with(state: "finished", story_type: ['bug', 'feature']) { [feature, bug] }
28
+ end
29
+
30
+ it "retrieves finished stories and bugs" do
31
+ project = Tracker::Project.new(tracker_token, project_id)
32
+ project.finished.should == [feature, bug]
33
+ end
34
+ end
35
+
36
+ describe "#deliver" do
37
+ let(:project) { Tracker::Project.new(stub, stub) }
38
+ let(:story) { stub }
39
+
40
+ it "marks the story as delivered" do
41
+ story.should_receive(:update).with(current_state: "delivered")
42
+ project.deliver(story)
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,6 @@
1
+ RSpec.configure do |config|
2
+ config.run_all_when_everything_filtered = true
3
+
4
+ require File.dirname(__FILE__) + '/../lib/tracker-git'
5
+ require 'pivotal_tracker'
6
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/tracker-git/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Robbie Clutton"]
6
+ gem.email = ["robert.clutton@gmail.com"]
7
+ gem.description = %q{Tracker integration: Update Tracker based on current Git repo.}
8
+ gem.summary = %q{Tracker integration.}
9
+ gem.homepage = ""
10
+
11
+ gem.add_runtime_dependency 'pivotal-tracker'
12
+ gem.add_development_dependency "rspec"
13
+ gem.add_development_dependency "guard-rspec"
14
+ gem.add_development_dependency "rake"
15
+
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.name = "tracker-git"
20
+ gem.require_paths = ["lib"]
21
+ gem.version = Tracker::VERSION
22
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tracker-git
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robbie Clutton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pivotal-tracker
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard-rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ! 'Tracker integration: Update Tracker based on current Git repo.'
79
+ email:
80
+ - robert.clutton@gmail.com
81
+ executables:
82
+ - tracker
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - .rspec
88
+ - .travis.yml
89
+ - Gemfile
90
+ - Guardfile
91
+ - LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - bin/tracker
95
+ - lib/tracker-git.rb
96
+ - lib/tracker-git/deliverer.rb
97
+ - lib/tracker-git/git.rb
98
+ - lib/tracker-git/project.rb
99
+ - lib/tracker-git/version.rb
100
+ - spec/deliverer_spec.rb
101
+ - spec/git_spec.rb
102
+ - spec/project_spec.rb
103
+ - spec/spec_helper.rb
104
+ - tracker-git.gemspec
105
+ homepage: ''
106
+ licenses: []
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ segments:
118
+ - 0
119
+ hash: -4298825467225277464
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ segments:
127
+ - 0
128
+ hash: -4298825467225277464
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 1.8.24
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: Tracker integration.
135
+ test_files:
136
+ - spec/deliverer_spec.rb
137
+ - spec/git_spec.rb
138
+ - spec/project_spec.rb
139
+ - spec/spec_helper.rb