percy-client 0.3.0 → 0.3.1

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: 0f7070109c5961c00615e57891774502d0f0685e
4
- data.tar.gz: 866f8b2a9a708d1fb4e31411af4a28ce11029ec7
3
+ metadata.gz: 8d2b12edbcf92649f7f63cf396884d852332bb38
4
+ data.tar.gz: 4ebf745962d67e4bc58fa5b636c9d6b6f211aa49
5
5
  SHA512:
6
- metadata.gz: cd466d0a8c561ed6154cff9cce14d32f811ca7df22c1e8fd23b9ca833b9adea79d6e33646752be5357b56f7f4f37e245960cfd40ed5a9fc3bd17f7a87fedaf3d
7
- data.tar.gz: 25fbd1da9b863151e3c36e38ad76582b866d76b4c28d2a889c95eec9ceb20f810006cd97888fcbc954fd26765fec4a4df5ade0ab4d2b1ebc043ae46b0d4ae4b2
6
+ metadata.gz: 3c29f557ff8cadba3b55e721b72fe0cd29493e2f4fc9ce6490d1cbff7ce43e5d8bd81002665923c45adb808ba364b6acb670bdb4e37da0f12c8e21fd0a1d244f
7
+ data.tar.gz: 2a5363ce9f0a34254a6495bb8cb8e219de99057caa1035d885106851ac85cb748847ed32fb4bfce1c5dd38e91e5d2e1312cbf8f26b88d60254f5beab66fb90af
@@ -25,19 +25,29 @@ module Percy
25
25
  # @return [Hash] All commit data from the current commit. Might be empty if commit data could
26
26
  # not be found.
27
27
  def self.commit
28
- output = _raw_commit_output(_commit_sha)
28
+ output = _raw_commit_output(_commit_sha) if _commit_sha
29
29
  output = _raw_commit_output('HEAD') if !output
30
- return {branch: branch} if !output
31
30
 
31
+ # Use the specified SHA or, if not given, the parsed SHA at HEAD.
32
+ commit_sha = _commit_sha || output && output.match(/COMMIT_SHA:(.*)/)[1]
33
+
34
+ # If not running in a git repo, allow nils for certain commit attributes.
35
+ extract_or_nil = lambda { |regex| (output && output.match(regex) || [])[1] }
32
36
  data = {
33
- sha: output.match(/COMMIT_SHA:(.*)/)[1],
37
+ # The only required attribute:
34
38
  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],
39
+ # An optional but important attribute:
40
+ sha: commit_sha,
41
+
42
+ # Optional attributes:
43
+ message: extract_or_nil.call(/COMMIT_MESSAGE:(.*)/m),
44
+ committed_at: extract_or_nil.call(/COMMITTED_DATE:(.*)/),
45
+ # These GIT_ environment vars are from the Jenkins Git Plugin, but could be
46
+ # used generically. This behavior may change in the future.
47
+ author_name: extract_or_nil.call(/AUTHOR_NAME:(.*)/) || ENV['GIT_AUTHOR_NAME'],
48
+ author_email: extract_or_nil.call(/AUTHOR_EMAIL:(.*)/) || ENV['GIT_AUTHOR_EMAIL'],
49
+ committer_name: extract_or_nil.call(/COMMITTER_NAME:(.*)/) || ENV['GIT_COMMITTER_NAME'],
50
+ committer_email: extract_or_nil.call(/COMMITTER_EMAIL:(.*)/) || ENV['GIT_COMMITTER_EMAIL'],
41
51
  }
42
52
  end
43
53
 
@@ -47,15 +57,14 @@ module Percy
47
57
 
48
58
  case current_ci
49
59
  when :jenkins
50
- ENV['ghprbActualCommit']
60
+ # Pull Request Builder Plugin OR Git Plugin.
61
+ ENV['ghprbActualCommit'] || ENV['GIT_COMMIT']
51
62
  when :travis
52
63
  ENV['TRAVIS_COMMIT']
53
64
  when :circle
54
65
  ENV['CIRCLE_SHA1']
55
66
  when :codeship
56
67
  ENV['CI_COMMIT_ID']
57
- else
58
- 'HEAD'
59
68
  end
60
69
  end
61
70
 
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  class Client
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
5
5
  end
@@ -73,8 +73,8 @@ RSpec.describe Percy::Client::Environment do
73
73
  end
74
74
  end
75
75
  describe '#_commit_sha' do
76
- it 'reads from the current local repo' do
77
- expect(Percy::Client::Environment._commit_sha).to eq('HEAD')
76
+ it 'returns nil if no environment info can be found' do
77
+ expect(Percy::Client::Environment._commit_sha).to be_nil
78
78
  end
79
79
  it 'can be overridden with PERCY_COMMIT' do
80
80
  ENV['PERCY_COMMIT'] = 'test-commit'
@@ -277,22 +277,30 @@ RSpec.describe Percy::Client::Environment do
277
277
  describe '#commit' do
278
278
  it 'returns current local commit data' do
279
279
  commit = Percy::Client::Environment.commit
280
+ expect(commit[:branch]).to_not be_empty
281
+ expect(commit[:sha]).to_not be_empty
282
+ expect(commit[:sha].length).to eq(40)
283
+
280
284
  expect(commit[:author_email]).to match(/.+@.+\..+/)
281
285
  expect(commit[:author_name]).to_not be_empty
282
- expect(commit[:branch]).to_not be_empty
283
286
  expect(commit[:committed_at]).to_not be_empty
284
287
  expect(commit[:committer_email]).to_not be_empty
285
288
  expect(commit[:committer_name]).to_not be_empty
286
289
  expect(commit[:message]).to_not be_empty
287
- expect(commit[:sha]).to_not be_empty
288
- expect(commit[:sha].length).to eq(40)
289
290
  end
290
291
  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
+ expect(Percy::Client::Environment).to receive(:_raw_commit_output).once.and_return(nil)
292
293
 
293
294
  commit = Percy::Client::Environment.commit
294
- expect(commit.length).to eq(1)
295
295
  expect(commit[:branch]).to be
296
+ expect(commit[:sha]).to be_nil
297
+
298
+ expect(commit[:author_email]).to be_nil
299
+ expect(commit[:author_name]).to be_nil
300
+ expect(commit[:committed_at]).to be_nil
301
+ expect(commit[:committer_email]).to be_nil
302
+ expect(commit[:committer_name]).to be_nil
303
+ expect(commit[:message]).to be_nil
296
304
  end
297
305
  end
298
306
  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.3.0
4
+ version: 0.3.1
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-08-21 00:00:00.000000000 Z
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  requirements: []
171
171
  rubyforge_project:
172
- rubygems_version: 2.4.5
172
+ rubygems_version: 2.2.2
173
173
  signing_key:
174
174
  specification_version: 4
175
175
  summary: Percy::Client
@@ -190,4 +190,3 @@ 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: