percy-client 0.1.2 → 0.1.3

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: ac390ac562cecfd4bf1d32a46d95e9ec544f7eb3
4
- data.tar.gz: 14920f3b71e0038f51dd6bb10c30af279e5631e6
3
+ metadata.gz: bdab0f8284a32f328fb7dc4741ca66373dbf05ae
4
+ data.tar.gz: 1d43a124e5727b0fe60d20b51a7bc370af2d5b3e
5
5
  SHA512:
6
- metadata.gz: a4c7491bfa30fff592390a09c0d83dc23e621ab523fe71ef82b7b173dd7d4118b59e9aea942b8eb59aaedf45298f84516e13fb2355ce8d197a9d01856696426f
7
- data.tar.gz: 23ab3e161e502438af1ae6bc4f4661c7fca4e46b6b060d0bf1c2b57d5481d5d0fb415237d8e59f7be05c9db52831d1d93ac9107af1f533ba38f22921088454f7
6
+ metadata.gz: 39677cbd0273d1f524160396a5a422146c2277a906a85c4ec7d41922c12b64df450a3dc02c85f40b9612e6fce96ad54161522ab125654461d5659b4e2e025bec
7
+ data.tar.gz: 6368f16f4aade526c1389aa1da24a800c35cef56607cee402d9e61ea398fc1de5c5f41a0c4f0c7bcf2aac9fbdb6a7a678530f6981aa386cb9e0ce93c785ee44d
data/lib/percy/client.rb CHANGED
@@ -10,7 +10,6 @@ require 'percy/client/resources'
10
10
  module Percy
11
11
  class Client
12
12
  include Percy::Client::Connection
13
- include Percy::Client::LocalGit
14
13
  include Percy::Client::Builds
15
14
  include Percy::Client::Snapshots
16
15
  include Percy::Client::Resources
@@ -1,25 +1,25 @@
1
1
  module Percy
2
2
  class Client
3
3
  module Builds
4
- def create_build(repo_slug)
5
- commit = Percy.current_local_commit
4
+ def create_build(repo, options = {})
5
+ commit_data = options[:commit_data] || Percy::Client::LocalGit.commit
6
6
  data = {
7
7
  'data' => {
8
8
  'type' => 'builds',
9
9
  'attributes' => {
10
- 'commit-sha' => commit[:sha],
11
- 'commit-branch' => commit[:branch],
12
- 'commit-committed-at' => commit[:committed_at],
13
- 'commit-author-name' => commit[:author_name],
14
- 'commit-author-email' => commit[:author_email],
15
- 'commit-committer-name' => commit[:committer_name],
16
- 'commit-committer-email' => commit[:committer_email],
17
- 'commit-message' => commit[:message],
10
+ 'commit-sha' => commit_data[:sha],
11
+ 'commit-branch' => commit_data[:branch],
12
+ 'commit-committed-at' => commit_data[:committed_at],
13
+ 'commit-author-name' => commit_data[:author_name],
14
+ 'commit-author-email' => commit_data[:author_email],
15
+ 'commit-committer-name' => commit_data[:committer_name],
16
+ 'commit-committer-email' => commit_data[:committer_email],
17
+ 'commit-message' => commit_data[:message],
18
18
  'pull-request-number' => nil,
19
19
  },
20
20
  }
21
21
  }
22
- post("#{config.api_url}/repos/#{repo_slug}/builds/", data)
22
+ post("#{config.api_url}/repos/#{repo}/builds/", data)
23
23
  end
24
24
 
25
25
  def finalize_build(build_id)
@@ -3,12 +3,11 @@ module Percy
3
3
  module LocalGit
4
4
  GIT_FORMAT_LINES = [
5
5
  'COMMIT_SHA:%H',
6
- 'AUTHOR_DATE:%ai',
7
6
  'AUTHOR_NAME:%an',
8
7
  'AUTHOR_EMAIL:%ae',
9
8
  'COMMITTER_NAME:%an',
10
9
  'COMMITTER_EMAIL:%ae',
11
- 'COMMITTER_DATE:%ai',
10
+ 'COMMITTED_DATE:%ai',
12
11
  # Note: order is important, this must come last because the regex is a multiline match.
13
12
  'COMMIT_MESSAGE:%B'
14
13
  ].freeze
