percy-client 2.1.1 → 2.1.2

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
  SHA256:
3
- metadata.gz: e2751056507e27c44bfc5b7552d7e261b1cbe3c77b4df44d7f98b23cc1945792
4
- data.tar.gz: b485db38b5214a4491875eb9bfa89b8256a75849a5dce5a7cf617f3854cd80d5
3
+ metadata.gz: 51671bb32d58324c42e9413522bb0cb0cbb3ee7a899d3251539264af0faa4a8e
4
+ data.tar.gz: d7f5fd90414a6b7eb5b9a204afa7ba7bc9c2aacfc4e7ceca42a121b0cac8cf53
5
5
  SHA512:
6
- metadata.gz: c66d7d596eee4b05f0e20962106aacb8cd30f26f81aca3de2e0f4d059fb1ecff591e7877dbcf386b804d66c780c3416a917d18297dbe5229a196fefe4fdc47ae
7
- data.tar.gz: d5e9233876eea097e30206c308948aa6b690f2974151c6c626af44d37b989c725d3415c1fc922b8a68f6987cc6a7ec7b64a11558fba6bbd5d4d6853cbe4a6fe3
6
+ metadata.gz: be64d48d3af30e8c8b875fa8519f3549669473b68f10c2fd41432c77ba7c5e6060760ea9d3e9b014455dcd70be795e29c549c68237e3170d40c2462d861c312d
7
+ data.tar.gz: f0bf7067aef7e4f8fc8ccdc4ebbd221c40a413c4393402c7df70fe09c426674e51421a64ebe450cb8c4934193e649058094e1ebbcac4f10fc806aca82d7274da
@@ -2,8 +2,7 @@
2
2
  name: Semgrep
3
3
 
4
4
  on:
5
- # Scan changed files in PRs (diff-aware scanning):
6
- # The branches below must be a subset of the branches above
5
+ # Scan changed files in PRs (diff-aware scanning).
7
6
  pull_request:
8
7
  branches: ["master", "main"]
9
8
  push:
@@ -21,28 +20,35 @@ jobs:
21
20
  permissions:
22
21
  contents: read # for actions/checkout to fetch code
23
22
  security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
24
- name: semgrep/ci
25
- # If you are self-hosting, change the following `runs-on` value:
23
+ name: semgrep/ci
24
+ # If you are self-hosting, change the following `runs-on` value:
26
25
  runs-on: ubuntu-latest
27
26
 
28
27
  container:
29
28
  # A Docker image with Semgrep installed. Do not change this.
30
- image: returntocorp/semgrep
31
-
29
+ image: returntocorp/semgrep:1.166.0
32
30
  # Skip any PR created by dependabot to avoid permission issues:
33
31
  if: (github.actor != 'dependabot[bot]')
34
32
 
35
33
  steps:
36
34
  # Fetch project source with GitHub Actions Checkout.
37
35
  - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
36
+ with:
37
+ # Diff-aware PR scans need the merge base with the target branch.
38
+ fetch-depth: 0
39
+ # The container runs as root but the workspace belongs to the runner user, so git
40
+ # (used by "semgrep ci" for diff-aware scans) refuses it unless it is marked safe.
41
+ - run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
38
42
  # Run the "semgrep ci" command on the command line of the docker image.
39
43
  - run: semgrep ci --sarif --output=semgrep.sarif
40
44
  env:
41
- # Add the rules that Semgrep uses by setting the SEMGREP_RULES environment variable.
45
+ # Add the rules that Semgrep uses by setting the SEMGREP_RULES environment variable.
42
46
  SEMGREP_RULES: p/default # more at semgrep.dev/explore
43
47
 
44
48
  - name: Upload SARIF file for GitHub Advanced Security Dashboard
45
49
  uses: github/codeql-action/upload-sarif@6c089f53dd51dc3fc7e599c3cb5356453a52ca9e # v2.20.0
46
50
  with:
47
51
  sarif_file: semgrep.sarif
48
- if: always()
52
+ # Also runs on fork PRs: GitHub accepts SARIF uploads from their read-only token
53
+ # in public repositories, so no extra permissions are needed.
54
+ if: always()
@@ -1,3 +1,5 @@
1
+ require 'open3'
2
+
1
3
  module Percy
2
4
  class Client
3
5
  module Environment
@@ -104,16 +106,27 @@ module Percy
104
106
 
105
107
  # @private
106
108
  def self._raw_commit_output(commit_sha)
109
+ # The SHA can come from env vars such as PERCY_COMMIT. Refuse anything git could read
110
+ # as an option (e.g. "--output=/some/file"); it is never a valid revision anyway.
111
+ commit_sha = commit_sha.to_s
112
+ return if commit_sha.empty? || commit_sha.start_with?('-')
113
+
107
114
  format = GIT_FORMAT_LINES.join('%n') # "git show" format uses %n for newlines.
108
- output = if Gem.win_platform?
109
- `git show --quiet #{commit_sha} --format="#{format}" 2> NUL`.strip
110
- else
111
- `git show --quiet #{commit_sha} --format="#{format}" 2> /dev/null`.strip
112
- end
113
- return if $CHILD_STATUS.to_i != 0
114
- output
115
+ output = _git_output('show', '--quiet', commit_sha, "--format=#{format}")
116
+ output && output.strip
115
117
  end
116
118
 
119
+ # Runs git with an argument list (no shell), discarding stderr.
120
+ # @private
121
+ # @return [String, nil] stdout, or nil if git exits non-zero or cannot be run.
122
+ def self._git_output(*args)
123
+ stdout, status = Open3.capture2('git', *args, err: File::NULL)
124
+ stdout if status.success?
125
+ rescue SystemCallError
126
+ nil
127
+ end
128
+ class << self; private :_git_output; end
129
+
117
130
  def self.target_commit_sha
118
131
  return ENV['PERCY_TARGET_COMMIT'] if ENV['PERCY_TARGET_COMMIT']
119
132
  end
@@ -161,12 +174,9 @@ module Percy
161
174
 
162
175
  # @private
163
176
  def self._raw_branch_output
164
- # Discover from local git repo branch name.
165
- if Gem.win_platform?
166
- `git rev-parse --abbrev-ref HEAD 2> NUL`.strip
167
- else
168
- `git rev-parse --abbrev-ref HEAD 2> /dev/null`.strip
169
- end
177
+ # Discover from local git repo branch name. Empty string (not nil) when git fails, so
178
+ # that #branch can warn about not being in a git repo.
179
+ (_git_output('rev-parse', '--abbrev-ref', 'HEAD') || '').strip
170
180
  end
171
181
  class << self; private :_raw_branch_output; end
172
182
 
@@ -238,7 +248,7 @@ module Percy
238
248
 
239
249
  # @private
240
250
  def self._get_origin_url
241
- `git config --get remote.origin.url`
251
+ _git_output('config', '--get', 'remote.origin.url') || ''
242
252
  end
243
253
  class << self; private :_get_origin_url; end
244
254
  end
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  class Client
3
- VERSION = '2.1.1'.freeze
3
+ VERSION = '2.1.2'.freeze
4
4
  end
5
5
  end
data/percy-client.gemspec CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_dependency 'faraday', '0.15.4'
23
- spec.add_dependency 'excon', '0.105.0'
22
+ spec.add_dependency 'faraday', '>= 0.15.4', '< 1.0'
23
+ spec.add_dependency 'excon', '>= 0.105.0', '< 1.0'
24
24
  spec.add_dependency 'addressable'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 2.0'
@@ -1,3 +1,5 @@
1
+ require 'tmpdir'
2
+
1
3
  RSpec.describe Percy::Client::Environment do
2
4
  def clear_env_vars
3
5
  # Unset Percy vars.
@@ -516,6 +518,80 @@ RSpec.describe Percy::Client::Environment do
516
518
  commit = Percy::Client::Environment.commit
517
519
  expect(commit[:author_name]).to eq('Spêcìal Ñàme')
518
520
  end
