danger-periphery 0.4.0 → 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: 8d2f612902b0953cad3166423f6ec628619d1de19fe9727b0c55164067283de6
4
- data.tar.gz: 9ed570bd16dfea55ade3e05ea1043e29c8f0924edec9c2851501a92c6a3989dd
3
+ metadata.gz: 9006201540562aff46abee569a0fb7d437e5d88d57a469db159f587e8183f3e7
4
+ data.tar.gz: 6c1d7515560909bcfa30ff03ebdbeffc57d11f713ddd33625441fd67560c4e7c
5
5
  SHA512:
6
- metadata.gz: b805c2969118ac69ac822c01f155138798d005cda0f14264cf71cde95cbbab5143f6dd2eba4439accd980d53b54b37baf0778803ca7a95526919ca5fed8a923b
7
- data.tar.gz: 96c7baebde3044b5d7c70014b3a42fb408e24775c8c5587363b496cb53e1d31ad5a86af3665a2ee17c0610df6e00929dc9c1df1b7755fd55aa518f98fca4d9b9
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]
@@ -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.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -2,22 +2,24 @@
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)
19
+ stdout, stderr, status = capture_output(arguments)
20
+ validate_subprocess_status!(arguments, status, stderr)
16
21
 
17
- stdout, stderr, status = Open3.capture3(*arguments)
18
- raise "error: #{arguments} exited with status code #{status.exitstatus}. #{stderr}" unless status.success?
19
-
20
- stdout
22
+ stdout.string
21
23
  end
22
24
 
23
25
  def scan_arguments(options)
@@ -45,10 +47,49 @@ module Periphery
45
47
 
46
48
  def version
47
49
  arguments = [binary_path, 'version']
48
- stdout, stderr, status = Open3.capture3(*arguments)
49
- 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
50
57
 
51
- 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
52
93
  end
53
94
  end
54
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.4.0
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-08-28 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.5.14
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.