heroku_deployer 0.7.20 → 0.7.21

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: 283f7123f1226998c26c440aa8e492445abf20a9
4
- data.tar.gz: fc1351fa7c82ede930111417116a7920328b357e
3
+ metadata.gz: 752fb24f5602e61b9b79d088e4af84ab4ce44894
4
+ data.tar.gz: 228deb30594b9686cf969d782e175504aa23788d
5
5
  SHA512:
6
- metadata.gz: afe580321eff5319bc7cfbc90ca08d14a93f9c06a34ac3fedd0f92e5fdde999e8effe78965e6f9eebd1eff17e1f29ee9e17a0c4c5fb411db01258bf0e5f9c836
7
- data.tar.gz: ffae0e8881c910b84c6623901e9508f92d6eace8d57aa10db759611574272bb5210f5fde1c9eeea39496be4381446cd269e930fa9f344675720ce1f332a1a560
6
+ metadata.gz: f3acc34e43638026b0204469bbe73ec96cd3f63e51279c2f6330c9d1a9b6524a1d88a7ebe850b76888a187f71b21de40b1d07b455c650d71077bdc3649d897a8
7
+ data.tar.gz: f84360ef509828550feafe0eedfb6dabb10c63b6c7eadd7ac41e06d9ba47d723f2dd76e214f4bda00a5bbd3163b2e2f7a775bfb386c329ddd8852ab24b545e44
@@ -0,0 +1,7 @@
1
+ module Amitree
2
+ class GitClient
3
+ class NotFoundError < StandardError
4
+ end
5
+ end
6
+ end
7
+
@@ -0,0 +1,38 @@
1
+ module Amitree
2
+ class GitClient
3
+ class EmptyRangeError < StandardError
4
+ end
5
+
6
+ class Range
7
+ attr_reader :commits
8
+
9
+ def initialize commits
10
+ @commits = commits
11
+ end
12
+
13
+ def story_ids
14
+ commit_messages.map do |msg|
15
+ msg.scan(/(?<=\[).*?(?=\])/).map{|expr| expr.scan /(?<=#)\d+/}
16
+ end.flatten.map(&:to_i).uniq
17
+ end
18
+
19
+ def commit_messages
20
+ commits.map(&:commit).map(&:message)
21
+ end
22
+
23
+ def since(rev)
24
+ Range.new(commits[(index(rev)+1)..-1])
25
+ end
26
+
27
+ def up_to(rev)
28
+ Range.new(commits[0..index(rev)])
29
+ end
30
+
31
+ private
32
+
33
+ def index rev
34
+ commits.index{|commit| commit.sha.start_with?(rev)} or raise NotFoundError, "Failed to find #{rev} in range"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,4 +1,6 @@
1
1
  require 'octokit'
2
+ require 'amitree/git_client/range'
3
+ require 'amitree/git_client/not_found_error'
2
4
 
3
5
  module Amitree
4
6
  class GitClient
@@ -15,22 +17,38 @@ module Amitree
15
17
  password: password,
16
18
  middleware: (self.class.verbose_middleware if options[:verbose]),
17
19
  connection_options: Octokit::Default.options[:connection_options].merge(request: {timeout: 60, open_timeout: 60})
20
+ @max_commit_range = options[:max_commit_range] || 1000
18
21
  end
19
22
 
20
- def commits_between(rev1, rev2)
21
- result = @client.compare @repository, rev1, rev2
22
- result.commits
23
- end
23
+ def commits_since(rev)
24
+ result = []
25
+
26
+ @client.commits(@repository, per_page: 100)
27
+ response = @client.last_response
28
+
29
+ loop do
30
+ if response.data.length == 0
31
+ raise "Empty response received from GitHub!"
32
+ end
24
33
 
25
- def commit_messages_between(rev1, rev2)
26
- commits_between(rev1, rev2).map(&:commit).map(&:message)
34
+ result.concat response.data
35
+
36
+ if index = result.index{|commit| commit.sha.start_with?(rev)}
37
+ return result[0...index].reverse
38
+ end
39
+ if result.length >= @max_commit_range
40
+ raise NotFoundError, "Failed to find #{rev} in the most recent #{@max_commit_range} commits. Consider increasing max_commit_range."
41
+ end
42
+ unless page = response.rels[:next]
43
+ raise NotFoundError, "Failed to find #{rev} in entire commit history."
44
+ end
45
+
46
+ response = page.get
47
+ end
27
48
  end
28
49
 
29
- def stories_worked_on_between(rev1, rev2)
30
- messages = commit_messages_between(rev1, rev2)
31
- messages.map do |msg|
32
- msg.scan(/(?<=\[).*?(?=\])/).map{|expr| expr.scan /(?<=#)\d+/}
33
- end.flatten.map(&:to_i).uniq
50
+ def range_since(rev)
51
+ Range.new(commits_since(rev))
34
52
  end
35
53
 
36
54
  def link_to(rev)
@@ -6,7 +6,7 @@ require 'pivotal-tracker'
6
6
  module Amitree
7
7
  class HerokuDeployer
8
8
  class ReleaseDetails
9
- attr_accessor :production_release, :staging_release_to_deploy, :stories
9
+ attr_accessor :production_release, :staging_release_to_deploy, :stories, :git_range
10
10
 
11
11
  def initialize
12
12
  @stories = []
@@ -51,7 +51,8 @@ module Amitree
51
51
  prod_commit = @heroku.get_production_commit(result.production_release)
52
52
  puts "Production release is #{prod_commit}" if options[:verbose]
53
53
 
54
- result.stories = stories_worked_on_between(prod_commit, 'HEAD')
54
+ git_range = @git.range_since(prod_commit)
55
+ result.stories = all_stories(git_range)
55
56
  all_stories = Hash[result.stories.map{|story| [story.id, story]}]
56
57
 
57
58
  staging_releases.reverse.each do |staging_release|
@@ -60,7 +61,8 @@ module Amitree
60
61
 
61
62
  puts "- Trying staging release #{@heroku.version(staging_release)} with commit #{staging_commit}" if options[:verbose]
62
63
 
63
- stories = all_stories.values_at(*@git.stories_worked_on_between(prod_commit, staging_commit)).compact
64
+ candidate_git_range = git_range.up_to(staging_commit)
65
+ stories = all_stories.values_at(*candidate_git_range.story_ids).compact
64
66
  story_ids = stories.map(&:id)
65
67
 
66
68
  puts " - Stories: #{story_ids.inspect}" if options[:verbose]
@@ -75,7 +77,7 @@ module Amitree
75
77
  elsif story_ids.length == 0 && !options[:allow_empty]
76
78
  puts " - Refusing to deploy empty release" if options[:verbose]
77
79
  else
78
- story_ids_referenced_later = story_ids & @git.stories_worked_on_between(staging_commit, 'HEAD')
80
+ story_ids_referenced_later = story_ids & git_range.since(staging_commit).story_ids
79
81
  if story_ids_referenced_later.length > 0
80
82
  puts " - Some stories have been worked on in a later commit: #{story_ids_referenced_later}" if options[:verbose]
81
83
  else
@@ -84,6 +86,7 @@ module Amitree
84
86
  end
85
87
  puts " - This release is good to go!" if options[:verbose]
86
88
  result.staging_release_to_deploy = staging_release
89
+ result.git_range = candidate_git_range
87
90
  break
88
91
  end
89
92
  end
@@ -106,8 +109,8 @@ module Amitree
106
109
  end
107
110
  end
108
111
 
109
- def stories_worked_on_between(rev1, rev2)
110
- @git.stories_worked_on_between(rev1, rev2).map do |story_id|
112
+ def all_stories(git_range)
113
+ git_range.story_ids.map do |story_id|
111
114
  if story = tracker_data(story_id)
112
115
  ReleaseDetails::Story.new(story)
113
116
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_deployer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.20
4
+ version: 0.7.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Wargnier
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-21 00:00:00.000000000 Z
12
+ date: 2017-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: 2.14.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: webmock
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.3.2
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 2.3.2
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: octokit
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +103,8 @@ extensions: []
89
103
  extra_rdoc_files: []
90
104
  files:
91
105
  - lib/amitree/git_client.rb
106
+ - lib/amitree/git_client/not_found_error.rb
107
+ - lib/amitree/git_client/range.rb
92
108
  - lib/amitree/heroku_client.rb
93
109
  - lib/amitree/heroku_deployer.rb
94
110
  - lib/amitree/utils.rb