cocov_plugin_kit 0.1.1 → 0.1.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: 58a993db2cae820ec262839636dcec32f746ba604fefe2c421fe6ee3f559ec2f
4
- data.tar.gz: 84f5d7cc669b2207405588ff063cedfe76bd585f00af7708fe2268100b8049e9
3
+ metadata.gz: 1a8273e71e6a782ac8eb359fe94f8a4f36214122d738f462427dc0db7ac30d99
4
+ data.tar.gz: 4cb89031486138bd9893297792db58e92fe6099a4ffa43f067635683cf0c8f78
5
5
  SHA512:
6
- metadata.gz: f715fb0d82ee68aef358b981cd6e15ee1cd99feb216d05cf1f138eca85b550c5251c8bd248b14f009d919063379d4b25a0f899188a5156580e6bc1233fc17866
7
- data.tar.gz: '0394e82212fb0fa3f5accb0302c02b0bb9682310f4e7bf162b3410a9fdc43bae18765e4d263dd19004119065c071217549e35a8a509571b5c45d64ff8a0a2d85'
6
+ metadata.gz: 3b59f4546faf3f18b6c45805352f6050f70b3c1cf0b8b436ce4bcbcef6e7fe2ec7a64c3f8c0faf8c0806d244d754ac286c835dac9938a4552153025835d688f9
7
+ data.tar.gz: 751d2360770a35d2e565142d12e502dd1932cc14c26357a305760e7ef95c6a4aae9c63d005f7657630225661014238c015907ae398ac760e0c2ff6ed7dd9440a
data/.rubocop.yml CHANGED
@@ -2,6 +2,15 @@ AllCops:
2
2
  TargetRubyVersion: 2.6
3
3
  NewCops: enable
4
4
 
5
+ Metrics/AbcSize:
6
+ Enabled: false
7
+
8
+ Metrics/MethodLength:
9
+ Enabled: false
10
+
11
+ Metrics/ParameterLists:
12
+ Enabled: false
13
+
5
14
  Style/StringLiterals:
6
15
  Enabled: true
7
16
  EnforcedStyle: double_quotes
@@ -12,3 +21,16 @@ Style/StringLiteralsInInterpolation:
12
21
 
13
22
  Layout/LineLength:
14
23
  Max: 120
24
+ Exclude:
25
+ - plugin_kit.gemspec
26
+
27
+ Metrics/BlockLength:
28
+ Exclude:
29
+ - spec/**/*.rb
30
+
31
+ Lint/RescueException:
32
+ Exclude:
33
+ - lib/cocov/plugin_kit.rb
34
+
35
+ Layout/FirstHashElementIndentation:
36
+ EnforcedStyle: consistent
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cocov_plugin_kit (0.1.1)
4
+ cocov_plugin_kit (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,33 +1,69 @@
1
1
  # PluginKit
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/plugin_kit`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ PluginKit implements a utility library to help the development of Cocov Plugins using the Ruby programming language.
6
4
 
7
5
  ## Installation
8
6
 
9
- Install the gem and add to the application's Gemfile by executing:
7
+ Cocov plugins should not contain Gemfiles. Instead, install the library directly
8
+ using the `gem install` command, providing a specific version. For instance,
9
+
10
+ ```
11
+ gem install cocov_plugin_kit -v 0.1.2
12
+ ```
10
13
 
11
- $ bundle add plugin_kit
14
+ ## Usage
12
15
 
13
- If bundler is not being used to manage dependencies, install the gem by executing:
16
+ ### For simple plugins
14
17
 
15
- $ gem install plugin_kit
18
+ When implementing simple plugins, like for example, [brakeman](https://github.com/cocov-ci/brakeman/blob/master/plugin.rb),
19
+ the block-based usage of PluginKit can be used:
16
20
 
17
- ## Usage
21
+ ```ruby
22
+ Cocov::PluginKit.run do
23
+ output = JSON.parse(exec(["my", "plugin", "--format", "json"], env: ENV))
24
+ # Process output...
25
+ emit_issue kind: # ...
26
+ end
27
+ ```
28
+
29
+ ### For elaborate plugins
30
+
31
+ For plugins requiring more organization or several internal methods, like [rubocop](https://github.com/cocov-ci/rubocop/blob/master/plugin.rb),
32
+ `Cocov::PluginKit::Run` can be inherited into a new class, and `#run` can be
33
+ overridden to be used as the plugin entrypoint, followed by a call to
34
+ `Cocov::PluginKit.run`:
35
+
36
+ ```ruby
37
+ class ElaboratePlugin < Cocov::PluginKit::Run
38
+ def run
39
+ output = JSON.parse(exec(["my", "plugin", "--format", "json"], env: ENV))
40
+ # Process output...
41
+ emit_issue kind: # ...
42
+ end
43
+ end
18
44
 
19
- TODO: Write usage instructions here
45
+ Cocov::PluginKit.run(ElaboratePlugin)
46
+ ```
20
47
 
21
48
  ## Development
22
49
 
23
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+ A `docker-compose.yaml` is provided for allowing Ruby 2.6 to be used without
51
+ requiring developers to install that version on their machines. When writing
52
+ Dockerfiles, developers are advised to use the latest version available when
53
+ building plugins.
24
54
 
25
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+ Use `docker compose run --rm -it ruby bash` to get a shell on the container;
56
+ `bin/setup` can be used to install dependencies, `rspec` to run tests,
57
+ `rubocop` to lint the codebase, and `bin/console` to get an interactive console
58
+ that allows you to experiment.
26
59
 
27
60
  ## Contributing
28
61
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/plugin_kit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/plugin_kit/blob/master/CODE_OF_CONDUCT.md).
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cocov-ci/plugin_kit.
63
+ This project is intended to be a safe, welcoming space for collaboration, and
64
+ contributors are expected to adhere to the [Cocov's code of conduct](https://github.com/cocov-ci/.github/blob/main/CODE_OF_CONDUCT.md).
30
65
 
31
66
  ## Code of Conduct
32
67
 
33
- Everyone interacting in the PluginKit project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/plugin_kit/blob/master/CODE_OF_CONDUCT.md).
68
+ Everyone interacting in the Cocov project's codebases, issue trackers, chat rooms
69
+ and mailing lists is expected to follow the [Cocov's code of conduct](https://github.com/cocov-ci/.github/blob/main/CODE_OF_CONDUCT.md).
data/cocov.output.bin ADDED
File without changes
@@ -2,10 +2,15 @@
2
2
 
3
3
  module Cocov
4
4
  module PluginKit
5
+ # Exec provides utilities for executing processes and obtaining its results.
5
6
  module Exec
7
+ # ExecutionError is thrown when an #exec or #exec2 procedure fails. It
8
+ # includes the captured stdout and stderr streams, along with the exit
9
+ # status, the original command and its environment.
6
10
  class ExecutionError < StandardError
7
11
  attr_reader :stdout, :stderr, :status, :cmd, :env
8
12
 
13
+ # Internal: Initializes a new ExecutionError instance
9
14
  def initialize(status, stdout, stderr, cmd, env)
10
15
  super("Process #{cmd.split.first} exited with status #{status}")
11
16
  @status = status
@@ -18,6 +23,19 @@ module Cocov
18
23
 
19
24
  module_function
20
25
 
26
+ # Public: Executes a given command (represented as an array of strings),
27
+ # returning both its stdout and stderr streams as Strings. Extra options
28
+ # are passed directly to Process.spawn, except :env, which when provided
29
+ # must be a Hash representing environment keys and values.
30
+ # This function will block until the process finishes, either returning
31
+ # both streams (stdout, stderr) as an Array, or raising an ExecutionError.
32
+ #
33
+ # Example:
34
+ #
35
+ # stdout, stderr = Exec::exec2(["git", "version"], chdir: "/tmp")
36
+ # # stdout == "git version 2.30.2\n"
37
+ # # stderr == ""
38
+ #
21
39
  def exec2(cmd, **options)
22
40
  out_reader, out_writer = IO.pipe
23
41
  err_reader, err_writer = IO.pipe
@@ -62,6 +80,9 @@ module Cocov
62
80
  [stdout, stderr]
63
81
  end
64
82
 
83
+ # Public: exec works exactly like #exec2, but only returns the stdout
84
+ # stream, instead of both stdout and stderr.
85
+ # For more information, see the documentation for #exec.
65
86
  def exec(cmd, **options)
66
87
  exec2(cmd, **options).first
67
88
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cocov
4
+ module PluginKit
5
+ # :nodoc:
6
+ class Realloc
7
+ def self.bindings
8
+ secrets_path = Pathname.new("/secrets")
9
+ bindings_path = secrets_path.join("bindings")
10
+ return {} if !bindings_path.exist? || bindings_path.directory?
11
+
12
+ bindings_path.read.split("\0").to_h do |entry|
13
+ from, to = entry.split("=", 2)
14
+ from_path = secrets_path.join(from)
15
+ to_path = Pathname.new(File.expand_path(to))
16
+ [from_path, to_path]
17
+ end
18
+ end
19
+
20
+ def self.mounts!
21
+ bindings.each do |from_path, to_path|
22
+ unless from_path.exist?
23
+ puts "Expected binding of #{from_path} to exist, but could not locate it"
24
+ exit 1
25
+ end
26
+
27
+ to_path.dirname.mkpath
28
+
29
+ FileUtils.cp from_path, to_path
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -2,6 +2,16 @@
2
2
 
3
3
  module Cocov
4
4
  module PluginKit
5
+ # Public: Run implements helpers and prepares the environment for a Plugin
6
+ # runtime. All Cocov Ruby plugins must either inherit this class or directly
7
+ # use it by using the block alternative of Cocov::PluginKit#run.
8
+ #
9
+ # The class provides the following accessors:
10
+ # - workdir: The path to the root of the repository being checked. The
11
+ # plugin is always executed with its pwd set to this path.
12
+ # - repo_name: The name of the repository being cheked.
13
+ # - commit_sha: The SHA of the commit being checked.
14
+ #
5
15
  class Run
6
16
  attr_reader :workdir, :repo_name, :commit_sha
7
17
 
@@ -13,23 +23,34 @@ module Cocov
13
23
  @output_file = output_file
14
24
  end
15
25
 
26
+ # Public: When inheriting this class, the plugin entrypoint must be
27
+ # implemented on this method's override.
16
28
  def run; end
17
29
 
30
+ # Public: Alias to Exec.exec2. For more information, see the documentation
31
+ # for that method.
18
32
  def exec2(cmd, **options)
19
33
  Exec.exec2(cmd, **options)
20
34
  end
21
35
 
36
+ # Public: Alias to Exec.exec. For more information, see the documentation
37
+ # for that method.
22
38
  def exec(cmd, **options)
23
39
  Exec.exec(cmd, **options)
24
40
  end
25
41
 
42
+ # Public: Returns the SHA1 digest of the provided data
26
43
  def sha1(data)
27
44
  Digest::SHA1.hexdigest(data)
28
45
  end
29
46
 
30
- ALLOWED_KINDS = %i[style performance security bug complexity duplication].freeze
47
+ # :nodoc:
48
+ ALLOWED_KINDS = %i[style performance security bug complexity duplication convention].freeze
31
49
 
32
- def emit_issue(kind:, file:, line_start:, line_end:, message:, uid: nil)
50
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
51
+
52
+ # :nodoc:
53
+ def validate_issue_args!(kind:, file:, line_start:, line_end:, message:, uid:)
33
54
  unless ALLOWED_KINDS.include? kind
34
55
  raise ArgumentError, "Invalid kind `#{kind}'. Valid options are #{ALLOWED_KINDS.join(", ")}"
35
56
  end
@@ -44,10 +65,35 @@ module Cocov
44
65
 
45
66
  raise ArgumentError, "message must be a non-empty string" if !message.is_a?(String) || message.strip == ""
46
67
 
47
- if !uid.nil? && (!uid.is_a?(String) || uid.strip == "")
48
- raise ArgumentError, "uid must be a non-empty string when provided"
49
- end
68
+ return unless !uid.nil? && (!uid.is_a?(String) || uid.strip == "")
50
69
 
70
+ raise ArgumentError, "uid must be a non-empty string when provided"
71
+ end
72
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
73
+
74
+ # Public: Emits a new issue with the provided arguments.
75
+ #
76
+ # kind: - A symbol identifying kind of the issue being emitted.
77
+ # file: - The path, relative to the repository root, of the file
78
+ # where the issue was found.
79
+ # line_start: - The first line where the issue was found. Must be greater
80
+ # than zero.
81
+ # line_end: - The last line where the issue was found. Must be equal or
82
+ # greater than the value of line_start.
83
+ # message: - A message describing the issue. Must not be empty.
84
+ # uid: - An uniquely identifier representing this issue among any
85
+ # other possible issue in any other file in this repository.
86
+ # This identifier must be the result of a pure function;
87
+ # i.e. the same issue in the same file, spanning the same
88
+ # lines must have the same uid no matter how many times it
89
+ # is reported. If omitted, an UID is automatically
90
+ # calculated. If provided, must be a non-empty string.
91
+ #
92
+ # Returns nothing. Raises ArgumentError in case invalid data is provided
93
+ # (see documentation above.)
94
+ def emit_issue(kind:, file:, line_start:, line_end:, message:, uid: nil)
95
+ validate_issue_args! kind: kind, file: file, line_start: line_start,
96
+ line_end: line_end, message: message, uid: uid
51
97
  data = {
52
98
  kind: kind,
53
99
  file: file,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cocov
4
4
  module PluginKit
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
@@ -8,21 +8,29 @@ require "tempfile"
8
8
  require "tmpdir"
9
9
 
10
10
  require_relative "plugin_kit/version"
11
- require_relative "plugin_kit/run"
12
11
  require_relative "plugin_kit/exec"
12
+ require_relative "plugin_kit/realloc"
13
+ require_relative "plugin_kit/run"
13
14
 
14
15
  module Cocov
16
+ # PluginKit implements helpers for implementing Cocov Plugins in Ruby. The
17
+ # main module provides a single run function that must be used to wrap the
18
+ # plugin runtime, and is responsible for preparing the environment and running
19
+ # the provided block
15
20
  module PluginKit
16
- class Error < StandardError; end
17
-
18
21
  module_function
19
22
 
23
+ # Public: Prepares the environment and executes a given `klass` (Class) or
24
+ # a single block. When `klass` is not provided, PluginKit::Run is used.
25
+ # When providing a custom class, make sure to inherit PluginKit::Run.
26
+ # For examples, see the library's README file.
20
27
  def run(klass = nil, &block)
21
28
  output_file = File.open(ENV.fetch("COCOV_OUTPUT_FILE"), "w")
22
29
  exit_code = 0
23
30
  klass ||= Run
24
31
  instance = klass.new(output_file)
25
32
  Dir.chdir(instance.workdir) do
33
+ Realloc.mounts!
26
34
  if block_given?
27
35
  instance.instance_exec(&block)
28
36
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocov_plugin_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Gama
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-04 00:00:00.000000000 Z
11
+ date: 2023-01-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: PluginKit implements helpers for running Cocov plugins
14
14
  email:
@@ -21,15 +21,16 @@ files:
21
21
  - ".editorconfig"
22
22
  - ".rspec"
23
23
  - ".rubocop.yml"
24
- - CODE_OF_CONDUCT.md
25
24
  - Gemfile
26
25
  - Gemfile.lock
27
26
  - LICENSE
28
27
  - README.md
29
28
  - Rakefile
29
+ - cocov.output.bin
30
30
  - exe/cocov
31
31
  - lib/cocov/plugin_kit.rb
32
32
  - lib/cocov/plugin_kit/exec.rb
33
+ - lib/cocov/plugin_kit/realloc.rb
33
34
  - lib/cocov/plugin_kit/run.rb
34
35
  - lib/cocov/plugin_kit/version.rb
35
36
  homepage: https://github.com/cocov-ci/plugin_kit
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hey@vito.io. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.