threat 1.0.3 → 1.2.0

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: acf5d5350c0b8e527c2347910603a1079129f1451f9f8e540aff7dd8e291980a
4
- data.tar.gz: dba33d9ebcd83085bc21d4d1909d359283bf282f040c9a8a839e7fb780b3afd7
3
+ metadata.gz: 336fc3bbb30c8e9701d462989aa9bcdd9d5eba680b95e39d95b07d030cb04acf
4
+ data.tar.gz: a7e6878b4251494be015c66bbbffaa910ee9d9c1d2155ba4068e5491e17b9e50
5
5
  SHA512:
6
- metadata.gz: bbf4f9909099e32bf249c1d028856f530befa866cfb700afbb083c0d8f340686092207f03cc71aae0a40a3fe0b5c2bce64afa8c3ec159ff2ccdde66e7d757eac
7
- data.tar.gz: 9da87b474d3c6fd24d0c066a847adc175c63ea70a52ee4ae5a0599c184e4cbb94703eb700401d7aaae472397d3ce14c464daffb2412d9778f3aea3702f42411d
6
+ metadata.gz: 4cd286f8ce2f0ba952ccc23c3824aacc863cfb7ac4b12aefb200b4e2389d3e857601a81301341f6950005c42b9ff16e24a2d58daca4d17e95906443e08337104
7
+ data.tar.gz: 7305af20c0f9aee1c0f444aca69a575a0ad7ac9fdc9da02ae352d96cc01488a08eccc1b8103c5260050193d0002bc058ff20e2588cdd94c77c6292045d00d1cf
data/Dangerfile CHANGED
@@ -2,4 +2,35 @@
2
2
 
3
3
  require 'threat'
4
4
 
5
+ # This way we're autoloading all defined plugins for Danger to register
6
+ Threat.loader.eager_load_namespace(Threat::Plugins)
7
+
5
8
  refresh_plugins
