pivotal-git-tracker 0.1.0 → 0.2.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 +4 -4
- data/README.md +5 -33
- data/bin/tracker +5 -35
- data/lib/pivotal-git-tracker.rb +4 -4
- data/lib/pivotal-git-tracker/deliverer.rb +14 -8
- data/lib/pivotal-git-tracker/git.rb +8 -1
- data/lib/pivotal-git-tracker/project.rb +14 -7
- data/lib/pivotal-git-tracker/version.rb +1 -1
- data/spec/deliverer_spec.rb +11 -25
- data/spec/git_spec.rb +27 -20
- data/spec/project_spec.rb +14 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2651207423effbf1213ad57a1acdd440ad066284
|
4
|
+
data.tar.gz: 3d1066dc2d476e125008fbc11e4b643147c00c8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7155033ee3bf6421389cba48fbbb65bb6496c4983b57ee2ec36c03fc2dd4099f5945c87d4e867935b0f22cb552aefe6fb6c1c433eeca7bd62010bfcc0b104fb6
|
7
|
+
data.tar.gz: 26ca8296f54aa21ec7afb1db917bbe15ec8efbbe8e20fc182429c9533ac3d3d68eaf755d733f9a302d04959dab47c21742830d187e6c0d6628adadb3e75abec3
|
data/README.md
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Update Pivotal Tracker depending on your local Git repository.
|
4
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
|
6
|
-
|
5
|
+
This gem finds all finished stories and bugs and if it finds the story id in a Git commit, marks that story as delivered.
|
7
6
|
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.
|
7
|
+
The gem will add a comment to the Pivotal story everytime the commit is deployed to an environment (for example: staging -> acceptance -> production).
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
|
-
gem '
|
13
|
+
gem 'pivotal-git-tracker'
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
@@ -18,7 +18,7 @@ And then execute:
|
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
$ gem install
|
21
|
+
$ gem install pivotal-git-tracker
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
@@ -27,36 +27,8 @@ the tracker id and access token as command line arguments, or with following
|
|
27
27
|
environment variables set, and your finished stories will be updated to
|
28
28
|
delivered.
|
29
29
|
|
30
|
-
|
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
|
30
|
+
tracker 123456 abc123 branch-name server-name
|
37
31
|
|
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
32
|
## Contributing
|
61
33
|
|
62
34
|
1. Fork it
|
data/bin/tracker
CHANGED
@@ -1,52 +1,22 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'optparse'
|
3
2
|
|
4
3
|
begin
|
5
4
|
require 'pivotal-git-tracker'
|
6
|
-
require 'optparse'
|
7
5
|
rescue LoadError
|
8
6
|
require 'rubygems'
|
9
7
|
require 'pivotal-git-tracker'
|
10
8
|
end
|
11
9
|
|
12
|
-
|
13
|
-
|
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
|
10
|
+
project_id, tracker_token, git_branch, server_name, version = \
|
11
|
+
if [2, 3, 4, 5].include? ARGV.size
|
36
12
|
ARGV
|
37
|
-
else
|
38
|
-
[ENV['TRACKER_PROJECT_ID'], ENV['TRACKER_TOKEN'], ENV['GIT_BRANCH']]
|
39
13
|
end
|
40
14
|
|
41
15
|
unless tracker_token && project_id
|
42
16
|
puts <<-USAGE
|
43
17
|
Usage: Pass your pivotal tracker project id and access token on the command
|
44
18
|
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
|
19
|
+
tracker 123456 abc123 branch-name server-name version
|
50
20
|
USAGE
|
51
21
|
exit(1)
|
52
22
|
end
|
@@ -54,5 +24,5 @@ end
|
|
54
24
|
project = Tracker::Project.new(tracker_token, project_id)
|
55
25
|
git = Tracker::Git.new
|
56
26
|
deliverer = Tracker::Deliverer.new(project, git)
|
57
|
-
deliverer.mark_as_delivered(git_branch,
|
58
|
-
deliverer.
|
27
|
+
deliverer.mark_as_delivered(git_branch, server_name)
|
28
|
+
deliverer.find_and_comment(git_branch, server_name, version)
|
data/lib/pivotal-git-tracker.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
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
5
|
|
@@ -6,25 +6,31 @@ module Tracker
|
|
6
6
|
@git = git
|
7
7
|
end
|
8
8
|
|
9
|
-
def mark_as_delivered(branch = nil,
|
9
|
+
def mark_as_delivered(branch = nil, server_name = nil)
|
10
10
|
options = {}
|
11
11
|
options[:branch] = branch if branch
|
12
|
-
options[:remote_branch] = remote_branch if remote_branch
|
13
12
|
|
14
|
-
collection =
|
13
|
+
collection = project.finished
|
15
14
|
|
16
15
|
collection.each do |story|
|
17
16
|
if git.contains?(story.id, options)
|
18
|
-
|
19
|
-
project.deliver(story)
|
20
|
-
project.add_label(story, label) if label
|
17
|
+
puts "Delivering story with id #{story.id} on server #{server_name}"
|
18
|
+
project.deliver(story)
|
21
19
|
project.comment(story, server_name) if server_name
|
22
20
|
end
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
|
-
def
|
27
|
-
|
24
|
+
def find_and_comment(branch = nil, server_name = nil, version = nil)
|
25
|
+
options = {}
|
26
|
+
options[:branch] = branch if branch
|
27
|
+
|
28
|
+
for story_id in git.latest_log(options)
|
29
|
+
puts "Found story with id #{story_id} on server #{server_name}"
|
30
|
+
story = project.find(story_id)
|
31
|
+
project.comment(story, server_name)
|
32
|
+
project.add_label(story, version) if version
|
33
|
+
end
|
28
34
|
end
|
29
35
|
end
|
30
36
|
end
|
@@ -1,10 +1,17 @@
|
|
1
1
|
module Tracker
|
2
2
|
class Git
|
3
3
|
def contains?(message, options = {})
|
4
|
-
branch = options.fetch(:branch,
|
4
|
+
branch = options.fetch(:branch, 'HEAD')
|
5
5
|
remote_branch = options[:remote_branch]
|
6
6
|
result = `git log #{[remote_branch, branch].compact.join('..')} --grep='#{message}'`
|
7
7
|
result.length > 0
|
8
8
|
end
|
9
|
+
|
10
|
+
def latest_log(options = {})
|
11
|
+
branch = options.fetch(:branch, 'HEAD')
|
12
|
+
remote_branch = options[:remote_branch]
|
13
|
+
commits = `git log -n 100 #{[remote_branch, branch].compact.join('..')} --grep='#' --oneline`
|
14
|
+
commits = commits.scan(/#([0-9]+)/).flatten
|
15
|
+
end
|
9
16
|
end
|
10
17
|
end
|
@@ -13,30 +13,37 @@ module Tracker
|
|
13
13
|
PivotalTracker::Client.use_ssl = true
|
14
14
|
end
|
15
15
|
|
16
|
+
def find(story_id)
|
17
|
+
_project.stories.find(story_id)
|
18
|
+
end
|
19
|
+
|
16
20
|
def finished
|
17
|
-
_project.stories.all(state:
|
21
|
+
_project.stories.all(state: 'finished', story_type: ['bug', 'feature'])
|
18
22
|
end
|
19
23
|
|
20
24
|
def delivered
|
21
|
-
_project.stories.all(state:
|
25
|
+
_project.stories.all(state: 'delivered', story_type: ['bug', 'feature'])
|
22
26
|
end
|
23
27
|
|
24
28
|
def deliver(story)
|
25
|
-
story.update(current_state:
|
29
|
+
story.update(current_state: 'delivered')
|
26
30
|
end
|
27
31
|
|
28
32
|
def accept(story)
|
29
|
-
story.update(current_state:
|
33
|
+
story.update(current_state: 'accepted')
|
30
34
|
end
|
31
35
|
|
32
36
|
def add_label(story, label)
|
33
|
-
labels = (story.labels ||
|
37
|
+
labels = (story.labels || '').split(',')
|
34
38
|
labels << label
|
35
|
-
story.update(labels: labels.join(
|
39
|
+
story.update(labels: labels.join(','))
|
36
40
|
end
|
37
41
|
|
38
42
|
def comment(story, server_name)
|
39
|
-
|
43
|
+
msg = "Delivered by script to #{server_name}"
|
44
|
+
unless story.notes.all.include? msg
|
45
|
+
story.notes.create(:text => msg)
|
46
|
+
end
|
40
47
|
end
|
41
48
|
|
42
49
|
private
|
data/spec/deliverer_spec.rb
CHANGED
@@ -4,9 +4,9 @@ describe Tracker::Deliverer do
|
|
4
4
|
|
5
5
|
let(:tracker_token) { double }
|
6
6
|
let(:project_id) { double }
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
let(:finished_stories) { [
|
7
|
+
let(:committed_story) { double(id: 1) }
|
8
|
+
let(:uncommitted_story) { double(id: 2) }
|
9
|
+
let(:finished_stories) { [committed_story, uncommitted_story] }
|
10
10
|
let(:project) { double }
|
11
11
|
let(:git) { double }
|
12
12
|
let(:deliverer) { Tracker::Deliverer.new(project, git) }
|
@@ -17,9 +17,9 @@ describe Tracker::Deliverer do
|
|
17
17
|
expect(project).to receive(:finished) { finished_stories }
|
18
18
|
expect(git).to receive(:contains?).with(1, {}) { true }
|
19
19
|
expect(git).to receive(:contains?).with(2, {}) { false }
|
20
|
-
expect(project).to receive(:deliver).with(
|
21
|
-
expect(project).to_not receive(:deliver).with(
|
22
|
-
expect(project).to_not receive(:comment).with(
|
20
|
+
expect(project).to receive(:deliver).with(committed_story)
|
21
|
+
expect(project).to_not receive(:deliver).with(uncommitted_story)
|
22
|
+
expect(project).to_not receive(:comment).with(uncommitted_story)
|
23
23
|
|
24
24
|
deliverer.mark_as_delivered
|
25
25
|
end
|
@@ -30,37 +30,23 @@ describe Tracker::Deliverer do
|
|
30
30
|
expect(project).to receive(:finished) { finished_stories }
|
31
31
|
expect(git).to receive(:contains?).with(1, {branch: 'develop'}) { true }
|
32
32
|
expect(git).to receive(:contains?).with(2, {branch: 'develop'}) { false }
|
33
|
-
expect(project).to receive(:deliver).with(
|
34
|
-
expect(project).to_not receive(:deliver).with(
|
33
|
+
expect(project).to receive(:deliver).with(committed_story)
|
34
|
+
expect(project).to_not receive(:deliver).with(uncommitted_story)
|
35
35
|
expect(project).to_not receive(:comment)
|
36
36
|
deliverer.mark_as_delivered('develop')
|
37
37
|
end
|
38
38
|
end
|
39
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
40
|
context 'when given a specific server name' do
|
55
41
|
it('should comment story with server name where story is delivered') do
|
56
42
|
expect(project).to receive(:comment)
|
57
43
|
expect(project).to receive(:finished) { finished_stories }
|
58
44
|
expect(git).to receive(:contains?).with(1, {}) { true }
|
59
45
|
expect(git).to receive(:contains?).with(2, {}) { false }
|
60
|
-
expect(project).to receive(:deliver).with(
|
61
|
-
expect(project).not_to receive(:deldeliveriver).with(
|
46
|
+
expect(project).to receive(:deliver).with(committed_story)
|
47
|
+
expect(project).not_to receive(:deldeliveriver).with(committed_story)
|
62
48
|
|
63
|
-
deliverer.mark_as_delivered(nil,
|
49
|
+
deliverer.mark_as_delivered(nil, 'staging-server')
|
64
50
|
end
|
65
51
|
|
66
52
|
end
|
data/spec/git_spec.rb
CHANGED
@@ -1,57 +1,64 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Tracker::Git do
|
4
|
-
describe
|
5
|
-
let(:message) {
|
6
|
-
let(:branch) {
|
4
|
+
describe '#search' do
|
5
|
+
let(:message) { '[Finishes #123456]' }
|
6
|
+
let(:branch) { 'HEAD' }
|
7
7
|
let(:query) { "git log #{branch} --grep='#{message}'" }
|
8
|
-
let(:result) {
|
8
|
+
let(:result) { 'Some git message' }
|
9
9
|
let(:git) { Tracker::Git.new }
|
10
10
|
|
11
|
+
context 'from history' do
|
12
|
+
before do
|
13
|
+
expect(git).to receive(:`).with("git log -n 100 HEAD --grep='#' --oneline") { '#100 #99' }
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'gets latest x logs' do
|
17
|
+
expect(git.latest_log).to eq(['100', '99'])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
11
21
|
context 'when remote branch is not used' do
|
12
22
|
before do
|
13
23
|
expect(git).to receive(:`).with(query) { result }
|
14
24
|
end
|
15
25
|
|
16
|
-
context
|
17
|
-
it
|
26
|
+
context 'defaults' do
|
27
|
+
it 'searches via system calls using default branch' do
|
18
28
|
expect(git.contains?(message)).to eq(true)
|
19
29
|
end
|
20
30
|
|
21
|
-
context
|
22
|
-
let(:branch) {
|
23
|
-
it
|
31
|
+
context 'passing branch' do
|
32
|
+
let(:branch) { 'test' }
|
33
|
+
it 'searches via system calls using given branch' do
|
24
34
|
expect(git.contains?(message, branch: branch)).to eq(true)
|
25
35
|
end
|
26
36
|
|
27
|
-
context
|
28
|
-
let(:branch) {
|
29
|
-
it
|
37
|
+
context 'passing branch' do
|
38
|
+
let(:branch) { 'test' }
|
39
|
+
it 'searches via system calls using given branch' do
|
30
40
|
expect(git.contains?(message, branch: branch)).to eq(true)
|
31
41
|
end
|
32
42
|
end
|
33
43
|
|
34
44
|
end
|
35
45
|
|
36
|
-
context
|
37
|
-
let(:result) {
|
38
|
-
it
|
46
|
+
context 'no result found' do
|
47
|
+
let(:result) { '' }
|
48
|
+
it 'returns false' do
|
39
49
|
expect(git.contains?(message)).to eq(false)
|
40
50
|
end
|
41
51
|
end
|
42
52
|
end
|
43
53
|
end
|
44
54
|
|
45
|
-
context
|
55
|
+
context 'when remote brach is not blank' do
|
46
56
|
let(:remote_branch) { 'remote/branch' }
|
47
57
|
before { expect(git).to receive(:`).with("git log #{remote_branch}..#{branch} --grep='#{message}'") { result } }
|
48
58
|
|
49
|
-
it
|
59
|
+
it 'searches via system calls using geven remote and local branches' do
|
50
60
|
git.contains?(message, branch: branch, remote_branch: remote_branch)
|
51
61
|
end
|
52
|
-
|
53
62
|
end
|
54
|
-
|
55
|
-
|
56
63
|
end
|
57
64
|
end
|
data/spec/project_spec.rb
CHANGED
@@ -8,8 +8,8 @@ describe Tracker::Project do
|
|
8
8
|
let(:feature) { double }
|
9
9
|
let(:bug) { double }
|
10
10
|
|
11
|
-
describe
|
12
|
-
it
|
11
|
+
describe '#initialize' do
|
12
|
+
it 'initializes the project class' do
|
13
13
|
project = Tracker::Project.new(tracker_token, project_id)
|
14
14
|
expect(project).to be
|
15
15
|
expect(project.tracker_token).to eq(tracker_token)
|
@@ -17,38 +17,37 @@ describe Tracker::Project do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
describe
|
21
|
-
|
20
|
+
describe '#finished' do
|
22
21
|
let(:query) { double }
|
23
22
|
|
24
23
|
before do
|
25
24
|
expect(PivotalTracker::Project).to receive(:find).with(project_id) { the_project }
|
26
25
|
expect(the_project).to receive(:stories) { query }
|
27
|
-
expect(query).to receive(:all).with(state:
|
26
|
+
expect(query).to receive(:all).with(state: 'finished', story_type: ['bug', 'feature']) { [feature, bug] }
|
28
27
|
end
|
29
28
|
|
30
|
-
it
|
29
|
+
it 'retrieves finished stories and bugs' do
|
31
30
|
project = Tracker::Project.new(tracker_token, project_id)
|
32
31
|
expect(project.finished).to eq([feature, bug])
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
36
|
-
describe
|
35
|
+
describe '#deliver' do
|
37
36
|
let(:project) { Tracker::Project.new(double, double) }
|
38
37
|
let(:story) { double }
|
39
38
|
|
40
|
-
it
|
41
|
-
expect(story).to receive(:update).with(current_state:
|
39
|
+
it 'marks the story as delivered' do
|
40
|
+
expect(story).to receive(:update).with(current_state: 'delivered')
|
42
41
|
project.deliver(story)
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
46
|
-
describe
|
45
|
+
describe '#add_label' do
|
47
46
|
let(:project) { Tracker::Project.new(double, double) }
|
48
47
|
let(:story) { double }
|
49
48
|
|
50
49
|
context 'there is no label on the story' do
|
51
|
-
it
|
50
|
+
it 'adds a label' do
|
52
51
|
expect(story).to receive(:labels) { '' }
|
53
52
|
expect(story).to receive(:update).with(labels: 'label')
|
54
53
|
project.add_label(story, 'label')
|
@@ -56,7 +55,7 @@ describe Tracker::Project do
|
|
56
55
|
end
|
57
56
|
|
58
57
|
context 'there is already one label on the story' do
|
59
|
-
it
|
58
|
+
it 'adds a label' do
|
60
59
|
expect(story).to receive(:labels) { 'foo' }
|
61
60
|
expect(story).to receive(:update).with(labels: 'foo,label')
|
62
61
|
project.add_label(story, 'label')
|
@@ -64,7 +63,7 @@ describe Tracker::Project do
|
|
64
63
|
end
|
65
64
|
|
66
65
|
context 'there is already two labels on the story' do
|
67
|
-
it
|
66
|
+
it 'adds a label' do
|
68
67
|
expect(story).to receive(:labels) { 'foo,bar' }
|
69
68
|
expect(story).to receive(:update).with(labels: 'foo,bar,label')
|
70
69
|
project.add_label(story, 'label')
|
@@ -72,7 +71,7 @@ describe Tracker::Project do
|
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
75
|
-
describe
|
74
|
+
describe '#comment' do
|
76
75
|
let(:project) { Tracker::Project.new(double, double) }
|
77
76
|
let(:story) { double }
|
78
77
|
let(:notes_stub) { double }
|
@@ -81,7 +80,7 @@ describe Tracker::Project do
|
|
81
80
|
before { allow(notes_stub).to receive(:create).with( hash_including(:text => "Delivered by script to #{server_name}")) }
|
82
81
|
before { expect(story).to receive(:notes) { notes_stub } }
|
83
82
|
|
84
|
-
it
|
83
|
+
it 'comment story with server' do
|
85
84
|
project.comment story, server_name
|
86
85
|
end
|
87
86
|
|