pivotal-git-tracker 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e5ade6820466519a7d7a21ea6840893b2be0fa5d
4
+ data.tar.gz: 3c14d53daff6caa970f28108a1421aaa378cd603
5
+ SHA512:
6
+ metadata.gz: 82ec3bbcdb85c62b1a151a1ff3d70ad335e848bf75834dbb98ab4d9b25821f655862779ec8b3701ca986bcf16baecd2a51361a47fe0a65a7a2d32ca904a012c4
7
+ data.tar.gz: cd087b2f2c298fced103756387f4d722d46218361d5d8be0eb30e2265cc5750c182672bc198cc566b7f084b53a4a2e441f38011892a8c810294f8d69c211c94b
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ *.iml
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ .idea
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rakeTasks ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build tracker-git-0.0.5.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Build and install tracker-git-0.0.5.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install tracker-git-0.0.5.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.0.5 and build and push tracker-git-0.0.5.gem to Rubygems" fullCmd="release" taksId="release" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup><RakeTask description="" fullCmd="rspec" taksId="rspec" /></RakeGroup></Settings>
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tracker-git.gemspec
4
+ gemspec
5
+
6
+ group :tracker do
7
+ gem 'pivotal-tracker', '~> 0.5', '>= 0.5.10'
8
+ gem 'happymapper'
9
+ gem 'nokogiri'
10
+ gem 'rest-client'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pivotal-git-tracker (0.1.0)
5
+ pivotal-tracker (>= 0.5.10)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ builder (3.2.2)
11
+ celluloid (0.16.0)
12
+ timers (~> 4.0.0)
13
+ coderay (1.1.0)
14
+ crack (0.4.2)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.2.5)
17
+ ffi (1.9.3)
18
+ formatador (0.2.5)
19
+ guard (2.6.1)
20
+ formatador (>= 0.2.4)
21
+ listen (~> 2.7)
22
+ lumberjack (~> 1.0)
23
+ pry (>= 0.9.12)
24
+ thor (>= 0.18.1)
25
+ guard-rspec (4.3.1)
26
+ guard (~> 2.1)
27
+ rspec (>= 2.14, < 4.0)
28
+ happymapper (0.4.1)
29
+ libxml-ruby (~> 2.0)
30
+ hitimes (1.2.2)
31
+ json (1.8.1)
32
+ libxml-ruby (2.7.0)
33
+ listen (2.7.9)
34
+ celluloid (>= 0.15.2)
35
+ rb-fsevent (>= 0.9.3)
36
+ rb-inotify (>= 0.9)
37
+ lumberjack (1.0.9)
38
+ method_source (0.8.2)
39
+ mime-types (1.25.1)
40
+ mini_portile (0.6.0)
41
+ nokogiri (1.6.3.1)
42
+ mini_portile (= 0.6.0)
43
+ nokogiri-happymapper (0.5.9)
44
+ nokogiri (~> 1.5)
45
+ pivotal-tracker (0.5.12)
46
+ builder
47
+ crack
48
+ happymapper (>= 0.3.2)
49
+ nokogiri (>= 1.4.3)
50
+ nokogiri (>= 1.5.5)
51
+ nokogiri-happymapper (>= 0.5.4)
52
+ rest-client (~> 1.6.0)
53
+ pry (0.10.1)
54
+ coderay (~> 1.1.0)
55
+ method_source (~> 0.8.1)
56
+ slop (~> 3.4)
57
+ rake (10.3.2)
58
+ rb-fsevent (0.9.4)
59
+ rb-inotify (0.9.5)
60
+ ffi (>= 0.5.0)
61
+ rdoc (4.1.1)
62
+ json (~> 1.4)
63
+ rest-client (1.6.8)
64
+ mime-types (~> 1.16)
65
+ rdoc (>= 2.4.2)
66
+ rspec (3.1.0)
67
+ rspec-core (~> 3.1.0)
68
+ rspec-expectations (~> 3.1.0)
69
+ rspec-mocks (~> 3.1.0)
70
+ rspec-core (3.1.1)
71
+ rspec-support (~> 3.1.0)
72
+ rspec-expectations (3.1.0)
73
+ diff-lcs (>= 1.2.0, < 2.0)
74
+ rspec-support (~> 3.1.0)
75
+ rspec-mocks (3.1.0)
76
+ rspec-support (~> 3.1.0)
77
+ rspec-support (3.1.0)
78
+ safe_yaml (1.0.3)
79
+ slop (3.6.0)
80
+ thor (0.19.1)
81
+ timers (4.0.0)
82
+ hitimes
83
+
84
+ PLATFORMS
85
+ ruby
86
+
87
+ DEPENDENCIES
88
+ guard-rspec
89
+ happymapper
90
+ nokogiri
91
+ pivotal-git-tracker!
92
+ pivotal-tracker (~> 0.5, >= 0.5.10)
93
+ rake
94
+ rest-client
95
+ rspec
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) 2015 myTomorrows
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,66 @@
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
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'tracker-git'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tracker-git
22
+
23
+ ## Usage
24
+
25
+ This gem will create a 'tracker' binary. Call that in your deploy script with
26
+ the tracker id and access token as command line arguments, or with following
27
+ environment variables set, and your finished stories will be updated to
28
+ delivered.
29
+
30
+ export TRACKER_PROJECT_ID=123456
31
+ export TRACKER_TOKEN=abc123
32
+ tracker
33
+
34
+ You can also pass the project id and token in as parameters
35
+
36
+ tracker 123456 abc123
37
+
38
+ ## Optional parameters
39
+
40
+ Optionally you can specify a git branch to search for completed story IDs as
41
+ the third command line argument or with the GIT\_BRANCH environment variable.
42
+
43
+ If you want to add a label (tag) to the story marked as delivered, you
44
+ can use the `--label` flag:
45
+
46
+ tracker --label THE_LABEL
47
+
48
+
49
+ For detect tasks only in commits which delivered to servers
50
+
51
+ --remote-branch=heroku/master
52
+
53
+ For commenting task with message 'Delivered by script to <%server_name_parameter%>'
54
+
55
+ --server-name=staging
56
+
57
+ Optionally you can specify a git branch to search for completed story IDs as
58
+ the third command line argument or with the GIT\_BRANCH environment variable.
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 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,58 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+
4
+ begin
5
+ require 'pivotal-git-tracker'
6
+ require 'optparse'
7
+ rescue LoadError
8
+ require 'rubygems'
9
+ require 'pivotal-git-tracker'
10
+ end
11
+
12
+ remote_branch, server_name = [ENV['REMOTE_BRANCH'], ENV['SERVER_NAME']]
13
+ options = {}
14
+ OptionParser.new do |opts|
15
+ opts.banner = "Usage: example.rb [options]"
16
+
17
+ opts.on("-l", "--label LABEL", "Add a label to a story marked as deployed") do |label|
18
+ options[:label] = label if label =~ /[^[:space:]]/
19
+ end
20
+
21
+ opts.on("-a", "--accept", "Changes status from delivered to accepted") do |accept|
22
+ options[:accept] = true
23
+ end
24
+
25
+ opts.on('--remote-branch [VALUE]') do |value|
26
+ remote_branch = value
27
+ end
28
+
29
+ opts.on('--server-name [VALUE]') do |value|
30
+ server_name = value
31
+ end
32
+ end.parse!
33
+
34
+ project_id, tracker_token, git_branch, server_name = \
35
+ if [2, 3, 4].include? ARGV.size
36
+ ARGV
37
+ else
38
+ [ENV['TRACKER_PROJECT_ID'], ENV['TRACKER_TOKEN'], ENV['GIT_BRANCH']]
39
+ end
40
+
41
+ unless tracker_token && project_id
42
+ puts <<-USAGE
43
+ Usage: Pass your pivotal tracker project id and access token on the command
44
+ line, e.g:
45
+ tracker 123456 abc123
46
+ or as an environment variable:
47
+ export TRACKER_PROJECT_ID=123456
48
+ export TRACKER_TOKEN=abc123
49
+ tracker
50
+ USAGE
51
+ exit(1)
52
+ end
53
+
54
+ project = Tracker::Project.new(tracker_token, project_id)
55
+ git = Tracker::Git.new
56
+ deliverer = Tracker::Deliverer.new(project, git)
57
+ deliverer.mark_as_delivered(git_branch, remote_branch, options[:label], false, server_name)
58
+ deliverer.mark_as_accepted(git_branch, remote_branch, options[:label]) if options[:accept]
@@ -0,0 +1,30 @@
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(branch = nil,remote_branch= nil, label = nil, use_accepted = false, server_name = nil)
10
+ options = {}
11
+ options[:branch] = branch if branch
12
+ options[:remote_branch] = remote_branch if remote_branch
13
+
14
+ collection = use_accepted ? project.delivered : project.finished
15
+
16
+ collection.each do |story|
17
+ if git.contains?(story.id, options)
18
+ project.accept(story) if use_accepted
19
+ project.deliver(story) unless use_accepted
20
+ project.add_label(story, label) if label
21
+ project.comment(story, server_name) if server_name
22
+ end
23
+ end
24
+ end
25
+
26
+ def mark_as_accepted(branch = nil,remote_branch = nil, label = nil)
27
+ mark_as_delivered(branch, remote_branch, label, true)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ module Tracker
2
+ class Git
3
+ def contains?(message, options = {})
4
+ branch = options.fetch(:branch, "HEAD")
5
+ remote_branch = options[:remote_branch]
6
+ result = `git log #{[remote_branch, branch].compact.join('..')} --grep='#{message}'`
7
+ result.length > 0
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,47 @@
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 delivered
21
+ _project.stories.all(state: "delivered", story_type: ['bug', 'feature'])
22
+ end
23
+
24
+ def deliver(story)
25
+ story.update(current_state: "delivered")
26
+ end
27
+
28
+ def accept(story)
29
+ story.update(current_state: "accepted")
30
+ end
31
+
32
+ def add_label(story, label)
33
+ labels = (story.labels || "").split(",")
34
+ labels << label
35
+ story.update(labels: labels.join(","))
36
+ end
37
+
38
+ def comment(story, server_name)
39
+ story.notes.create(:text => "Delivered by script to #{server_name}")
40
+ end
41
+
42
+ private
43
+ def _project
44
+ @project ||= PivotalTracker::Project.find(project_id)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Tracker
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "pivotal-git-tracker/version"
2
+ require "pivotal-git-tracker/project"
3
+ require "pivotal-git-tracker/git"
4
+ require "pivotal-git-tracker/deliverer"
5
+
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/pivotal-git-tracker/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Marcel Panse"]
6
+ gem.email = ["marcel.panse@gmail.com"]
7
+ gem.description = %q{Tracker integration: Update Tracker based on current Git repo.}
8
+ gem.summary = %q{Tracker integration.}
9
+ gem.homepage = "https://github.com/myTomorrows/pivotal-git-tracker"
10
+ gem.license = 'MIT'
11
+
12
+ gem.add_runtime_dependency('pivotal-tracker', '>= 0.5.10')
13
+ gem.add_development_dependency "rspec"
14
+ gem.add_development_dependency "guard-rspec"
15
+ gem.add_development_dependency "rake"
16
+
17
+ gem.files = `git ls-files`.split($\)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.name = "pivotal-git-tracker"
21
+ gem.require_paths = ["lib"]
22
+ gem.version = Tracker::VERSION
23
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tracker::Deliverer do
4
+
5
+ let(:tracker_token) { double }
6
+ let(:project_id) { double }
7
+ let(:commited_story) { double(id: 1) }
8
+ let(:uncommited_story) { double(id: 2) }
9
+ let(:finished_stories) { [commited_story, uncommited_story] }
10
+ let(:project) { double }
11
+ let(:git) { double }
12
+ let(:deliverer) { Tracker::Deliverer.new(project, git) }
13
+
14
+ describe '#mark_as_delivered' do
15
+ context 'when called without argument' do
16
+ it('should mark stories as delivered') do
17
+ expect(project).to receive(:finished) { finished_stories }
18
+ expect(git).to receive(:contains?).with(1, {}) { true }
19
+ expect(git).to receive(:contains?).with(2, {}) { false }
20
+ expect(project).to receive(:deliver).with(commited_story)
21
+ expect(project).to_not receive(:deliver).with(uncommited_story)
22
+ expect(project).to_not receive(:comment).with(uncommited_story)
23
+
24
+ deliverer.mark_as_delivered
25
+ end
26
+ end
27
+
28
+ context 'when given a specific branch' do
29
+ it('should mark stories as delivered') do
30
+ expect(project).to receive(:finished) { finished_stories }
31
+ expect(git).to receive(:contains?).with(1, {branch: 'develop'}) { true }
32
+ expect(git).to receive(:contains?).with(2, {branch: 'develop'}) { false }
33
+ expect(project).to receive(:deliver).with(commited_story)
34
+ expect(project).to_not receive(:deliver).with(uncommited_story)
35
+ expect(project).to_not receive(:comment)
36
+ deliverer.mark_as_delivered('develop')
37
+ end
38
+ end
39
+
40
+ context 'when given a label to add' do
41
+ it('should mark stories as delivered and add a label') do
42
+ expect(project).to receive(:finished) { finished_stories }
43
+ expect(git).to receive(:contains?).with(1, {}) { true }
44
+ expect(git).to receive(:contains?).with(2, {}) { false }
45
+ expect(project).to receive(:deliver).with(commited_story)
46
+ expect(project).to_not receive(:deliver).with(uncommited_story)
47
+ expect(project).to receive(:add_label).with(commited_story, 'label')
48
+ expect(project).to_not receive(:add_label).with(uncommited_story, 'label')
49
+
50
+ deliverer.mark_as_delivered(nil, nil, 'label')
51
+ end
52
+ end
53
+
54
+ context 'when given a specific server name' do
55
+ it('should comment story with server name where story is delivered') do
56
+ expect(project).to receive(:comment)
57
+ expect(project).to receive(:finished) { finished_stories }
58
+ expect(git).to receive(:contains?).with(1, {}) { true }
59
+ expect(git).to receive(:contains?).with(2, {}) { false }
60
+ expect(project).to receive(:deliver).with(commited_story)
61
+ expect(project).not_to receive(:deldeliveriver).with(commited_story)
62
+
63
+ deliverer.mark_as_delivered(nil, nil, nil, false, 'spot instance')
64
+ end
65
+
66
+ end
67
+ end
68
+
69
+ end
data/spec/git_spec.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tracker::Git do
4
+ describe "#search" do
5
+ let(:message) { "[Finishes #123456]" }
6
+ let(:branch) { "HEAD" }
7
+ let(:query) { "git log #{branch} --grep='#{message}'" }
8
+ let(:result) { "Some git message" }
9
+ let(:git) { Tracker::Git.new }
10
+
11
+ context 'when remote branch is not used' do
12
+ before do
13
+ expect(git).to receive(:`).with(query) { result }
14
+ end
15
+
16
+ context "defaults" do
17
+ it "searches via system calls using default branch" do
18
+ expect(git.contains?(message)).to eq(true)
19
+ end
20
+
21
+ context "passing branch" do
22
+ let(:branch) { "test" }
23
+ it "searches via system calls using given branch" do
24
+ expect(git.contains?(message, branch: branch)).to eq(true)
25
+ end
26
+
27
+ context "passing branch" do
28
+ let(:branch) { "test" }
29
+ it "searches via system calls using given branch" do
30
+ expect(git.contains?(message, branch: branch)).to eq(true)
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ context "no result found" do
37
+ let(:result) { "" }
38
+ it "returns false" do
39
+ expect(git.contains?(message)).to eq(false)
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ context "when remote brach is not blank" do
46
+ let(:remote_branch) { 'remote/branch' }
47
+ before { expect(git).to receive(:`).with("git log #{remote_branch}..#{branch} --grep='#{message}'") { result } }
48
+
49
+ it "searches via system calls using geven remote and local branches" do
50
+ git.contains?(message, branch: branch, remote_branch: remote_branch)
51
+ end
52
+
53
+ end
54
+
55
+
56
+ end
57
+ end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tracker::Project do
4
+
5
+ let(:tracker_token) { double }
6
+ let(:project_id) { double }
7
+ let(:the_project) { double }
8
+ let(:feature) { double }
9
+ let(:bug) { double }
10
+
11
+ describe "#initialize" do
12
+ it "initializes the project class" do
13
+ project = Tracker::Project.new(tracker_token, project_id)
14
+ expect(project).to be
15
+ expect(project.tracker_token).to eq(tracker_token)
16
+ expect(project.project_id).to eq(project_id)
17
+ end
18
+ end
19
+
20
+ describe "#finished" do
21
+
22
+ let(:query) { double }
23
+
24
+ before do
25
+ expect(PivotalTracker::Project).to receive(:find).with(project_id) { the_project }
26
+ expect(the_project).to receive(:stories) { query }
27
+ expect(query).to 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
+ expect(project.finished).to eq([feature, bug])
33
+ end
34
+ end
35
+
36
+ describe "#deliver" do
37
+ let(:project) { Tracker::Project.new(double, double) }
38
+ let(:story) { double }
39
+
40
+ it "marks the story as delivered" do
41
+ expect(story).to receive(:update).with(current_state: "delivered")
42
+ project.deliver(story)
43
+ end
44
+ end
45
+
46
+ describe "#add_label" do
47
+ let(:project) { Tracker::Project.new(double, double) }
48
+ let(:story) { double }
49
+
50
+ context 'there is no label on the story' do
51
+ it "adds a label" do
52
+ expect(story).to receive(:labels) { '' }
53
+ expect(story).to receive(:update).with(labels: 'label')
54
+ project.add_label(story, 'label')
55
+ end
56
+ end
57
+
58
+ context 'there is already one label on the story' do
59
+ it "adds a label" do
60
+ expect(story).to receive(:labels) { 'foo' }
61
+ expect(story).to receive(:update).with(labels: 'foo,label')
62
+ project.add_label(story, 'label')
63
+ end
64
+ end
65
+
66
+ context 'there is already two labels on the story' do
67
+ it "adds a label" do
68
+ expect(story).to receive(:labels) { 'foo,bar' }
69
+ expect(story).to receive(:update).with(labels: 'foo,bar,label')
70
+ project.add_label(story, 'label')
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "#comment" do
76
+ let(:project) { Tracker::Project.new(double, double) }
77
+ let(:story) { double }
78
+ let(:notes_stub) { double }
79
+ let(:server_name) {'spot instance' }
80
+
81
+ before { allow(notes_stub).to receive(:create).with( hash_including(:text => "Delivered by script to #{server_name}")) }
82
+ before { expect(story).to receive(:notes) { notes_stub } }
83
+
84
+ it "comment story with server" do
85
+ project.comment story, server_name
86
+ end
87
+
88
+ end
89
+
90
+ 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/pivotal-git-tracker'
5
+ require 'pivotal_tracker'
6
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pivotal-git-tracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcel Panse
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pivotal-tracker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.10
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: 'Tracker integration: Update Tracker based on current Git repo.'
70
+ email:
71
+ - marcel.panse@gmail.com
72
+ executables:
73
+ - tracker
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rakeTasks"
79
+ - ".rspec"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - Guardfile
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - bin/tracker
87
+ - lib/pivotal-git-tracker.rb
88
+ - lib/pivotal-git-tracker/deliverer.rb
89
+ - lib/pivotal-git-tracker/git.rb
90
+ - lib/pivotal-git-tracker/project.rb
91
+ - lib/pivotal-git-tracker/version.rb
92
+ - privotal-git-tracker.gemspec
93
+ - spec/deliverer_spec.rb
94
+ - spec/git_spec.rb
95
+ - spec/project_spec.rb
96
+ - spec/spec_helper.rb
97
+ homepage: https://github.com/myTomorrows/pivotal-git-tracker
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.4.3
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Tracker integration.
121
+ test_files:
122
+ - spec/deliverer_spec.rb
123
+ - spec/git_spec.rb
124
+ - spec/project_spec.rb
125
+ - spec/spec_helper.rb