9
+
10
+ ENVIRONMENT_MAPPING = {
11
+ Danger::RequestSources::LocalOnly => 'local',
12
+ Danger::RequestSources::GitHub => 'github'
13
+ }.freeze
14
+
15
+ # This is a simple way to run a plugins only when the Dangerfile is executed in a specific environment
16
+ #
17
+ # P.S This method is added to the top-level scope of your Dangerfile
18
+ def on(environment_name)
19
+ return unless ENVIRONMENT_MAPPING[env.request_source.class] == environment_name.to_s
20
+
21
+ yield
22
+ end
23
+
24
+ # This is a simple way to run only a part of your Dangerfile
25
+ #
26
+ # P.S This method is added to the top-level scope of your Dangerfile
27
+ def workflow(workflow_name)
28
+ return if (current_workflow = ENV['DANGER_WORKFLOW']) &&
29
+ (workflow_name.to_s != current_workflow)
30
+
31
+ yield
32
+ end
33
+
34
+ def rake(*tasks)
35
+ system("bundle exec rake #{tasks.join(' ')}")
36
+ end
data/README.md CHANGED
@@ -1 +1,120 @@
1
- # Threat - Collection of useful Danger plugins
1
+ # Threat
2
+
3
+ Collection of useful Danger plugins which intends to help you get up and running with Danger faster
4
+
5
+ Danger itself - https://danger.systems
6
+
7
+ ## Usage
8
+
9
+ All you need to do to start using Threat is:
10
+
11
+ 1. Add it to your Gemfile
12
+
13
+ ```ruby
14
+ group :development, :test do
15
+ gem 'threat', require: false
16
+ end
17
+ ```
18
+
19
+ 2. Bundle
20
+
21
+ ```sh
22
+ bundle install
23
+ ```
24
+
25
+ 3. Import it into your Dangerfile
26
+
27
+ ```ruby
28
+ danger.import_dangerfile(gem: 'threat')
29
+ ```
30
+
31
+ 4. Create a GitHub workflow which will run your Dangerfile when the PR is opened/updated
32
+
33
+ ```yaml
34
+ # .github/workflows/ci.yml
35
+
36
+ name: CI
37
+
38
+ on:
39
+ pull_request:
40
+ branches:
41
+ - master
42
+
43
+ concurrency:
44
+ group: ${{ github.workflow }}-${{ github.ref }}
45
+ cancel-in-progress: true
46
+
47
+ # https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
48
+ permissions:
49
+ actions: write
50
+ checks: write
51
+ contents: read
52
+ statuses: write
53
+ pull-requests: write
54
+
55
+ jobs:
56
+ danger:
57
+ runs-on: ubuntu-latest
58
+ steps:
59
+ - uses: actions/checkout@v4
60
+ with:
61
+ fetch-depth: 0
62
+
63
+ - name: Set up Ruby
64
+ uses: ruby/setup-ruby@v1
65
+ with:
66
+ ruby-version: 3.3.1
67
+ bundler-cache: true
68
+
69
+ - name: Run Danger
70
+ env:
71
+ DANGER_GITHUB_API_TOKEN: ${{ github.token }}
72
+ run: bundle exec danger
73
+
74
+ ```
75
+
76
+ ## Available plugins
77
+
78
+ 1. PR Title
79
+
80
+ Validates that the Pull Request title is in correct format, containing JIRA ticket number and a meaningful short description. This works best when combined with "use pr title" + squash and merge strategy in GitHub
81
+
82
+ ```ruby
83
+ # Dangerfile
84
+
85
+ danger.import_dangerfile(gem: 'threat')
86
+
87
+ pr_title.run!
88
+ ```
89
+
90
+ 2. TODO
91
+
92
+ Checks if there are TODOs in PR diff. Can be improved by adding logic that will check if TODO was introduced in the PR itself, in this case warning message could be rephrased
93
+
94
+ ```ruby
95
+ # Dangerfile
96
+
97
+ danger.import_dangerfile(gem: 'threat')
98
+
99
+ todo.run!
100
+ ```
101
+
102
+ 3. Confetti 🎉
103
+
104
+ Just add the following line at the bottom of your Dangerfile to celebrate a good run!
105
+
106
+ ```ruby
107
+ # Dangerfile
108
+
109
+ danger.import_dangerfile(gem: 'threat')
110
+
111
+ # The rest of your Dangerfile goes here...
112
+
113
+ confetti.run! unless failed?
114
+ ```
115
+
116
+ P.S [Raycast](https://www.raycast.com/) and macOS is required (not a paid promotion) (sorry @dhh)
117
+
118
+ ## Contributing
119
+
120
+ Yes, please 🥺
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # macOS and Raycast (https://www.raycast.com/) are required to celebrate a good run with confetti
4
+ #
5
+ # Usage:
6
+ #
7
+ # Dangerfile
8
+ #
9
+ # ```ruby
10
+ # danger.import_dangerfile(gem: 'threat')
11
+ #
12
+ # # The rest of your Dangerfile goes here...
13
+ #
14
+ # confetti.run! unless failed?
15
+ # ```
16
+ #
17
+ class Threat::Plugins::Confetti < Danger::Plugin
18
+ DEEPLINK = 'raycast://confetti'
19
+
20
+ def run!
21
+ return unless RUBY_PLATFORM =~ /darwin/
22
+
23
+ system("open #{DEEPLINK}", err: File::NULL)
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Threat::Plugins::PluginSet < Danger::Plugin
4
+ def rails_lint
5
+ rubocop.run!
6
+ todo.run!
7
+ end
8
+ end
@@ -17,8 +17,9 @@ class Threat::Plugins::PrTitle < Danger::Plugin
17
17
  PR_TITLE_REGEX = /\[#{JIRA_TICKET_NUMBER_FORMAT}\] [A-Z|0-9].*\S/ # [KEY-123] An amazing feature
18
18
 
19
19
  def run!
20
- # This check is available for pull requests only
21
- return unless env.pr?
20
+ # This check is available for GitHub pull requests only
21
+ return unless env.request_source.instance_of?(Danger::RequestSources::GitHub) &&
22
+ env.pr?
22
23
 
23
24
  failure('Invalid format of PR title') unless github.pr_title.strip.match?(PR_TITLE_REGEX)
24
25
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+
5
+ # This plugin runs RSpec and reports failing examples
6
+ #
7
+ # Usage:
8
+ #
9
+ # Dangerfile
10
+ #
11
+ # ```ruby
12
+ # danger.import_dangerfile(gem: 'threat')
13
+ #
14
+ # rspec.run!
15
+ # ```
16
+ #
17
+ class Threat::Plugins::Rspec < Danger::Plugin
18
+ FAILING_SPECS_LOG = 'tmp/failing_specs.log'
19
+ SEPARATOR = ':'
20
+
21
+ def run!
22
+ `bundle exec rspec -f failures --out #{FAILING_SPECS_LOG}`
23
+ return if $CHILD_STATUS.exitstatus.zero?
24
+
25
+ File.readlines(FAILING_SPECS_LOG).each do |line|
26
+ file_path, line_number, example = line.split(SEPARATOR)
27
+
28
+ failure("Example #{example.strip} failed at #{file_path.delete_prefix('./')}:#{line_number}")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This plugin runs Ribocop and warns about found violations
4
+ #
5
+ # Usage:
6
+ #
7
+ # Dangerfile
8
+ #
9
+ # ```ruby
10
+ # danger.import_dangerfile(gem: 'threat')
11
+ #
12
+ # rspec.run!
13
+ # ```
14
+ #
15
+ class Threat::Plugins::Rubocop < Danger::Plugin
16
+ def run!
17
+ files_to_lint = git.modified_files + git.added_files
18
+
19
+ result = `bundle exec rubocop --force-exclusion --format json #{files_to_lint.join(' ')}`
20
+ return if $CHILD_STATUS.exitstatus.zero?
21
+
22
+ json_result = JSON.parse(result)
23
+
24
+ json_result['files'].each do |file|
25
+ file_path = file['path']
26
+
27
+ file['offenses'].each do |offence|
28
+ line = offence.dig('location', 'line')
29
+
30
+ warn("Rubocop: #{offence['message']} at #{file_path}:#{line}")
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # This plugin searches for TODO comments in the codebase
4
+ #
5
+ # TODO: May be improved by posting different messages for cases when TODO was just introduced in current diff and when
6
+ # contributor just touched a file with existing TODO
7
+ #
8
+ # Usage:
9
+ #
10
+ # Dangerfile
11
+ #
12
+ # ```ruby
13
+ # danger.import_dangerfile(gem: 'threat')
14
+ #
15
+ # todo.run!
16
+ # ```
17
+ #
3
18
  class Threat::Plugins::Todo < Danger::Plugin
4
19
  SUPPORTED_COMMENTS = [
5
20
  '#', # e.g Ruby/YAML/Dockerfile and so on
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Threat
4
- VERSION = '1.0.3'
4
+ VERSION = '1.2.0'
5
5
  end
data/lib/threat.rb CHANGED
@@ -4,8 +4,11 @@ require 'zeitwerk'
4
4
  require 'danger'
5
5
 
6
6
  module Threat
7
+ module_function
8
+
9
+ def loader
10
+ @loader ||= Zeitwerk::Loader.for_gem
11
+ end
7
12
  end
8
13
 
9
- loader = Zeitwerk::Loader.for_gem
10
- loader.setup
11
- loader.eager_load_namespace(Threat::Plugins) # This way we're autoloading all defined plugins for Danger to register
14
+ Threat.loader.setup
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: threat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Egor Iskrenkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-09 00:00:00.000000000 Z
11
+ date: 2024-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -48,7 +48,11 @@ files:
48
48
  - Dangerfile
49
49
  - README.md
50
50
  - lib/threat.rb
51
+ - lib/threat/plugins/confetti.rb
52
+ - lib/threat/plugins/plugin_set.rb
51
53
  - lib/threat/plugins/pr_title.rb
54
+ - lib/threat/plugins/rspec.rb
55
+ - lib/threat/plugins/rubocop.rb
52
56
  - lib/threat/plugins/todo.rb
53
57
  - lib/threat/version.rb
54
58
  homepage: https://github.com/eiskrenkov/threat