@@ -16,7 +15,7 @@ module Percy
16
15
  class Error < Exception; end
17
16
  class NoLocalRepo < Exception; end
18
17
 
19
- def current_local_commit
18
+ def self.commit
20
19
  commit = ENV['PERCY_COMMIT'] || 'HEAD'
21
20
  branch = ENV['PERCY_BRANCH'] || `git rev-parse --abbrev-ref HEAD`.strip
22
21
  if branch == ''
@@ -28,7 +27,7 @@ module Percy
28
27
  data = {
29
28
  sha: output.match(/COMMIT_SHA:(.*)/)[1],
30
29
  branch: branch,
31
- committed_at: output.match(/AUTHOR_DATE:(.*)/)[1],
30
+ committed_at: output.match(/COMMITTED_DATE:(.*)/)[1],
32
31
  author_name: output.match(/AUTHOR_NAME:(.*)/)[1],
33
32
  author_email: output.match(/AUTHOR_EMAIL:(.*)/)[1],
34
33
  committer_name: output.match(/COMMITTER_NAME:(.*)/)[1],
@@ -37,7 +36,7 @@ module Percy
37
36
  }
38
37
  end
39
38
 
40
- def current_local_repo
39
+ def self.repo
41
40
  origin_url = `git config --get remote.origin.url`
42
41
  if origin_url == ''
43
42
  raise Percy::Client::LocalGit::NoLocalRepo.new('No local git repository found.')
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  class Client
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
data/lib/percy/config.rb CHANGED
@@ -7,6 +7,7 @@ module Percy
7
7
 
8
8
  attr_accessor :access_token
9
9
  attr_accessor :api_url
10
+ attr_accessor :repo
10
11
 
11
12
  # List of configurable keys for {Percy::Client}
12
13
  # @return [Array] Option keys.
@@ -14,6 +15,7 @@ module Percy
14
15
  @keys ||= [
15
16
  :access_token,
16
17
  :api_url,
18
+ :repo,
17
19
  ]
18
20
  end
19
21
 
@@ -24,5 +26,9 @@ module Percy
24
26
  def api_url
25
27
  @api_url ||= ENV['PERCY_API'] || 'https://percy.io/api/v1'
26
28
  end
29
+
30
+ def repo
31
+ @repo ||= ENV['PERCY_REPO'] || Percy::Client::LocalGit.repo
32
+ end
27
33
  end
28
34
  end
@@ -1,12 +1,12 @@
1
1
  RSpec.describe Percy::Client::LocalGit do
2
- describe '#current_local_repo' do
2
+ describe '#repo' do
3
3
  it 'returns the current local repo name' do
4
- expect(Percy.current_local_repo).to eq('percy/percy-client')
4
+ expect(Percy::Client::LocalGit.repo).to eq('percy/percy-client')
5
5
  end
6
6
  end
7
- describe '#current_local_commit' do
7
+ describe '#commit' do
8
8
  it 'returns current local commit data' do
9
- commit = Percy.current_local_commit
9
+ commit = Percy::Client::LocalGit.commit
10
10
  expect(commit[:author_email]).to match(/.+@.+\..+/)
11
11
  expect(commit[:author_name]).to_not be_empty
12
12
  expect(commit[:branch]).to_not be_empty
@@ -4,6 +4,14 @@ RSpec.describe Percy::Client do
4
4
  config = Percy::Config.new
5
5
  client = Percy::Client.new(config: config)
6
6
  expect(client.config).to eq(config)
7
+ expect(client.config.keys).to eq([
8
+ :access_token,
9
+ :api_url,
10
+ :repo,
11
+ ])
12
+ expect(client.config.access_token).to be_nil
13
+ expect(client.config.api_url).to eq(ENV['PERCY_API'])
14
+ expect(client.config.repo).to eq('percy/percy-client')
7
15
  end
8
16
  end
9
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percy-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Perceptual Inc.