pivotal-github 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d5c6c4ff6bc562432cdad32deefcadd1095ce31
4
- data.tar.gz: 4ad424a5c6365e1bea404ecef4bec42ddab9e61d
3
+ metadata.gz: 790d9af1927198ccaa10a814e1b55e7ac8297427
4
+ data.tar.gz: 19ac915287456c91a30b2186738a12a83cc49b7e
5
5
  SHA512:
6
- metadata.gz: 9d4e770331dccb47984810e94565c198290687d7adb4168bd2577ffb7afd1a3e1e1227a5fd4ce4964ce6ba05efc2054efe09b5b81f4273d858549bfa77517f7a
7
- data.tar.gz: 89fcc3a626db9d8fca1f3e16663404f45311d05f453962c9ed3da114838ae352b47b3ad430f19bdd1c14178668c83758301e7d53bb206bdce9c9fdbe9c1e13bd
6
+ metadata.gz: 66d8f52e653b9a08848bbc01937cab720d7a37db2367ea8ee0bb94af683ab7673893c3d890dc768fda4aa9ce6e0ca17aa634b36f4781b46759fcc734e5818372
7
+ data.tar.gz: ede4d84d31bc6c87cf7fadf9c151106c9002d8d99322989077cf80e30ce1ed61ee8fb0516bc7f30dba47b00c13d11adcac9b3c43e426779b23e64fcb5dd6c5be
data/README.md CHANGED
@@ -132,8 +132,6 @@ As with `git story-merge`, by default `git story-pull-request` exits with a warn
132
132
 
133
133
  The purpose of `git story-accept` is to accept stories that have been merged into `master`, so by default it works only on the master branch. This requirement can be overridden by the `--override` option.
134
134
 
135
- In order to avoid reading the entire Git log every time it's run, by default `git story-accept` stops immediately after finding a story that has already been accepted. The assumption is that `git story-accept` is run immediately after merging a pull request into a master branch that is always up-to-date, so that there are no delivered but unaccepted stories further down in the log.
136
-
137
135
  `git story-accept` requires the existence of `.api_token` and `.project_id` files containing the Pivotal Tracker API token and project id, respectively. The user is prompted to create them if they are not present. (They aren't read from the command line using `gets` due to an incompatibility with options passing.)
138
136
 
139
137
  #### Options
@@ -141,8 +139,8 @@ In order to avoid reading the entire Git log every time it's run, by default `gi
141
139
  Usage: git story-accept [options]
142
140
  -o, --override override master branch requirement
143
141
  -q, --quiet suppress display of accepted story ids
144
- -a, --all process all stories (entire log)
145
142
  -h, --help this usage guide
143
+
146
144
  ### story-open
147
145
 
148
146
  The `story-open` command (no `git`) opens the current story in the default browser (OS X–only):
@@ -16,9 +16,6 @@ class StoryAccept < Command
16
16
  opts.on("-q", "--quiet", "suppress display of accepted story ids") do |opt|
17
17
  self.options.quiet = opt
18
18
  end
19
- opts.on("-a", "--all", "process all stories (entire log)") do |opt|
20
- self.options.all = opt
21
- end
22
19
  opts.on_tail("-h", "--help", "this usage guide") do
23
20
  puts opts.to_s; exit 0
24
21
  end
@@ -32,24 +29,38 @@ class StoryAccept < Command
32
29
  end
33
30
 
34
31
  # Returns the ids to accept.
35
- # These ids are of the form [Delivers #<story id>] or
36
- # [Delivers #<story id> #<another story id>].
32
+ # The stories to accept are the set intersection of the delivered stories
33
+ # according to the Git log and according to Pivotal Tracker.
37
34
  def ids_to_accept
38
- delivered_lines = `git log | egrep '\\[Deliver(s|ed) #'`.split("\n")
35
+ git_log_delivered_story_ids & pivotal_tracker_delivered_story_ids
36
+ end
37
+
38
+ # Returns the ids of delivered stories according to the Git log.
39
+ # These ids are of the form [Delivers #<story id>] or
40
+ # [Delivers #<story id> #<another story id>]. The difference is handled
41
+ # by the delivered_ids method.
42
+ def git_log_delivered_story_ids
43
+ delivered_lines = `git log | egrep '\\[Deliver(s|ed) #'`.split("\n").uniq
39
44
  delivered_lines.inject([]) do |accept, line|
40
- delivered_ids(line).each do |commit_id|
41
- return accept if already_accepted?(commit_id) && !options.all
42
- accept << commit_id
43
- accept.uniq!
44
- end
45
- accept
45
+ accept << delivered_ids(line)
46
+ end.uniq
47
+ end
48
+
49
+ # Returns the ids of delivered stories according to Pivotal Tracker.
50
+ def pivotal_tracker_delivered_story_ids
51
+ data = { 'X-TrackerToken' => api_token,
52
+ 'Content-type' => "application/xml" }
53
+ uri = URI.parse("#{project_uri}/stories?filter=state%3Adelivered")
54
+ response = Net::HTTP.start(uri.host, uri.port) do |http|
55
+ http.get(uri.path, data)
46
56
  end
57
+ Nokogiri::XML(response.body).css('id').map(&:content)
47
58
  end
48
59
 
49
60
  # Returns true if a story has already been accepted.
50
61
  def already_accepted?(story_id)
51
62
  data = { 'X-TrackerToken' => api_token,
52
- 'Content-type' => "application/xml" }
63
+ 'Content-type' => "application/xml" }
53
64
  uri = story_uri(story_id)
54
65
  response = Net::HTTP.start(uri.host, uri.port) do |http|
55
66
  http.get(uri.path, data)
@@ -122,8 +133,11 @@ class StoryAccept < Command
122
133
  'http://www.pivotaltracker.com/services/v3'
123
134
  end
124
135
 
136
+ def project_uri
137
+ URI.parse("#{api_base}/projects/#{project_id}")
138
+ end
139
+
125
140
  def story_uri(story_id)
126
- uri = "#{api_base}/projects/#{project_id}/stories/#{story_id}"
127
- URI.parse(uri)
141
+ URI.parse("#{project_uri}/stories/#{story_id}")
128
142
  end
129
143
  end
@@ -1,5 +1,5 @@
1
1
  module Pivotal
2
2
  module Github
3
- VERSION = "1.1.3"
3
+ VERSION = "1.1.4"
4
4
  end
5
5
  end
@@ -5,7 +5,10 @@ describe StoryAccept do
5
5
  let(:command) { StoryAccept.new(['-o', '-a']) }
6
6
  before do
7
7
  command.stub(:story_branch).and_return('62831853-tau-manifesto')
8
- command.stub(:already_accepted?).and_return(false)
8
+ command.stub(:git_log_delivered_story_ids).
9
+ and_return(%w[51204529 51106181 50566167 50566179 60566178])
10
+ command.stub(:pivotal_tracker_delivered_story_ids).
11
+ and_return(%w[51204529 51106181 50566167 50566178])
9
12
  end
10
13
  subject { command }
11
14
 
@@ -19,6 +22,9 @@ describe StoryAccept do
19
22
  it { should include("51204529") }
20
23
  it { should include("51106181") }
21
24
  it { should include("50566167") }
25
+ it { should_not include("50566178") }
26
+ it { should_not include("50566178") }
27
+ it { should_not include("60566178") }
22
28
 
23
29
  it "should not have duplicate ids" do
24
30
  expect(ids).to eq ids.uniq
@@ -39,18 +45,4 @@ describe StoryAccept do
39
45
  command.run!
40
46
  end
41
47
  end
42
-
43
- describe "when stopping upon reading the first accepted id" do
44
- let(:command) { StoryAccept.new(['-o']) }
45
- before do
46
- command.stub(:story_branch).and_return('62831853-tau-manifesto')
47
- command.stub(:already_accepted?).and_return(false)
48
- command.stub(:already_accepted?).with("50566167").and_return(true)
49
- end
50
- subject { command }
51
-
52
- its(:ids_to_accept) { should include("51204529") }
53
- its(:ids_to_accept) { should include("51106181") }
54
- its(:ids_to_accept) { should_not include("50566167") }
55
- end
56
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pivotal-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Hartl