percy-client 1.13.7 → 1.13.8

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: 679ab5cb622bcd8363fbc9145dce6e533cc5d887
4
- data.tar.gz: 2847774e6745adc368a9cd5c2519190057290f4f
3
+ metadata.gz: bf2ad29ea7519dca29107bb4730ce63b01209658
4
+ data.tar.gz: d0537050170ed7da2ae408d8e587b8e2a8b4de0c
5
5
  SHA512:
6
- metadata.gz: 1aec137240ec78d0f293fde22542553c312a0d3a4955abd846d9c30d4d585ec77c794b63df2b8e96046187441d249adc879db920bc2937a7b4e71babafe6225b
7
- data.tar.gz: ed66d35eb25c182def63139abe20929fcfe541aa5dda061519a09e7c3aec7397f14f5e5e2f1e7f0d8074cc7b137732742db3a0ce3c05c57d55498239659d3a2c
6
+ metadata.gz: cb995b91309f0289a1e823fa2ce9268a7d25649043085a3e71c6fd8c23fcd78461e73b101d4d1b0bcc465aa31037791f0b9d0d920aada58de6565d6bfe885599
7
+ data.tar.gz: 61aca7740b14dc0f72a19cd62649e89358e65cc6fce77e4bc3d8b541d25b2d9a15e75cb318c03a1954eb175e9f9afe5be404675168addc339148380659413395
@@ -29,16 +29,14 @@ module Percy
29
29
  # @return [Hash] All commit data from the current commit. Might be empty if commit data could
30
30
  # not be found.
31
31
  def self.commit
32
- output = _raw_commit_output(_commit_sha) if _commit_sha
33
- output ||= _raw_commit_output('HEAD')
34
- return {branch: branch} unless output && output != ''
35
- output = output.force_encoding('UTF-8') if output && output.encoding.to_s == 'US-ASCII'
32
+ # Try getting data from git itself.
33
+ # If this has a result, it means git is present in the system.
34
+ git_data_from_git = _git_commit_output
36
35
 
37
- # Use the specified SHA or, if not given, the parsed SHA at HEAD.
38
- commit_sha = _commit_sha || (output && output.match(/COMMIT_SHA:(.*)/) || [])[1]
36
+ parse = ->(regex) { (git_data_from_git && git_data_from_git.match(regex) || [])[1] }
37
+
38
+ commit_sha = _commit_sha || parse.call(/COMMIT_SHA:(.*)/)
39
39
 
40
- # If not running in a git repo, allow nils for certain commit attributes.
41
- parse = ->(regex) { (output && output.match(regex) || [])[1] }
42
40
  {
43
41
  # The only required attribute:
44
42
  branch: branch,
@@ -46,10 +44,11 @@ module Percy
46
44
  sha: commit_sha,
47
45
 
48
46
  # Optional attributes:
49
- message: parse.call(/COMMIT_MESSAGE:(.*)/m),
50
- committed_at: parse.call(/COMMITTED_DATE:(.*)/),
51
- # These GIT_ environment vars are from the Jenkins Git Plugin, but could be
47
+ # If we have the git information, read from those rather than env vars.
48
+ # The GIT_ environment vars are from the Jenkins Git Plugin, but could be
52
49
  # used generically. This behavior may change in the future.
50
+ message: parse.call(/COMMIT_MESSAGE:(.*)/),
51
+ committed_at: parse.call(/COMMITTED_DATE:(.*)/),
53
52
  author_name: parse.call(/AUTHOR_NAME:(.*)/) || ENV['GIT_AUTHOR_NAME'],
54
53
  author_email: parse.call(/AUTHOR_EMAIL:(.*)/) || ENV['GIT_AUTHOR_EMAIL'],
55
54
  committer_name: parse.call(/COMMITTER_NAME:(.*)/) || ENV['GIT_COMMITTER_NAME'],
@@ -57,6 +56,16 @@ module Percy
57
56
  }
58
57
  end
59
58
 
59
+ # @private
60
+ def self._git_commit_output
61
+ raw_git_output = _raw_commit_output(_commit_sha) if _commit_sha
62
+ raw_git_output ||= _raw_commit_output('HEAD')
63
+ if raw_git_output && raw_git_output.encoding.to_s == 'US-ASCII'
64
+ raw_git_output = raw_git_output.force_encoding('UTF-8')
65
+ end
66
+ raw_git_output
67
+ end
68
+
60
69
  # @private
61
70
  def self._commit_sha
62
71
  return ENV['PERCY_COMMIT'] if ENV['PERCY_COMMIT']
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  class Client
3
- VERSION = '1.13.7'.freeze
3
+ VERSION = '1.13.8'.freeze
4
4
  end
5
5
  end
@@ -503,25 +503,39 @@ RSpec.describe Percy::Client::Environment do
503
503
  describe 'local git repo methods' do
504
504
  describe '#commit' do
505
505
  it 'returns current local commit data' do
506
+ raw_git_output = "COMMIT_SHA:sweetsha\n" \
507
+ "AUTHOR_NAME:LC\n" \
508
+ "AUTHOR_EMAIL:foobar@gmail.com\n" \
509
+ "COMMITTER_NAME:LC\n" \
510
+ "COMMITTER_EMAIL:foobar@gmail.com\n" \
511
+ "COMMITTED_DATE:444-44-44 44:44:44 -0700\n" \
512
+ 'COMMIT_MESSAGE:wow how cool is this commit'
513
+ expect(Percy::Client::Environment).to receive(:_git_commit_output).once.and_return(
514
+ raw_git_output,
515
+ )
516
+
506
517
  commit = Percy::Client::Environment.commit
518
+
507
519
  expect(commit[:branch]).to_not be_empty
508
- expect(commit[:sha]).to_not be_empty
509
- expect(commit[:sha].length).to eq(40)
520
+ expect(commit[:sha]).to eq('sweetsha')
510
521
 
511
- expect(commit[:author_email]).to match(/.+@.+\..+/)
512
- expect(commit[:author_name]).to_not be_empty
513
- expect(commit[:committed_at]).to_not be_empty
514
- expect(commit[:committer_email]).to_not be_empty
515
- expect(commit[:committer_name]).to_not be_empty
516
- expect(commit[:message]).to_not be_empty
522
+ expect(commit[:author_email]).to eq('foobar@gmail.com')
523
+ expect(commit[:author_name]).to eq('LC')
524
+ expect(commit[:committed_at]).to eq('444-44-44 44:44:44 -0700')
525
+ expect(commit[:committer_email]).to eq('foobar@gmail.com')
526
+ expect(commit[:committer_name]).to eq('LC')
527
+ expect(commit[:message]).to eq('wow how cool is this commit')
517
528
  end
518
529
 
519
- it 'returns only branch if commit data cannot be found' do
520
- expect(Percy::Client::Environment).to receive(:_raw_commit_output).once.and_return(nil)
530
+ it 'returns data from environment if commit data cannot be found' do
531
+ ENV['PERCY_BRANCH'] = 'the-coolest-branch'
532
+ ENV['PERCY_COMMIT'] = 'agreatsha'
533
+
534
+ expect(Percy::Client::Environment).to receive(:_git_commit_output).once.and_return(nil)
521
535
 
522
536
  commit = Percy::Client::Environment.commit
523
- expect(commit[:branch]).to be
524
- expect(commit[:sha]).to be_nil
537
+ expect(commit[:branch]).to eq('the-coolest-branch')
538
+ expect(commit[:sha]).to eq('agreatsha')
525
539
 
526
540
  expect(commit[:author_email]).to be_nil
527
541
  expect(commit[:author_name]).to be_nil
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: 1.13.7
4
+ version: 1.13.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Perceptual Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-05 00:00:00.000000000 Z
11
+ date: 2018-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday