danger-periphery 0.3.1 → 0.5.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
  SHA256:
3
- metadata.gz: 12b5d90e78c9ce9ffe21444e0f89723c36287b74f6cec8047185e6c6266f179e
4
- data.tar.gz: 533cd4b72da33e99be395e41a9c81e764f99ec6f149b6695df90b59ef25cbe77
3
+ metadata.gz: 9006201540562aff46abee569a0fb7d437e5d88d57a469db159f587e8183f3e7
4
+ data.tar.gz: 6c1d7515560909bcfa30ff03ebdbeffc57d11f713ddd33625441fd67560c4e7c
5
5
  SHA512:
6
- metadata.gz: 545d4b1bf8b95ed580a7267f937548efa47ca8b3835bb646aa55270f4016796be8de5e9309631c51cf42c6804e2f1356758efb2d063a05542edc2a16d38d997a
7
- data.tar.gz: a0aca8766ed747d3a0dde0c2fb919dde6bf4c79048a95805063d7df35d535447cd5f7e1a569b66a28ee867918cd1c340c4432b656c72c421ecfa45aec22b4ebe
6
+ metadata.gz: 0c72323b652e535bc893165125fdd441989130e5426311d14a4842d61534bfad42838c5f5c2c08258c8087d41ab657e416544f912abad76e5ee8a6a7603549ca
7
+ data.tar.gz: d24d10f5730367a3461c663d70d1ca45516d17d3b979a63063bf006011aaff928a55b6f0e56f88cb7e10093e4325f816cfd3c9b7b5e6fea7e82f3d5674fa6d55
@@ -35,6 +35,16 @@ module Danger
35
35
  # By default +false+ is set.
36
36
  attr_accessor :warning_as_error
37
37
 
38
+ # A flag to enable verbose output.
39
+ # @return [Boolean] +true+ if this plugin prints all outputs from Periphery.
40
+ # Otherwise returns +false+ and prints only errors.
41
+ # Defaults to +false+.
42
+ # Note that regardless of this value, this plugin always overrides certain options,
43
+ # such as +--disable-update-check+, +--format+ and +--quiet+.
44
+ # @see OPTION_OVERRIDES
45
+ # @see format=
46
+ attr_accessor :verbose
47
+
38
48
  # For internal use only.
39
49
  #
40
50
  # @return [Symbol]
@@ -46,7 +56,7 @@ module Danger
46
56
  }.freeze
47
57
 
48
58
  def initialize(dangerfile)
49
- super(dangerfile)
59
+ super
50
60
  @format = :checkstyle
51
61
  @warning_as_error = false
52
62
  end
@@ -86,6 +96,13 @@ module Danger
86
96
  end
87
97
  end
88
98
 
99
+ # The version of underlying Periphery executable.
100
+ #
101
+ # @return [string]
102
+ def version
103
+ Periphery::Runner.new(binary_path).version
104
+ end
105
+
89
106
  # Download and install Periphery executable binary.
90
107
  #
91
108
  # @param [String, Symbol] version The version of Periphery you want to install.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DangerPeriphery
4
- VERSION = '0.3.1'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -2,48 +2,94 @@
2
2
 
3
3
  require 'open3'
4
4
  require 'rubygems/version'
5
+ require 'stringio'
5
6
 
6
7
  module Periphery
7
8
  class Runner # :nodoc:
8
- attr_reader :binary_path
9
+ attr_reader :binary_path, :verbose
9
10
 
10
- def initialize(binary_path)
11
+ def initialize(binary_path, on_spawn: nil, verbose: false)
11
12
  @binary_path = binary_path || 'periphery'
13
+ @on_spawn = on_spawn
14
+ @verbose = verbose
12
15
  end
13
16
 
14
17
  def scan(options)
15
18
  arguments = [binary_path, 'scan'] + scan_arguments(options)
16
- stdout, stderr, status = Open3.capture3(*arguments)
17
- raise "error: #{arguments} exited with status code #{status.exitstatus}. #{stderr}" unless status.success?
19
+ stdout, stderr, status = capture_output(arguments)
20
+ validate_subprocess_status!(arguments, status, stderr)
18
21
 
19
- stdout
22
+ stdout.string
20
23
  end
21
24
 
22
25
  def scan_arguments(options)
23
- options.each_with_object([]) do |(key, value), new_options|
26
+ args = []
27
+ options.each do |key, value|
24
28
  next unless value
25
29
 
30
+ next if key == :build_args
31
+
26
32
  value = nil if value.is_a?(TrueClass)
33
+ args << "--#{key.to_s.tr('_', '-')}"
27
34
  if value.is_a?(Array)
28
35
  if Gem::Version.new(version) >= Gem::Version.new('2.18.0')
29
- new_options << "--#{key.to_s.tr('_', '-')}"
30
- new_options.push(*value.map(&:to_s))
31
- next
36
+ args.push(*value.map(&:to_s))
32
37
  else
33
- value = value.join(',')
38
+ args << value.join(',')
34
39
  end
40
+ elsif value
41
+ args << value&.to_s
35
42
  end
36
- new_options << "--#{key.to_s.tr('_', '-')}"
37
- new_options << value&.to_s if value
38
43
  end
44
+ args += ['--', options[:build_args]] if options[:build_args]
45
+ args
39
46
  end
40
47
 
41
48
  def version
42
49
  arguments = [binary_path, 'version']
43
- stdout, stderr, status = Open3.capture3(*arguments)
44
- raise "error: #{arguments} existed with status code #{status.exitstatus}. #{stderr}" unless status.success?
50
+ stdout, stderr, status = capture_output(arguments)
51
+ validate_subprocess_status!(arguments, status, stderr)
52
+
53
+ stdout.string.strip
54
+ end
55
+
56
+ private
45
57
 
46
- stdout.strip
58
+ def capture_output(arguments)
59
+ out = StringIO.new
60
+ err = StringIO.new
61
+ status = Open3.popen3(*arguments, in: :close) do |_, stdout, stderr, wait_thread|
62
+ @on_spawn&.call(wait_thread.pid)
63
+ threads = []
64
+ begin
65
+ threads << tee(stdout, verbose ? [out, $stdout] : [out])
66
+ threads << tee(stderr, verbose ? [err, $stderr] : [err])
67
+ status = wait_thread.value
68
+ threads.each(&:join)
69
+ status
70
+ ensure
71
+ threads.each(&:kill)
72
+ end
73
+ end
74
+ [out, err, status]
75
+ end
76
+
77
+ def validate_subprocess_status!(arguments, status, stderr)
78
+ case status.success?
79
+ when false
80
+ raise "error: #{arguments} exited with status code #{status.exitstatus}. #{stderr.string}"
81
+ when nil
82
+ raise "error: #{arguments} was terminated by SIG#{Signal.signame(status.termsig)}"
83
+ end
84
+ end
85
+
86
+ def tee(in_io, out_ios)
87
+ Thread.new do
88
+ until in_io.eof?
89
+ data = in_io.readpartial(1024)
90
+ out_ios.each { |io| io.write(data) }
91
+ end
92
+ end
47
93
  end
48
94
  end
49
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-periphery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryosuke Ito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-26 00:00:00.000000000 Z
11
+ date: 2025-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -38,7 +38,9 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
- description: A Danger plugin to detect unused codes.
41
+ description: |
42
+ This project is a plugin for Danger, which is a tool for monitoring the quality of the codebase.
43
+ This plugin detects unused codes in your Swift project using Periphery.
42
44
  email:
43
45
  - rito.0305@gmail.com
44
46
  executables: []
@@ -58,6 +60,10 @@ homepage: https://github.com/manicmaniac/danger-periphery
58
60
  licenses:
59
61
  - MIT
60
62
  metadata:
63
+ bug_tracker_uri: https://github.com/manicmaniac/danger-periphery/issues
64
+ changelog_uri: https://raw.githubusercontent.com/manicmaniac/danger-periphery/refs/heads/0.5.0/CHANGELOG.md
65
+ documentation_uri: https://www.rubydoc.info/gems/danger-periphery/0.5.0
66
+ homepage_uri: https://github.com/manicmaniac/danger-periphery
61
67
  rubygems_mfa_required: 'true'
62
68
  post_install_message:
63
69
  rdoc_options: []
@@ -74,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
80
  - !ruby/object:Gem::Version
75
81
  version: '0'
76
82
  requirements: []
77
- rubygems_version: 3.4.6
83
+ rubygems_version: 3.5.16
78
84
  signing_key:
79
85
  specification_version: 4
80
86
  summary: A Danger plugin to detect unused codes.