pivotal-github 1.0.6 → 1.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 091af9ded0530e42a30625af563e7dcebfcb97b6
4
- data.tar.gz: caf99d0c43663d578bad073cc546aa16dcbf235a
3
+ metadata.gz: e16466ce0f0728a4075215b06ef480c66e358698
4
+ data.tar.gz: a03a52a01808c51a758e707c8f656b4c1c23459d
5
5
  SHA512:
6
- metadata.gz: 902f24ae87b0b379371a2e2110d87d8bd24573b3305856566419627e17026db3621b2a97958255bb4f31862beb2109a583b6e0930064e014f6fbbed59e76d7a7
7
- data.tar.gz: bd03cd55db1985473f41226dcf59d78f7da727deae4f0e967bce299def4b89301d5a01a686f957068251badd455b0143f716eab0b0cfbe4969f36225cafff7b8
6
+ metadata.gz: 86bf5def499250269ebfab7e37c6183c83791da68cffda22a3a1632fc27ddda4d3295dfa8bd8581fb9daf25d8ce1236d298e077e7d59b8c945eb4b95f9cdc659
7
+ data.tar.gz: 81bed8ce18450aabac4cea63ebd84d1573e24c820ea6867a7ec1788e266ad26115ed099925aaaf2f14a744cc3c618db6acce68288ab95cb4a91f4574ee0e1b19
@@ -0,0 +1,17 @@
1
+ module Story
2
+
3
+ # Returns the URL for the story at Pivotal Tracker.
4
+ def story_url(story_id)
5
+ "https://www.pivotaltracker.com/story/show/#{story_id}"
6
+ end
7
+
8
+ # Returns the ids of delivered stories found in the given text.
9
+ def delivered_ids(text)
10
+ delivered = text.scan(/\[Deliver(?:s|ed) (.*?)\]/).flatten
11
+ # Handle multiple ids, i.e., '[Delivers #<id 1> #<id 2>]'
12
+ delivered.inject([]) do |ids, element|
13
+ ids.concat(element.scan(/[0-9]{8,}/).flatten)
14
+ ids
15
+ end
16
+ end
17
+ end
@@ -3,8 +3,10 @@ require 'git'
3
3
  require 'net/http'
4
4
  require 'uri'
5
5
  require 'nokogiri'
6
+ require 'pivotal-github/story'
6
7
 
7
8
  class StoryAccept < Command
9
+ include Story
8
10
 
9
11
  def parser
10
12
  OptionParser.new do |opts|
@@ -34,21 +36,14 @@ class StoryAccept < Command
34
36
  # These ids are of the form [Delivers #<story id>] or
35
37
  # [Delivers #<story id> #<another story id>].
36
38
  def ids_to_accept
37
- delivered_regex = /\[Deliver(?:s|ed) (.*?)\]/
38
39
  n_commits = `git rev-list HEAD --count`
39
- Git.open('.').log(n_commits).inject([]) do |delivered_ids, commit|
40
- message = commit.message
41
- delivered = message.scan(delivered_regex).flatten
42
- commit_ids = delivered.inject([]) do |ids, element|
43
- ids.concat(element.scan(/[0-9]{8,}/).flatten)
44
- ids
40
+ Git.open('.').log(n_commits).inject([]) do |accept, commit|
41
+ delivered_ids(commit.message).each do |commit_id|
42
+ return accept if already_accepted?(commit_id) && !options.all
43
+ accept << commit_id
44
+ accept.uniq!
45
45
  end
46
- commit_ids.each do |commit_id|
47
- return delivered_ids if already_accepted?(commit_id) && !options['all']
48
- delivered_ids << commit_id
49
- delivered_ids.uniq!
50
- end
51
- delivered_ids
46
+ accept
52
47
  end
53
48
  end
54
49
 
@@ -1,13 +1,13 @@
1
1
  require 'pivotal-github/command'
2
+ require 'pivotal-github/story'
2
3
 
3
4
  class StoryOpen < Command
5
+ include Story
4
6
 
5
7
  # Returns a command appropriate for executing at the command line
6
8
  # I.e., 'open https://www.pivotaltracker.com/story/show/62831853'
7
9
  def cmd
8
- story_ids.map do |id|
9
- "open https://www.pivotaltracker.com/story/show/#{id}"
10
- end.join(' ; ')
10
+ story_ids.map { |id| "open #{story_url(id)}" }.join(' ; ')
11
11
  end
12
12
 
13
13
  def run!
@@ -1,11 +1,16 @@
1
1
  require 'pivotal-github/command'
