ossy 0.3.2 → 0.3.3

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
  SHA256:
3
- metadata.gz: 692163075005596e24fcd369ab7a65bae9cf32fbaa9fd4ba7443059b398d7744
4
- data.tar.gz: aa9d30379da6adcace2c88605dd781e40395fb04eca3d483402f1214edcc8281
3
+ metadata.gz: f7335a5f4133bde5fed20bcd4ae682450b57ca98e184a784c3df18ba938510e6
4
+ data.tar.gz: 70139766a69aa38d1ffa6f3bd089ce2567ac850907ae52451d60f91a73928064
5
5
  SHA512:
6
- metadata.gz: ba6e94b22f3309d56f2df084ba0b27b4069d47aaa13b0789799d7b9b29b291dc64a974157ce90f74f0fbd2bbb9ae774acec296894ed0f885ce2dd0b810a2276c
7
- data.tar.gz: 131df202b10b86c1d2d147ce73c44bb8a9bc6de334afde09bec4c13f9d342344b51964bea6357d00e2ec176fa4cb14e91f545f5e053270d4562b4366a19c02df
6
+ metadata.gz: 237290f69c965cdd25f948cdff179c4d850d047cb4c86dbe09df455380a78c593ba4c7f6f97bc32b2c7e484c1309ee332e602c5fae0621ab02437cedcab37963
7
+ data.tar.gz: 9110f871c9a3b5aaf61fd08548cb03447cf63a473d53ae448de73fcb627d7c78ddffef58a82f4ae73a309d2f784e9bc255ea74eb9463f8f19fa89570324f1ad8
@@ -18,7 +18,7 @@ module Ossy
18
18
  KEYS = %w[version summary date fixed added changed].freeze
19
19
 
20
20
  def call(config_path:, message:)
21
- attrs = YAML.load(message)
21
+ attrs = YAML.safe_load(message)
22
22
  target = YAML.load_file(config_path)
23
23
 
24
24
  version = attrs["version"] || target[0]["version"]
@@ -22,6 +22,8 @@ module Ossy
22
22
 
23
23
  require "ossy/cli/templates/compile"
24
24
 
25
+ require "ossy/cli/metrics/rubocop"
26
+
25
27
  register "github", aliases: %w[gh] do |github|
26
28
  github.register "workflow", Github::Workflow, aliases: %w[w]
27
29
  github.register "membership", Github::Membership, aliases: %w[m]
@@ -46,6 +48,10 @@ module Ossy
46
48
  register "configs", aliases: %w[c] do |configs|
47
49
  configs.register "merge", Configs::Merge, aliases: %w[m]
48
50
  end
51
+
52
+ register "metrics", aliases: %w[m] do |configs|
53
+ configs.register "rubocop", Metrics::Rubocop, aliases: %w[rc]
54
+ end
49
55
  end
50
56
  end
51
57
  end
@@ -16,7 +16,7 @@ module Ossy
16
16
  argument :output_path, required: true, desc: "The path to the output file"
17
17
 
18
18
  option :identifiers, required: false, default: "",
19
- desc: "Key identifier that should be used for merging arrays of hashes"
19
+ desc: "Key identifier that should be used for merging arrays of hashes"
20
20
 
21
21
  def call(source_path:, target_path:, output_path:, **opts)
22
22
  puts "Merging #{source_path} + #{target_path} into #{output_path}"
@@ -49,9 +49,11 @@ module Ossy
49
49
  arr
50
50
  .map
51
51
  .with_index { |el, idx|
52
- (after = el.delete("_after")) ?
53
- [el, arr.index(arr.detect { |a| a[id].eql?(after) }) + 1] :
52
+ if (after = el.delete("_after"))
53
+ [el, arr.index(arr.detect { |a| a[id].eql?(after) }) + 1]
54
+ else
54
55
  [el, idx]
56
+ end
55
57
  }.sort_by(&:last).map(&:first)
56
58
  else
57
59
  (val1 + val2).uniq
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ossy/cli/commands/core"
4
+ require "ossy/import"
5
+ require "ossy/release"
6
+
7
+ require "yaml"
8
+ require "tilt"
9
+ require "ostruct"
10
+
11
+ module Ossy
12
+ module CLI
13
+ module Metrics
14
+ class Rubocop < Commands::Core
15
+ include Import[run_rubocop: "engine.rubocop.run"]
16
+
17
+ desc "Runs rubocop"
18
+
19
+ argument :path, required: true, desc: "The path to file(s)"
20
+ option :format, required: true, desc: "Output format"
21
+ option :do_exit, required: false,
22
+ desc: "Whether the command should exit with the same status as rubocop"
23
+ option :silence, required: false,
24
+ desc: "Whether the rubocop output should be displayed"
25
+
26
+ def call(path:, silence: "false", do_exit: "true", args: [], **opts)
27
+ result, output = run_rubocop.(path: path, args: args, **opts)
28
+
29
+ warn output if silence.eql?("false") && !result.success?
30
+
31
+ exit(result.exitstatus) if do_exit.eql?("true")
32
+
33
+ [result, output]
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -7,7 +7,7 @@ require "ossy/types"
7
7
 
8
8
  module Ossy
9
9
  class Container < Dry::System::Container
10
- use :env, inferrer: proc { ENV.fetch("OSSY_ENV") { "development" }.to_sym }
10
+ use :env, inferrer: proc { ENV.fetch("OSSY_ENV", "development").to_sym }
11
11
 
12
12
  configure do |config|
13
13
  config.root = Pathname(__dir__).join("../../")
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+
5
+ require "ossy/cli/commands/core"
6
+ require "ossy/struct"
7
+
8
+ module Ossy
9
+ module Engine
10
+ module Rubocop
11
+ # {
12
+ # "metadata" : {
13
+ # "ruby_platform" : "x86_64-darwin20",
14
+ # "ruby_version" : "2.7.2",
15
+ # "ruby_engine" : "ruby",
16
+ # "ruby_patchlevel" : "137",
17
+ # "rubocop_version" : "1.6.1"
18
+ # },
19
+ # "files" : [
20
+ # {
21
+ # "offenses" : [],
22
+ # "path" : "spec/spec_helper.rb"
23
+ # }
24
+ # ],
25
+ # "summary" : {
26
+ # "target_file_count" : 1,
27
+ # "inspected_file_count" : 1,
28
+ # "offense_count" : 0
29
+ # }
30
+ # }
31
+ #
32
+ # # json["files"] element
33
+ # {"path"=>"spec/fixtures/rubocop/bad.rb",
34
+ # "offenses"=>
35
+ # [{"severity"=>"convention",
36
+ # "message"=> "blablabla",
37
+ # "cop_name"=>"Style/StringLiterals",
38
+ # "corrected"=>false,
39
+ # "correctable"=>true,
40
+ # "location"=>
41
+ # {"start_line"=>3,
42
+ # "start_column"=>1,
43
+ # "last_line"=>3,
44
+ # "last_column"=>30,
45
+ # "length"=>30,
46
+ # "line"=>3,
47
+ # "column"=>1}}]}
48
+ class Result < Ossy::Struct
49
+ attribute :summary do
50
+ attribute :offense_count, Types::Integer
51
+ end
52
+
53
+ def self.build(json)
54
+ klass =
55
+ case json["summary"]["offense_count"]
56
+ in 0 then Success
57
+ in 1.. then Failure
58
+ end
59
+ klass.new(json)
60
+ end
61
+
62
+ def failure?
63
+ !success?
64
+ end
65
+ end
66
+
67
+ class Success < Result
68
+ def success?
69
+ true
70
+ end
71
+ end
72
+
73
+ class Failure < Result
74
+ attribute :files, Types::Array do
75
+ attribute :path, Types::String
76
+ attribute :offenses, Types::Array do
77
+ attribute :severity, Types::String
78
+ attribute :cop_name, Types::String
79
+ attribute :location do
80
+ attribute :start_line, Types::Integer
81
+ attribute :start_column, Types::Integer
82
+ attribute :last_line, Types::Integer
83
+ attribute :last_column, Types::Integer
84
+ attribute :line, Types::Integer
85
+ attribute :column, Types::Integer
86
+ end
87
+ end
88
+ end
89
+
90
+ def success?
91
+ false
92
+ end
93
+ end
94
+
95
+ class Run < Ossy::CLI::Commands::Core
96
+ option :path, desc: "Path to file(s)"
97
+ option :format, desc: "Path to file(s)"
98
+
99
+ def call(path:, format: "json", args: [])
100
+ extra_opts = args.join(" ")
101
+ result, output = exec("rubocop #{path} --format #{format} #{extra_opts}".strip)
102
+
103
+ case format
104
+ when "json" then Result.build(JSON.parse(output))
105
+ else
106
+ [result, output]
107
+ end
108
+ end
109
+
110
+ def exec(cmd, opts = {})
111
+ Open3.popen3(cmd, opts) do |_stdin, stdout, _stderr, wait_thr|
112
+ [wait_thr.value, stdout.read]
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
data/lib/ossy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ossy
4
- VERSION = "0.3.2"
4
+ VERSION = "0.3.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ossy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-03 00:00:00.000000000 Z
11
+ date: 2021-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -70,14 +70,14 @@ dependencies:
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: '0.14'
73
+ version: 0.18.1
74
74
  type: :runtime
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: '0.14'
80
+ version: 0.18.1
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: dry-types
83
83
  requirement: !ruby/object:Gem::Requirement
@@ -199,9 +199,11 @@ files:
199
199
  - lib/ossy/cli/github/tagger.rb
200
200
  - lib/ossy/cli/github/update_file.rb
201
201
  - lib/ossy/cli/github/workflow.rb
202
+ - lib/ossy/cli/metrics/rubocop.rb
202
203
  - lib/ossy/cli/releases/generate.rb
203
204
  - lib/ossy/cli/templates/compile.rb
204
205
  - lib/ossy/container.rb
206
+ - lib/ossy/engine/rubocop/run.rb
205
207
  - lib/ossy/github/client.rb
206
208
  - lib/ossy/github/workflow.rb
207
209
  - lib/ossy/import.rb
@@ -232,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
234
  - !ruby/object:Gem::Version
233
235
  version: '0'
234
236
  requirements: []
235
- rubygems_version: 3.2.3
237
+ rubygems_version: 3.2.15
236
238
  signing_key:
237
239
  specification_version: 4
238
240
  summary: Ossy is your ruby gem maintenance helper