521
+
522
+ it 'falls back to HEAD when the env commit SHA looks like a git option' do
523
+ ENV['PERCY_COMMIT'] = '--output=/tmp/percy-client-pwned'
524
+ head_sha = Percy::Client::Environment._raw_commit_output('HEAD')[/COMMIT_SHA:(.*)/, 1]
525
+
526
+ commit = Percy::Client::Environment.commit
527
+ expect(commit[:sha]).to eq('--output=/tmp/percy-client-pwned')
528
+ expect(commit[:message]).to_not be_nil
529
+ expect(Percy::Client::Environment._git_commit_output).to include("COMMIT_SHA:#{head_sha}")
530
+ end
531
+ end
532
+
533
+ describe '#_raw_commit_output' do
534
+ it 'returns git show output for a valid revision' do
535
+ output = Percy::Client::Environment._raw_commit_output('HEAD')
536
+ expect(output).to match(/\ACOMMIT_SHA:\h{40}$/)
537
+ expect(output).to include('COMMIT_MESSAGE:')
538
+ end
539
+
540
+ it 'calls git with an argument list and no shell, discarding stderr' do
541
+ status = instance_double(Process::Status, success?: true)
542
+ expect(Open3).to receive(:capture2)
543
+ .with('git', 'show', '--quiet', 'abc123', /\A--format=COMMIT_SHA:%H%n/, err: File::NULL)
544
+ .and_return(["COMMIT_SHA:abc123\n", status])
545
+
546
+ expect(Percy::Client::Environment._raw_commit_output('abc123')).to eq('COMMIT_SHA:abc123')
547
+ end
548
+
549
+ it 'does not run shell metacharacters in the SHA' do
550
+ Dir.mktmpdir do |dir|
551
+ marker = File.join(dir, 'pwned')
552
+ output = Percy::Client::Environment._raw_commit_output("HEAD; touch #{marker}")
553
+ expect(output).to be_nil
554
+ expect(File.exist?(marker)).to eq(false)
555
+ end
556
+ end
557
+
558
+ ['-p', '--output=/tmp/percy-client-pwned', '-'].each do |sha|
559
+ it "rejects #{sha.inspect} without running git" do
560
+ expect(Open3).to_not receive(:capture2)
561
+ expect(Percy::Client::Environment._raw_commit_output(sha)).to be_nil
562
+ end
563
+ end
564
+
565
+ it 'returns nil for an empty or nil SHA without running git' do
566
+ expect(Open3).to_not receive(:capture2)
567
+ expect(Percy::Client::Environment._raw_commit_output('')).to be_nil
568
+ expect(Percy::Client::Environment._raw_commit_output(nil)).to be_nil
569
+ end
570
+
571
+ it 'returns nil when git exits non-zero' do
572
+ expect(Percy::Client::Environment._raw_commit_output('0' * 40)).to be_nil
573
+ end
574
+
575
+ it 'returns nil when git is not installed' do
576
+ expect(Open3).to receive(:capture2).and_raise(Errno::ENOENT)
577
+ expect(Percy::Client::Environment._raw_commit_output('HEAD')).to be_nil
578
+ end
579
+ end
580
+
581
+ describe '#branch from the local repo' do
582
+ it 'returns nil and warns when git is not installed' do
583
+ expect(Open3).to receive(:capture2).and_raise(Errno::ENOENT)
584
+ expect(STDERR).to receive(:puts).with(/no branch detected/)
585
+ expect(Percy::Client::Environment.branch).to be_nil
586
+ end
587
+
588
+ it 'calls git rev-parse with an argument list' do
589
+ status = instance_double(Process::Status, success?: true)
590
+ expect(Open3).to receive(:capture2)
591
+ .with('git', 'rev-parse', '--abbrev-ref', 'HEAD', err: File::NULL)
592
+ .and_return(["some-branch\n", status])
593
+ expect(Percy::Client::Environment.branch).to eq('some-branch')
594
+ end
519
595
  end
520
596
  end
521
597
  end
metadata CHANGED
@@ -1,43 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percy-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Perceptual Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-18 00:00:00.000000000 Z
11
+ date: 2026-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.15.4
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - '='
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.15.4
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: excon
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - '='
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
39
  version: 0.105.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.0'
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - '='
47
+ - - ">="
39
48
  - !ruby/object:Gem::Version
40
49
  version: 0.105.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.0'
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: addressable
43
55
  requirement: !ruby/object:Gem::Requirement