2
2
  require 'pivotal-github/finished_command'
3
+ require 'pivotal-github/story'
3
4
 
4
5
  class StoryPullRequest < FinishedCommand
6
+ include Story
5
7
 
6
8
  def parser
7
9
  OptionParser.new do |opts|
8
10
  opts.banner = "Usage: git story-pull-request [options]"
11
+ opts.on("-b", "--base-branch", "base branch for delivered ids") do |opt|
12
+ self.options.base_branch = opt
13
+ end
9
14
  opts.on("-o", "--override", "override unfinished story warning") do |opt|
10
15
  self.options.override = opt
11
16
  end
@@ -15,28 +20,30 @@ class StoryPullRequest < FinishedCommand
15
20
  end
16
21
  end
17
22
 
18
- # Returns a command appropriate for executing at the command line
19
- # I.e., 'open https://www.pivotaltracker.com/story/show/62831853'
20
- def cmd
21
- "git pull-request"
23
+ # Returns the (Markdown) link for a delivered story id.
24
+ def delivers_url(id)
25
+ "[Delivers ##{id}](#{story_url(id)})"
22
26
  end
23
27
 
24
- def uri
25
- "#{origin_uri}/pull/new/#{story_branch}"
28
+ # Returns a commit message with links to all the delivered stories.
29
+ def commit_message
30
+ ids = delivered_ids(`git log #{base_branch}..HEAD`)
31
+ ids.map { |id| delivers_url(id) }.join("\n")
26
32
  end
27
33
 
28
- private
34
+ # Returns a command appropriate for executing at the command line
35
+ def cmd
36
+ Dir.mkdir '.pull_requests' unless File.directory?('.pull_requests')
37
+ c = ["touch .pull_requests/`date '+%s'`"]
38
+ c << "git add ."
39
+ c << %(git commit -m "Pull request" -m "#{commit_message}")
40
+ c << "git pull-request"
41
+ c.join("\n")
42
+ end
29
43
 
30
- # Returns the raw remote location for the repository.
31
- # E.g., http://github.com/mhartl/pivotal-github or
32
- # git@github.com:mhartl/pivotal-github
33
- def remote_location
34
- `git config --get remote.origin.url`.strip.chomp('.git')
35
- end
44
+ private
36
45
 
37
- # Returns the remote URI for the repository.
38
- # Both https://... and git@... remote formats are supported.
39
- def origin_uri
40
- remote_location.sub(/^git@(.+?):(.+)$/, 'https://\1/\2')
46
+ def base_branch
47
+ options.base_branch || 'master'
41
48
  end
42
49
  end
@@ -1,5 +1,5 @@
1
1
  module Pivotal
2
2
  module Github
3
- VERSION = "1.0.6"
3
+ VERSION = "1.0.7"
4
4
  end
5
5
  end
@@ -7,27 +7,15 @@ describe StoryPullRequest do
7
7
  before do
8
8
  command.stub(:remote_location).
9
9
  and_return('https://github.com/mhartl/foo')
10
+ command.stub(:delivered_ids).and_return(['62831853', '31415926'])
11
+ command.stub(:write_pr_file).and_return('')
10
12
  end
11
13
  subject { command }
12
14
 
13
15
  its(:cmd) { should match /git pull-request/ }
14
-
15
- describe 'origin uri parsing' do
16
- let(:correct_origin) { 'https://github.com/mhartl/foo' }
17
- subject { command.send :origin_uri }
18
-
19
- context 'https protocol' do
20
- it { should eq correct_origin }
21
- end
22
-
23
- context 'git protocol' do
24
- before do
25
- command.stub(:remote_location).
26
- and_return('git@github.com:mhartl/foo')
27
- end
28
-
29
- it { should eq correct_origin }
30
- end
16
+ its(:commit_message) do
17
+ should include '[Delivers #62831853]'
18
+ should include '[Delivers #31415926]'
31
19
  end
32
20
 
33
21
  describe "command-line command" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pivotal-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Hartl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-19 00:00:00.000000000 Z
11
+ date: 2013-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git-utils
@@ -54,6 +54,7 @@ files:
54
54
  - lib/pivotal-github/command.rb
55
55
  - lib/pivotal-github/finished_command.rb
56
56
  - lib/pivotal-github/options.rb
57
+ - lib/pivotal-github/story.rb
57
58
  - lib/pivotal-github/story_accept.rb
58
59
  - lib/pivotal-github/story_commit.rb
59
60
  - lib/pivotal-github/story_merge.rb