percy-client 0.2.11 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7efbfa1d29e3d37db3b6fc4b1e4672cd84404598
4
- data.tar.gz: 4b01197b60bbda28b5d8b63b0cc5eece4d122e27
3
+ metadata.gz: 0f7070109c5961c00615e57891774502d0f0685e
4
+ data.tar.gz: 866f8b2a9a708d1fb4e31411af4a28ce11029ec7
5
5
  SHA512:
6
- metadata.gz: 10426465a40a9af7af1362f100319dfbf067ecebbddd3024936063e2192f48d551fe6a0d5dfdc3823ad9c9234e498bb77b7e6b3b533704f200ed4696320110a5
7
- data.tar.gz: 4a07806286f6350d0845e21bad7771203344f8ea03e0b96781224199dbb50c6513825d2c0080e6baaca67d155ca0ecb02d6feab7678b94fac9d6aba8831b18ad
6
+ metadata.gz: cd466d0a8c561ed6154cff9cce14d32f811ca7df22c1e8fd23b9ca833b9adea79d6e33646752be5357b56f7f4f37e245960cfd40ed5a9fc3bd17f7a87fedaf3d
7
+ data.tar.gz: 25fbd1da9b863151e3c36e38ad76582b866d76b4c28d2a889c95eec9ceb20f810006cd97888fcbc954fd26765fec4a4df5ade0ab4d2b1ebc043ae46b0d4ae4b2
@@ -11,8 +11,8 @@ module Percy
11
11
  'data' => {
12
12
  'type' => 'builds',
13
13
  'attributes' => {
14
+ 'branch' => commit_data[:branch],
14
15
  'commit-sha' => commit_data[:sha],
15
- 'commit-branch' => commit_data[:branch],
16
16
  'commit-committed-at' => commit_data[:committed_at],
17
17
  'commit-author-name' => commit_data[:author_name],
18
18
  'commit-author-email' => commit_data[:author_email],
@@ -14,7 +14,6 @@ module Percy
14
14
 
15
15
  class Error < Exception; end
16
16
  class RepoNotFoundError < Exception; end
17
- class BranchNotFoundError < Exception; end
18
17
 
19
18
  def self.current_ci
20
19
  return :travis if ENV['TRAVIS_BUILD_ID']
@@ -23,7 +22,27 @@ module Percy
23
22
  return :codeship if ENV['CI_NAME'] && ENV['CI_NAME'] == 'codeship'
24
23
  end
25
24
 
26
- def self.commit_sha
25
+ # @return [Hash] All commit data from the current commit. Might be empty if commit data could
26
+ # not be found.
27
+ def self.commit
28
+ output = _raw_commit_output(_commit_sha)
29
+ output = _raw_commit_output('HEAD') if !output
30
+ return {branch: branch} if !output
31
+
32
+ data = {
33
+ sha: output.match(/COMMIT_SHA:(.*)/)[1],
34
+ branch: branch,
35
+ committed_at: output.match(/COMMITTED_DATE:(.*)/)[1],
36
+ author_name: output.match(/AUTHOR_NAME:(.*)/)[1],
37
+ author_email: output.match(/AUTHOR_EMAIL:(.*)/)[1],
38
+ committer_name: output.match(/COMMITTER_NAME:(.*)/)[1],
39
+ committer_email: output.match(/COMMITTER_EMAIL:(.*)/)[1],
40
+ message: output.match(/COMMIT_MESSAGE:(.*)/m)[1],
41
+ }
42
+ end
43
+
44
+ # @private
45
+ def self._commit_sha
27
46
  return ENV['PERCY_COMMIT'] if ENV['PERCY_COMMIT']
28
47
 
29
48
  case current_ci
@@ -40,19 +59,12 @@ module Percy
40
59
  end
41
60
  end
42
61
 
43
- def self.commit
62
+ # @private
63
+ def self._raw_commit_output(commit_sha)
44
64
  format = GIT_FORMAT_LINES.join('%n') # "git show" format uses %n for newlines.
45
- output = `git show --quiet #{commit_sha} --format="#{format}"`.strip
46
- data = {
47
- sha: output.match(/COMMIT_SHA:(.*)/)[1],
48
- branch: branch,
49
- committed_at: output.match(/COMMITTED_DATE:(.*)/)[1],
50
- author_name: output.match(/AUTHOR_NAME:(.*)/)[1],
51
- author_email: output.match(/AUTHOR_EMAIL:(.*)/)[1],
52
- committer_name: output.match(/COMMITTER_NAME:(.*)/)[1],
53
- committer_email: output.match(/COMMITTER_EMAIL:(.*)/)[1],
54
- message: output.match(/COMMIT_MESSAGE:(.*)/m)[1],
55
- }
65
+ output = `git show --quiet #{commit_sha} --format="#{format}" 2> /dev/null`.strip
66
+ return if $?.to_i != 0
67
+ output
56
68
  end
57
69
 
58
70
  # The name of the target branch that the build will be compared against.
@@ -69,15 +81,22 @@ module Percy
69
81
  when :codeship
70
82
  ENV['CI_BRANCH']
71
83
  else
72
- # Discover from current git repo branch name.
73
- `git rev-parse --abbrev-ref HEAD`.strip
84
+ _raw_branch_output
74
85
  end
75
86
  if result == ''
76
- raise Percy::Client::Environment::BranchNotFoundError.new('No target branch found.')
87
+ STDERR.puts '[percy] Warning: not in a git repo, setting PERCY_BRANCH to "master".'
88
+ result = 'master'
77
89
  end
78
90
  result
79
91
  end
80
92
 
93
+ # @private
94
+ def self._raw_branch_output
95
+ # Discover from local git repo branch name.
96
+ `git rev-parse --abbrev-ref HEAD 2> /dev/null`.strip
97
+ end
98
+ class << self; private :_raw_branch_output; end
99
+
81
100
  def self.repo
82
101
  return ENV['PERCY_REPO_SLUG'] if ENV['PERCY_REPO_SLUG']
83
102
 
@@ -89,13 +108,15 @@ module Percy
89
108
  else
90
109
  origin_url = _get_origin_url.strip
91
110
  if origin_url == ''
92
- raise Percy::Client::Environment::RepoNotFoundError.new('No local git repository found.')
111
+ raise Percy::Client::Environment::RepoNotFoundError.new(
112
+ 'No local git repository found. ' +
113
+ 'You can manually set PERCY_REPO_SLUG to fix this.')
93
114
  end
94
115
  match = origin_url.match(Regexp.new('[:/]([^/]+\/[^/]+?)(\.git)?\Z'))
95
116
  if !match
96
117
  raise Percy::Client::Environment::RepoNotFoundError.new(
97
118
  "Could not determine repository name from URL: #{origin_url.inspect}\n" +
98
- "You can manually set PERCY_REPO to fix this.")
119
+ "You can manually set PERCY_REPO_SLUG to fix this.")
99
120
  end
100
121
  match[1]
101
122
  end
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  class Client
3
- VERSION = '0.2.11'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -60,6 +60,10 @@ RSpec.describe Percy::Client::Environment do
60
60
  end
61
61
  end
62
62
  describe '#branch' do
63
+ it 'returns master if not in a git repo' do
64
+ expect(Percy::Client::Environment).to receive(:_raw_branch_output).and_return('')
65
+ expect(Percy::Client::Environment.branch).to eq('master')
66
+ end
63
67
  it 'reads from the current local repo' do
64
68
  expect(Percy::Client::Environment.branch).to_not be_empty
65
69
  end
@@ -68,13 +72,13 @@ RSpec.describe Percy::Client::Environment do
68
72
  expect(Percy::Client::Environment.branch).to eq('test-branch')
69
73
  end
70
74
  end
71
- describe '#commit_sha' do
75
+ describe '#_commit_sha' do
72
76
  it 'reads from the current local repo' do
73
- expect(Percy::Client::Environment.commit_sha).to eq('HEAD')
77
+ expect(Percy::Client::Environment._commit_sha).to eq('HEAD')
74
78
  end
75
79
  it 'can be overridden with PERCY_COMMIT' do
76
80
  ENV['PERCY_COMMIT'] = 'test-commit'
77
- expect(Percy::Client::Environment.commit_sha).to eq('test-commit')
81
+ expect(Percy::Client::Environment._commit_sha).to eq('test-commit')
78
82
  end
79
83
  end
80
84
  describe '#pull_request_number' do
@@ -147,9 +151,9 @@ RSpec.describe Percy::Client::Environment do
147
151
  expect(Percy::Client::Environment.branch).to eq('jenkins-target-branch')
148
152
  end
149
153
  end
150
- describe '#commit_sha' do
154
+ describe '#_commit_sha' do
151
155
  it 'reads from the CI environment' do
152
- expect(Percy::Client::Environment.commit_sha).to eq('jenkins-actual-commit')
156
+ expect(Percy::Client::Environment._commit_sha).to eq('jenkins-actual-commit')
153
157
  end
154
158
  end
155
159
  describe '#pull_request_number' do
@@ -182,9 +186,9 @@ RSpec.describe Percy::Client::Environment do
182
186
  expect(Percy::Client::Environment.branch).to eq('travis-branch')
183
187
  end
184
188
  end
185
- describe '#commit_sha' do
189
+ describe '#_commit_sha' do
186
190
  it 'reads from the CI environment' do
187
- expect(Percy::Client::Environment.commit_sha).to eq('travis-commit-sha')
191
+ expect(Percy::Client::Environment._commit_sha).to eq('travis-commit-sha')
188
192
  end
189
193
  end
190
194
  describe '#pull_request_number' do
@@ -218,9 +222,9 @@ RSpec.describe Percy::Client::Environment do
218
222
  expect(Percy::Client::Environment.branch).to eq('circle-branch')
219
223
  end
220
224
  end
221
- describe '#commit_sha' do
225
+ describe '#_commit_sha' do
222
226
  it 'reads from the CI environment' do
223
- expect(Percy::Client::Environment.commit_sha).to eq('circle-commit-sha')
227
+ expect(Percy::Client::Environment._commit_sha).to eq('circle-commit-sha')
224
228
  end
225
229
  end
226
230
 
@@ -253,9 +257,9 @@ RSpec.describe Percy::Client::Environment do
253
257
  expect(Percy::Client::Environment.branch).to eq('codeship-branch')
254
258
  end
255
259
  end
256
- describe '#commit_sha' do
260
+ describe '#_commit_sha' do
257
261
  it 'reads from the CI environment' do
258
- expect(Percy::Client::Environment.commit_sha).to eq('codeship-commit-sha')
262
+ expect(Percy::Client::Environment._commit_sha).to eq('codeship-commit-sha')
259
263
  end
260
264
  end
261
265
  describe '#pull_request_number' do
@@ -283,6 +287,13 @@ RSpec.describe Percy::Client::Environment do
283
287
  expect(commit[:sha]).to_not be_empty
284
288
  expect(commit[:sha].length).to eq(40)
285
289
  end
290
+ it 'returns only branch if commit data cannot be found' do
291
+ expect(Percy::Client::Environment).to receive(:_raw_commit_output).twice.and_return(nil)
292
+
293
+ commit = Percy::Client::Environment.commit
294
+ expect(commit.length).to eq(1)
295
+ expect(commit[:branch]).to be
296
+ end
286
297
  end
287
298
  end
288
299
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percy-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Perceptual Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-24 00:00:00.000000000 Z
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -190,3 +190,4 @@ test_files:
190
190
  - spec/lib/percy_spec.rb
191
191
  - spec/spec_helper.rb
192
192
  - spec/support/vcr_setup.rb
193
+ has_rdoc: