ossy 0.1.4 → 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: f8bcf521ecfc31f5113a77e3f07557dd47e9d2f314a1f1ea76702484c4162160
4
- data.tar.gz: 3deccc915655efe3af8511b7b78b5319b32ca83af82f5098159572646ea28d3a
3
+ metadata.gz: f7335a5f4133bde5fed20bcd4ae682450b57ca98e184a784c3df18ba938510e6
4
+ data.tar.gz: 70139766a69aa38d1ffa6f3bd089ce2567ac850907ae52451d60f91a73928064
5
5
  SHA512:
6
- metadata.gz: 37f8af0da24eb5b89eba2bd3cc8737dc0be54a742fb4fa92e5344528fd933e591bdbbfbfc7acdb6746f87c19055b6eb6de52a913f2330eafa65af1ffa6928cfb
7
- data.tar.gz: cfaa936acabd6b38321a32bf1dae49d620c9b00b81b42599aa539546ad468e77120fe2261d9c61e0e1cc7ac9aa9c4ef8ffd9c3cc7ce4e7eb9f14e7eb79cd795a
6
+ metadata.gz: 237290f69c965cdd25f948cdff179c4d850d047cb4c86dbe09df455380a78c593ba4c7f6f97bc32b2c7e484c1309ee332e602c5fae0621ab02437cedcab37963
7
+ data.tar.gz: 9110f871c9a3b5aaf61fd08548cb03447cf63a473d53ae448de73fcb627d7c78ddffef58a82f4ae73a309d2f784e9bc255ea74eb9463f8f19fa89570324f1ad8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.0 2021-01-02
2
+
3
+ ### Added
4
+
5
+ - `configs merge` now supports merging array of hashes (@solnic)
6
+
1
7
  ## 0.1.4 2020-01-23
2
8
 
3
9
  ### Fixed
data/lib/ossy.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ossy/version'
3
+ require "ossy/version"
4
4
 
5
5
  module Ossy
6
6
  end
data/lib/ossy/cli.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/cli'
4
- require 'ossy/cli/commands'
3
+ require "dry/cli"
4
+ require "ossy/cli/commands"
5
5
 
6
6
  module Ossy
7
7
  module CLI
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ossy/cli/commands/core'
4
- require 'ossy/import'
5
- require 'ossy/release'
3
+ require "ossy/cli/commands/core"
4
+ require "ossy/import"
5
+ require "ossy/release"
6
6
 
7
- require 'yaml'
8
- require 'tilt'
9
- require 'ostruct'
7
+ require "yaml"
8
+ require "tilt"
9
+ require "ostruct"
10
10
 
11
11
  module Ossy
12
12
  module CLI
@@ -23,13 +23,13 @@ module Ossy
23
23
  end
24
24
  end
25
25
 
26
- desc 'Generates a changelog markdown file from a yaml config'
26
+ desc "Generates a changelog markdown file from a yaml config"
27
27
 
28
- argument :config_path, required: true, desc: 'The path to the changelog config'
29
- argument :output_path, required: true, desc: 'The path to the output md file'
30
- argument :template_path, required: true, desc: 'The path to the changelog ERB template'
28
+ argument :config_path, required: true, desc: "The path to the changelog config"
29
+ argument :output_path, required: true, desc: "The path to the output md file"
30
+ argument :template_path, required: true, desc: "The path to the changelog ERB template"
31
31
 
32
- option :data_path, required: false, desc: 'Optional path to additional data yaml file'
32
+ option :data_path, required: false, desc: "Optional path to additional data yaml file"
33
33
 
34
34
  def call(config_path:, output_path:, template_path:, data_path: nil)
35
35
  puts "Generating #{output_path} from #{config_path} using #{template_path}"
@@ -40,7 +40,7 @@ module Ossy
40
40
  context = Context.new(ctx_data)
41
41
 
42
42
  if data_path
43
- key = File.basename(data_path).gsub('.yml', '')
43
+ key = File.basename(data_path).gsub(".yml", "")
44
44
  data = YAML.load_file(data_path)
45
45
 
46
46
  context.update(key => OpenStruct.new(data))
@@ -1,28 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ossy/cli/commands/core'
4
- require 'ossy/import'
5
- require 'ossy/release'
3
+ require "ossy/cli/commands/core"
4
+ require "ossy/import"
5
+ require "ossy/release"
6
6
 
7
- require 'yaml'
7
+ require "yaml"
8
8
 
9
9
  module Ossy
10
10
  module CLI
11
11
  module Changelogs
12
12
  class Update < Commands::Core
13
- desc 'Adds a new entry to a changelog config'
13
+ desc "Adds a new entry to a changelog config"
14
14
 
15
- argument :config_path, required: true, desc: 'The path to the changelog config'
16
- argument :message, required: true, desc: 'Message text including the entry'
15
+ argument :config_path, required: true, desc: "The path to the changelog config"
16
+ argument :message, required: true, desc: "Message text including the entry"
17
17
 
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
- version = attrs['version'] || target[0]['version']
25
- entry = target.detect { |e| e['version'].eql?(version) } || {}
24
+ version = attrs["version"] || target[0]["version"]
25
+ entry = target.detect { |e| e["version"].eql?(version) } || {}
26
26
 
27
27
  release = Release.new(attrs.merge(version: version))
28
28
 
@@ -1,44 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/cli/registry'
3
+ require "dry/cli/registry"
4
4
 
5
5
  module Ossy
6
6
  module CLI
7
7
  module Commands
8
8
  extend Dry::CLI::Registry
9
9
 
10
- require 'ossy/cli/github/workflow'
11
- require 'ossy/cli/github/membership'
12
- require 'ossy/cli/github/tagger'
13
- require 'ossy/cli/github/member'
14
- require 'ossy/cli/github/update_file'
10
+ require "ossy/cli/github/workflow"
11
+ require "ossy/cli/github/membership"
12
+ require "ossy/cli/github/tagger"
13
+ require "ossy/cli/github/member"
14
+ require "ossy/cli/github/update_file"
15
15
 
16
- require 'ossy/cli/changelogs/generate'
17
- require 'ossy/cli/changelogs/update'
16
+ require "ossy/cli/changelogs/generate"
17
+ require "ossy/cli/changelogs/update"
18
18
 
19
- require 'ossy/cli/configs/merge'
19
+ require "ossy/cli/releases/generate"
20
20
 
21
- require 'ossy/cli/templates/compile'
21
+ require "ossy/cli/configs/merge"
22
22
 
23
- register 'github', aliases: %w[gh] do |github|
24
- github.register 'workflow', Github::Workflow, aliases: %w[w]
25
- github.register 'membership', Github::Membership, aliases: %w[m]
26
- github.register 'tagger', Github::Tagger, aliases: %w[t]
27
- github.register 'member', Github::Member, aliases: %w[om]
28
- github.register 'update_file', Github::UpdateFile, aliases: %w[uf]
23
+ require "ossy/cli/templates/compile"
24
+
25
+ require "ossy/cli/metrics/rubocop"
26
+
27
+ register "github", aliases: %w[gh] do |github|
28
+ github.register "workflow", Github::Workflow, aliases: %w[w]
29
+ github.register "membership", Github::Membership, aliases: %w[m]
30
+ github.register "tagger", Github::Tagger, aliases: %w[t]
31
+ github.register "member", Github::Member, aliases: %w[om]
32
+ github.register "update_file", Github::UpdateFile, aliases: %w[uf]
33
+ end
34
+
35
+ register "templates", aliases: %w[t] do |templates|
36
+ templates.register "compile", Templates::Compile, aliases: %w[c]
37
+ end
38
+
39
+ register "changelogs", aliases: %w[ch] do |changelogs|
40
+ changelogs.register "generate", Changelogs::Generate, aliases: %w[g]
41
+ changelogs.register "update", Changelogs::Update, aliases: %w[u]
29
42
  end
30
43
 
31
- register 'templates', aliases: %w[t] do |templates|
32
- templates.register 'compile', Templates::Compile, aliases: %w[c]
44
+ register "releases", aliases: %w[r] do |releases|
45
+ releases.register "generate", Releases::Generate, aliases: %w[g]
33
46
  end
34
47
 
35
- register 'changelogs', aliases: %w[ch] do |changelogs|
36
- changelogs.register 'generate', Changelogs::Generate, aliases: %w[g]
37
- changelogs.register 'update', Changelogs::Update, aliases: %w[u]
48
+ register "configs", aliases: %w[c] do |configs|
49
+ configs.register "merge", Configs::Merge, aliases: %w[m]
38
50
  end
39
51
 
40
- register 'configs', aliases: %w[c] do |configs|
41
- configs.register 'merge', Configs::Merge, aliases: %w[m]
52
+ register "metrics", aliases: %w[m] do |configs|
53
+ configs.register "rubocop", Metrics::Rubocop, aliases: %w[rc]
42
54
  end
43
55
  end
44
56
  end
@@ -1,39 +1,63 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ossy/cli/commands/core'
4
- require 'ossy/import'
3
+ require "ossy/cli/commands/core"
4
+ require "ossy/import"
5
5
 
6
- require 'yaml'
6
+ require "yaml"
7
7
 
8
8
  module Ossy
9
9
  module CLI
10
10
  module Configs
11
11
  class Merge < Commands::Core
12
- desc 'Merge two yaml config files into a new one'
12
+ desc "Merge two yaml config files into a new one"
13
13
 
14
- argument :source_path, required: true, desc: 'The path to the source file'
15
- argument :target_path, required: true, desc: 'The path to the target file'
16
- argument :output_path, required: true, desc: 'The path to the output file'
14
+ argument :source_path, required: true, desc: "The path to the source file"
15
+ argument :target_path, required: true, desc: "The path to the target file"
16
+ argument :output_path, required: true, desc: "The path to the output file"
17
17
 
18
- def call(source_path:, target_path:, output_path:)
18
+ option :identifiers, required: false, default: "",
19
+ desc: "Key identifier that should be used for merging arrays of hashes"
20
+
21
+ def call(source_path:, target_path:, output_path:, **opts)
19
22
  puts "Merging #{source_path} + #{target_path} into #{output_path}"
20
23
 
24
+ identifiers = opts[:identifiers].split(",").map { |s| s.split(":") }.to_h
25
+
21
26
  source = YAML.load_file(source_path)
22
27
  target = YAML.load_file(target_path)
23
28
 
24
- output = deep_merge(source, target)
29
+ output = deep_merge(source, target, identifiers)
25
30
 
26
31
  File.write(output_path, YAML.dump(output))
27
32
  end
28
33
 
29
34
  private
30
35
 
31
- def deep_merge(h1, h2, &block)
36
+ def deep_merge(h1, h2, identifiers, &block)
32
37
  h1.merge(h2) do |key, val1, val2|
33
38
  if val1.is_a?(Hash) && val2.is_a?(Hash)
34
- deep_merge(val1, val2, &block)
39
+ deep_merge(val1, val2, identifiers, &block)
35
40
  elsif val1.is_a?(Array) && val2.is_a?(Array)
36
- (val1 + val2).uniq
41
+ if (id = identifiers[key])
42
+ arr = (val1 + val2)
43
+ .group_by { |el| el.fetch(id) }
44
+ .values
45
+ .map { |arr| arr.size.equal?(2) ? deep_merge(*arr, identifiers) : arr }
46
+ .flatten(1)
47
+ .uniq
48
+
49
+ arr
50
+ .map
51
+ .with_index { |el, idx|
52
+ if (after = el.delete("_after"))
53
+ [el, arr.index(arr.detect { |a| a[id].eql?(after) }) + 1]
54
+ else
55
+ [el, idx]
56
+ end
57
+ }.sort_by(&:last).map(&:first)
58
+ else
59
+ (val1 + val2).uniq
60
+ end
37
61
  else
38
62
  val2
39
63
  end
@@ -1,24 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ossy/cli/commands/core'
4
- require 'ossy/import'
3
+ require "ossy/cli/commands/core"
4
+ require "ossy/import"
5
5
 
6
6
  module Ossy
7
7
  module CLI
8
8
  module Github
9
9
  class Member < Commands::Core
10
- include Import['github.client']
10
+ include Import["github.client"]
11
11
 
12
- desc 'Return org member identified by the full name'
12
+ desc "Return org member identified by the full name"
13
13
 
14
- argument :name, required: true, desc: 'The member name'
15
- argument :org, required: true, desc: 'The org name'
14
+ argument :name, required: true, desc: "The member name"
15
+ argument :org, required: true, desc: "The org name"
16
16
 
17
17
  def call(name:, org:)
18
18
  result = client.member(name, org: org)
19
19
 
20
20
  if result
21
- puts result['login']
21
+ puts result["login"]
22
22
  end
23
23
  end
24
24
  end
@@ -1,26 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ossy/cli/commands/core'
4
- require 'ossy/import'
3
+ require "ossy/cli/commands/core"
4
+ require "ossy/import"
5
5
 
6
6
  module Ossy
7
7
  module CLI
8
8
  module Github
9
9
  class Membership < Commands::Core
10
- include Import['github.client']
10
+ include Import["github.client"]
11
11
 
12
- desc 'Check if a given user has an active membership in a team'
12
+ desc "Check if a given user has an active membership in a team"
13
13
 
14
- argument :username, required: true, desc: 'The username'
15
- argument :org, required: true, desc: 'The name of the org'
16
- argument :team, required: true, desc: 'The name of the team'
14
+ argument :username, required: true, desc: "The username"
15
+ argument :org, required: true, desc: "The name of the org"
16
+ argument :team, required: true, desc: "The name of the team"
17
17
 
18
18
  option :verify, required: false
19
19
 
20
- def call(username:, org:, team:, verify: 'false')
20
+ def call(username:, org:, team:, verify: "false")
21
21
  result = client.membership?(username, org: org, team: team)
22
22
 
23
- if verify.eql?('true')
23
+ if verify.eql?("true")
24
24
  exit(1) unless result
25
25
  else
26
26
  puts "#{username} has active membership in #{org}/@#{team}"
@@ -1,24 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ossy/cli/commands/core'
4
- require 'ossy/import'
3
+ require "ossy/cli/commands/core"
4
+ require "ossy/import"
5
5
 
6
6
  module Ossy
7
7
  module CLI
8
8
  module Github
9
9
  class Tagger < Commands::Core
10
- include Import['github.client']
10
+ include Import["github.client"]
11
11
 
12
- desc 'Return tagger email for a verified tag'
12
+ desc "Return tagger email for a verified tag"
13
13
 
14
- argument :repo, required: true, desc: 'The repo'
15
- argument :tag, required: true, desc: 'The tag name'
14
+ argument :repo, required: true, desc: "The repo"
15
+ argument :tag, required: true, desc: "The tag name"
16
16
 
17
17
  def call(repo:, tag:)
18
18
  result = client.tagger(repo: repo, tag: tag)
19
19
 
20
20
  if result && result[:verified].equal?(true)
21
- puts result[:tagger]['name']
21
+ puts result[:tagger]["name"]
22
22
  end
23
23
  end
24
24
  end
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ossy/cli/commands/core'
4
- require 'open-uri'
3
+ require "ossy/cli/commands/core"
4
+ require "open-uri"
5
5
 
6
6
  module Ossy
7
7
  module CLI
8
8
  module Github
9
9
  class UpdateFile < Commands::Core
10
- desc 'Update provided file using a canonical source in another repository'
10
+ desc "Update provided file using a canonical source in another repository"
11
11
 
12
- argument(:repo, required: true, desc: 'Source repository')
13
- argument(:file, required: true, desc: 'File path ie owner/repo:path/to/file')
14
- option(:branch, required: false, desc: 'Branch name', default: 'master')
12
+ argument(:repo, required: true, desc: "Source repository")
13
+ argument(:file, required: true, desc: "File path ie owner/repo:path/to/file")
14
+ option(:branch, required: false, desc: "Branch name", default: "master")
15
15
 
16
16
  def call(repo:, file:, branch:)
17
17
  url = "https://raw.githubusercontent.com/#{repo}/#{branch}/shared/#{file}"
@@ -1,22 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
3
+ require "json"
4
4
 
5
- require 'ossy/cli/commands/core'
6
- require 'ossy/import'
5
+ require "ossy/cli/commands/core"
6
+ require "ossy/import"
7
7
 
8
8
  module Ossy
9
9
  module CLI
10
10
  module Github
11
11
  class Workflow < Commands::Core
12
- include Import['github.workflow']
12
+ include Import["github.workflow"]
13
13
 
14
- desc 'Start a GitHub workflow'
14
+ desc "Start a GitHub workflow"
15
15
 
16
- argument :repo, required: true, desc: 'The name of the repository on GitHub'
17
- argument :name, required: true, desc: 'The name of the workflow'
16
+ argument :repo, required: true, desc: "The name of the repository on GitHub"
17
+ argument :name, required: true, desc: "The name of the workflow"
18
18
 
19
- option :payload, required: false, desc: 'Optional client payload'
19
+ option :payload, required: false, desc: "Optional client payload"
20
20
 
21
21
  def call(repo:, name:, payload: "{}")
22
22
  puts "Requesting: #{repo} => #{name}"
@@ -24,7 +24,7 @@ module Ossy
24
24
  result = workflow.(repo, name, JSON.load(payload))
25
25
 
26
26
  if result.status.eql?(204)
27
- puts 'Success!'
27
+ puts "Success!"
28
28
  else
29
29
  puts "Failure! #{result.inspect}"
30
30
  end
@@ -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
@@ -0,0 +1,64 @@
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 Releases
14
+ class Context < OpenStruct
15
+ def self.new(data)
16
+ super(releases: data.map(&Release))
17
+ end
18
+
19
+ def latest_release
20
+ releases.first
21
+ end
22
+
23
+ def previous_release
24
+ releases[1]
25
+ end
26
+
27
+ def update(hash)
28
+ hash.each { |k, v| self[k.to_sym] = v }
29
+ self
30
+ end
31
+ end
32
+
33
+ class Generate < Commands::Core
34
+ desc "Generates a release markdown file from a changelog.yml file"
35
+
36
+ argument :config_path, required: true, desc: "The path to the changelog config"
37
+ argument :output_path, required: true, desc: "The path to the output md file"
38
+ argument :template_path, required: true, desc: "The path to the changelog ERB template"
39
+
40
+ option :data_path, required: false, desc: "Optional path to additional data yaml file"
41
+
42
+ def call(config_path:, output_path:, template_path:, data_path: nil)
43
+ puts "Generating #{output_path} from #{config_path} using #{template_path}"
44
+
45
+ ctx_data = YAML.load_file(config_path)
46
+ template = Tilt.new(template_path)
47
+
48
+ context = Context.new(ctx_data)
49
+
50
+ if data_path
51
+ key = File.basename(data_path).gsub(".yml", "")
52
+ data = YAML.load_file(data_path)
53
+
54
+ context.update(key => OpenStruct.new(data))
55
+ end
56
+
57
+ output = template.render(context)
58
+
59
+ File.write(output_path, "#{output.strip}\n")
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/inflector'
4
- require 'ossy/cli/commands/core'
5
- require 'ossy/import'
3
+ require "dry/inflector"
4
+ require "ossy/cli/commands/core"
5
+ require "ossy/import"
6
6
 
7
- require 'tilt'
8
- require 'erb'
9
- require 'yaml'
10
- require 'ostruct'
7
+ require "tilt"
8
+ require "erb"
9
+ require "yaml"
10
+ require "ostruct"
11
11
 
12
12
  module Ossy
13
13
  module CLI
@@ -15,7 +15,7 @@ module Ossy
15
15
  class Compile < Commands::Core
16
16
  class Context < OpenStruct
17
17
  Inflector = Dry::Inflector.new do |i|
18
- i.acronym 'CLI'
18
+ i.acronym "CLI"
19
19
  end
20
20
 
21
21
  def inflector
@@ -23,13 +23,13 @@ module Ossy
23
23
  end
24
24
  end
25
25
 
26
- include Import['github.workflow']
26
+ include Import["github.workflow"]
27
27
 
28
- desc 'Compile an erb template'
28
+ desc "Compile an erb template"
29
29
 
30
- argument :source_path, required: true, desc: 'The path to the template file'
31
- argument :target_path, required: true, desc: 'The path to the output file'
32
- argument :data_file, required: true, desc: 'The path to yaml data file'
30
+ argument :source_path, required: true, desc: "The path to the template file"
31
+ argument :target_path, required: true, desc: "The path to the output file"
32
+ argument :data_file, required: true, desc: "The path to yaml data file"
33
33
 
34
34
  def call(source_path:, target_path:, data_file:)
35
35
  puts "Compiling #{source_path} => #{target_path}"
@@ -1,21 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/system/container'
4
- require 'dry/system/components'
3
+ require "dry/system/container"
4
+ require "dry/system/components"
5
5
 
6
- require 'ossy/types'
6
+ 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
- config.root = Pathname(__dir__).join('../../')
13
+ config.root = Pathname(__dir__).join("../../")
14
14
  config.name = :ossy
15
- config.default_namespace = 'ossy'
15
+ config.default_namespace = "ossy"
16
16
  end
17
17
 
18
- load_paths! 'lib'
18
+ load_paths! "lib"
19
19
 
20
20
  boot(:settings, from: :system) do
21
21
  settings do
@@ -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
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ossy/import'
3
+ require "ossy/import"
4
4
 
5
- require 'faraday'
6
- require 'json'
5
+ require "faraday"
6
+ require "json"
7
7
 
8
8
  module Ossy
9
9
  module Github
10
10
  class Client
11
11
  include Import[:settings]
12
12
 
13
- BASE_URL = 'https://api.github.com'
13
+ BASE_URL = "https://api.github.com"
14
14
 
15
15
  def membership?(username, org:, team:)
16
16
  path = "orgs/#{org}/teams/#{team}/memberships/#{username}"
@@ -20,7 +20,7 @@ module Ossy
20
20
 
21
21
  json = JSON.parse(resp.body)
22
22
 
23
- json['state'].eql?('active')
23
+ json["state"].eql?("active")
24
24
  end
25
25
 
26
26
  def tagger(repo:, tag:)
@@ -29,7 +29,7 @@ module Ossy
29
29
 
30
30
  return false unless resp.status.equal?(200)
31
31
 
32
- sha = JSON.parse(resp.body)['object']['sha']
32
+ sha = JSON.parse(resp.body)["object"]["sha"]
33
33
 
34
34
  path = "repos/#{repo}/git/tags/#{sha}"
35
35
  resp = get(path)
@@ -38,7 +38,7 @@ module Ossy
38
38
 
39
39
  json = JSON.parse(resp.body)
40
40
 
41
- { tagger: json['tagger'], verified: json['verification']['verified'] }
41
+ { tagger: json["tagger"], verified: json["verification"]["verified"] }
42
42
  end
43
43
 
44
44
  def member(name, org:)
@@ -47,11 +47,9 @@ module Ossy
47
47
 
48
48
  return nil unless resp.status.equal?(200)
49
49
 
50
- user = JSON.parse(resp.body)
51
- .map { |member| user(member['login']) }
52
- .detect { |user| user['name'].eql?(name) }
53
-
54
- user
50
+ JSON.parse(resp.body)
51
+ .map { |member| user(member["login"]) }
52
+ .detect { |user| user["name"].eql?(name) }
55
53
  end
56
54
 
57
55
  def user(login)
@@ -82,8 +80,8 @@ module Ossy
82
80
  end
83
81
 
84
82
  def headers
85
- { 'Content-Type' => 'application/json',
86
- 'Accept' => 'application/vnd.github.everest-preview+json' }
83
+ { "Content-Type" => "application/json",
84
+ "Accept" => "application/vnd.github.everest-preview+json" }
87
85
  end
88
86
  end
89
87
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ossy/github/client'
3
+ require "ossy/github/client"
4
4
 
5
5
  module Ossy
6
6
  module Github
data/lib/ossy/import.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ossy/container'
3
+ require "ossy/container"
4
4
 
5
5
  module Ossy
6
6
  Import = Container.injector
data/lib/ossy/release.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ossy/types'
4
- require 'ossy/struct'
3
+ require "ossy/types"
4
+ require "ossy/struct"
5
5
 
6
6
  module Ossy
7
7
  class Release < Ossy::Struct
@@ -12,7 +12,7 @@ module Ossy
12
12
  attribute? :added, Types::ChangeList
13
13
  attribute? :changed, Types::ChangeList
14
14
 
15
- def each(&block)
15
+ def each
16
16
  %i[fixed added changed].each do |type|
17
17
  yield(type, self[type]) unless self[type].empty?
18
18
  end
data/lib/ossy/struct.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/struct'
3
+ require "dry/struct"
4
4
 
5
5
  module Ossy
6
6
  class Struct < Dry::Struct
data/lib/ossy/types.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/types'
3
+ require "dry/types"
4
4
 
5
5
  module Ossy
6
6
  module Types
7
7
  include Dry.Types()
8
8
 
9
- Version = Types::String.constrained(eql: 'unreleased') |
10
- Types::String.constrained(format: %r[\d+\.\d+\.\d+])
9
+ Version = Types::String.constrained(eql: "unreleased") |
10
+ Types::String.constrained(format: /\d+\.\d+\.\d+/)
11
11
 
12
12
  Summary = Types::String.constrained(filled: true).optional
13
13
 
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.1.4'
4
+ VERSION = "0.3.3"
5
5
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ossy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-23 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
- name: dry-inflector
14
+ name: dry-cli
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: '0.5'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.1.2
22
+ version: 0.5.1
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '0.1'
29
+ version: '0.5'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.1.2
32
+ version: 0.5.1
33
33
  - !ruby/object:Gem::Dependency
34
- name: dry-cli
34
+ name: dry-inflector
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.5'
39
+ version: '0.1'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 0.5.1
42
+ version: 0.1.2
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '0.5'
49
+ version: '0.1'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 0.5.1
52
+ version: 0.1.2
53
53
  - !ruby/object:Gem::Dependency
54
- name: dry-types
54
+ name: dry-struct
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - "~>"
@@ -65,33 +65,33 @@ dependencies:
65
65
  - !ruby/object:Gem::Version
66
66
  version: '1.2'
67
67
  - !ruby/object:Gem::Dependency
68
- name: dry-struct
68
+ name: dry-system
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: '1.2'
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: '1.2'
80
+ version: 0.18.1
81
81
  - !ruby/object:Gem::Dependency
82
- name: dry-system
82
+ name: dry-types
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
- version: '0.14'
87
+ version: '1.2'
88
88
  type: :runtime
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
- version: '0.14'
94
+ version: '1.2'
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: faraday
97
97
  requirement: !ruby/object:Gem::Requirement
@@ -166,16 +166,16 @@ dependencies:
166
166
  name: rubocop
167
167
  requirement: !ruby/object:Gem::Requirement
168
168
  requirements:
169
- - - '='
169
+ - - "~>"
170
170
  - !ruby/object:Gem::Version
171
- version: 0.71.0
171
+ version: '1.6'
172
172
  type: :development
173
173
  prerelease: false
174
174
  version_requirements: !ruby/object:Gem::Requirement
175
175
  requirements:
176
- - - '='
176
+ - - "~>"
177
177
  - !ruby/object:Gem::Version
178
- version: 0.71.0
178
+ version: '1.6'
179
179
  description: Ossy is your ruby gem maintenance helper
180
180
  email:
181
181
  - piotr.solnica@gmail.com
@@ -199,8 +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
203
+ - lib/ossy/cli/releases/generate.rb
202
204
  - lib/ossy/cli/templates/compile.rb
203
205
  - lib/ossy/container.rb
206
+ - lib/ossy/engine/rubocop/run.rb
204
207
  - lib/ossy/github/client.rb
205
208
  - lib/ossy/github/workflow.rb
206
209
  - lib/ossy/import.rb
@@ -216,7 +219,7 @@ metadata:
216
219
  homepage_uri: https://github.com/solnic/ossy
217
220
  source_code_uri: https://github.com/solnic/ossy
218
221
  changelog_uri: https://github.com/solnic/ossy
219
- post_install_message:
222
+ post_install_message:
220
223
  rdoc_options: []
221
224
  require_paths:
222
225
  - lib
@@ -231,8 +234,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
234
  - !ruby/object:Gem::Version
232
235
  version: '0'
233
236
  requirements: []
234
- rubygems_version: 3.0.3
235
- signing_key:
237
+ rubygems_version: 3.2.15
238
+ signing_key:
236
239
  specification_version: 4
237
240
  summary: Ossy is your ruby gem maintenance helper
238
241
  test_files: []