netsoft-danger 0.3.5 → 0.4.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: 2b7b3e2a4fbfa992da4950813e78d8276a5f8055b4b09987d36b62b761134f8a
4
- data.tar.gz: e7f4046f836e76a11c5fcb5e37b31acdf664e921f506f8f7312a489852418168
3
+ metadata.gz: 456103b5d2e1de2010b9b7872ad35e05dd9280ccf2895626362750a5024abaa6
4
+ data.tar.gz: c57c9638ae3d747d64dfeb492ca75e68b6380d63b7f4bef38d2d90d6af9a37c8
5
5
  SHA512:
6
- metadata.gz: 2cde3fa84fa78f571710f9d52d4508410550f0e30d7795e5f925aca31902453e328ccb332db3fb003bcfd692a22a55a470eff5ed0859a87492131b5c3636aa76
7
- data.tar.gz: 38b61ca91282d42ba78b2bd7752f0be930fc1790f751bfb7c1e53e4772d66ca74dcf3d5e756aeb8011c6da009340bbacd436c7969f1030cce123ea406aefe8d1
6
+ metadata.gz: 12e7f27cd942a9bb9d9c425fc1ecbdca8a443076dabdb51a9770577ff67441bd2612b16a16d700bfd6f3e18e7ff2273b7a7105af1b56a0356b67bf5374451c65
7
+ data.tar.gz: 992cc446f38681c82f12b8d1191df42872717c84512c9185939f1ee5671d9099d0871592d936214e797e0e9f09cf6cc0f08eb2208b97946006ad20e2e78e8f1f
@@ -111,6 +111,10 @@ jobs:
111
111
  name: Build gem
112
112
  command: |-
113
113
  gem build *.gemspec
114
+ - run:
115
+ name: Run rubocop
116
+ command: |-
117
+ bundle exec rubocop
114
118
  - run:
115
119
  name: Run Danger
116
120
  command: |-
@@ -0,0 +1,15 @@
1
+ inherit_gem:
2
+ netsoft-rubocop:
3
+ - default.yml
4
+
5
+ Style/SignalException:
6
+ Exclude:
7
+ - Dangerfile
8
+
9
+ Style/IfUnlessModifier:
10
+ Exclude:
11
+ - Dangerfile
12
+
13
+ Layout/EmptyLineAfterGuardClause:
14
+ Exclude:
15
+ - Dangerfile
@@ -9,6 +9,31 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
9
9
  ### Changed
10
10
  ### Fixed
11
11
 
12
+ ## [0.4.0]
13
+ ### Fixed
14
+ - correct simplecov merge on newer simplecov release
15
+
16
+ ## [0.3.9]
17
+ ### Fixed
18
+ - correct API call to github for adding labels and fix logic in determining if we should or should not add the label
19
+
20
+ ## [0.3.8]
21
+ ### Added
22
+ - auto add/remove some labels
23
+ - allow conventional commit format for our migration, gemfile, and package.json
24
+ - add support for product review labels
25
+ - add support for renamed code review labels
26
+
27
+ ## [0.3.7]
28
+ ### Fixed
29
+ - require English in the netsoft-circle bin
30
+
31
+ ## [0.3.6]
32
+ ### Added
33
+ - rubocop checks for this gem
34
+ ### Changed
35
+ - allow bundler 1.17.3
36
+
12
37
  ## [0.3.5]
13
38
  ### Added
14
39
  - package.json checks
data/Dangerfile CHANGED
@@ -1,118 +1,156 @@
1
+ # frozen_string_literal: true
2
+
3
+ def toggle_label(github, label, should_set)
4
+ repo_name = github.pr_json['head']['repo']['full_name']
5
+ pr_number = github.pr_json['number']
6
+ has_label = github.pr_labels.include?(label)
7
+
8
+ if should_set && !has_label
9
+ github.api.add_labels_to_an_issue(repo_name, pr_number, [label])
10
+ elsif !should_set && has_label
11
+ github.api.remove_label(repo_name, pr_number, label)
12
+ end
13
+ end
14
+
1
15
  # Don't let testing shortcuts get into master by accident
2
- if Dir.exists?('spec')
3
- fail("fdescribe left in tests") if `grep -r -e '\\bfdescribe\\b' spec/ |grep -v 'danger ok' `.length > 1
4
- fail("fcontext left in tests") if `grep -r -e '\\bfcontext\\b' spec/ |grep -v 'danger ok' `.length > 1
5
- fail("fit left in tests") if `grep -r -e '\\bfit\\b' spec/ | grep -v 'danger ok' `.length > 1
6
- fail("ap left in tests") if `grep -r -e '\\bap\\b' spec/ | grep -v 'danger ok' `.length > 1
7
- fail("puts left in tests") if `grep -r -e '\\bputs\\b' spec/ | grep -v 'danger ok' `.length > 1
16
+ if Dir.exist?('spec')
17
+ fail('fdescribe left in tests') if `grep -r -e '\\bfdescribe\\b' spec/ |grep -v 'danger ok' `.length > 1
18
+ fail('fcontext left in tests') if `grep -r -e '\\bfcontext\\b' spec/ |grep -v 'danger ok' `.length > 1
19
+ fail('fit left in tests') if `grep -r -e '\\bfit\\b' spec/ | grep -v 'danger ok' `.length > 1
20
+ fail('ap left in tests') if `grep -r -e '\\bap\\b' spec/ | grep -v 'danger ok' `.length > 1
21
+ fail('puts left in tests') if `grep -r -e '\\bputs\\b' spec/ | grep -v 'danger ok' `.length > 1
8
22
  end
9
23
 
10
- if File.exists?('Gemfile')
24
+ if File.exist?('Gemfile')
11
25
  if `grep -r -e "^ *gem 'hubstaff_[a-z]\\+" Gemfile | grep -e ",.\\+[a-zA-Z]" `.length > 1
12
- fail("[gemfile] Beta hubstaff_* gems are not allowed in master/production")
26
+ fail('gemfile: Beta hubstaff_* gems are not allowed in master/production')
13
27
  end
14
28
  if `grep -r -e "^ *gem 'hubstaff_[a-z]\\+" Gemfile | grep -e ",.\\+'[~>=]\\+.\\+[a-zA-Z]" `.length > 1
15
- fail("[gemfile] Beta hubstaff_* gems should be the exact version")
29
+ fail('gemfile: Beta hubstaff_* gems should be the exact version')
16
30
  end
17
31
  if `grep -r -e "^ *gem 'hubstaff_[a-z]\\+" Gemfile | grep -e ",.\\+[' ][0-9.]\\+'" | grep -v '~>' `.length > 1
18
- fail("[gemfile] Release hubstaff_* gems should be using a ~> version")
32
+ fail('gemfile: Release hubstaff_* gems should be using a ~> version')
19
33
  end
20
34
  end
21
35
 
36
+ if github.branch_for_head.start_with?('security')
37
+ toggle_label(github, 'security', true)
38
+ end
39
+
40
+ should_have_migration_label = false
41
+
22
42
  git.commits.each do |c|
23
- short = " ( #{c.sha[0..7]} )"
24
- has_migrations = c.diff_parent.any? {|f| f.path =~ /db\/migrate\// }
25
- has_schema_changes = c.diff_parent.any? {|f| f.path =~ /db\/schema\.rb/ }
26
- has_migration_msg = c.message =~ /\A\[migration\]/
27
- no_schema_ok = ENV['DANGER_NO_SCHEMA_OK'] || false
43
+ short = " ( #{c.sha[0..7]} )"
44
+ has_migrations = c.diff_parent.any? { |f| f.path =~ %r{db/migrate/} }
45
+ has_schema_changes = c.diff_parent.any? { |f| f.path =~ %r{db/schema\.rb} }
46
+ old_migration_msg = c.message.start_with?('[migration]')
47
+ has_migration_msg = old_migration_msg || c.message.match?(/\Amigration(\([A-Za-z]+\))?:/)
48
+ no_schema_ok = ENV['DANGER_NO_SCHEMA_OK'] || false
28
49
  if has_migrations || has_schema_changes
29
50
  unless has_migration_msg
30
- fail '[migration] Schema migration commits need to be prefixed with [migration]' + short
51
+ fail 'migration: Schema migration commits needs to be tagged with (migration). e.g. migration(Module): ' + short
52
+ end
53
+ if old_migration_msg
54
+ warn 'migration: Please switch to the new conventional commit format.'
31
55
  end
32
56
  if has_migrations && !has_schema_changes && !no_schema_ok
33
- fail '[migration] Please checkin your schema.rb changes with your migration' + short
57
+ fail 'migration: Please checkin your schema.rb changes with your migration' + short
34
58
  end
35
59
  if !has_migrations && has_schema_changes
36
- warn '[migration] Please checkin your migrations with your schema.rb changes' + short
60
+ warn 'migration: Please checkin your migrations with your schema.rb changes' + short
37
61
  end
38
- if c.diff_parent.any? {|f| !( f.path =~ /db\/migrate\/|db\/schema\.rb/ ) }
39
- fail '[migration] Migration commit contains non-migration changes' + short
62
+ if c.diff_parent.any? { |f| f.path !~ %r{db/migrate/|db/schema\.rb} }
63
+ fail 'migration: Migration commit contains non-migration changes' + short
40
64
  end
65
+
66
+ should_have_migration_label = true
41
67
  elsif has_migration_msg
42
68
  fail '[migration] Migration commit with no migrations!' + short
43
69
  end
44
70
 
45
- has_hubstaff_icon_changes = c.diff_parent.any? {|f| f.path =~ /hubstaff(icons|font)|fontcustom-manifest/ }
71
+ has_hubstaff_icon_changes = c.diff_parent.any? { |f| f.path =~ /hubstaff(icons|font)|fontcustom-manifest/ }
46
72
  if has_hubstaff_icon_changes
47
- if c.diff_parent.any? {|f| !( f.path =~ /hubstaff-(icons|font)/ || f.path =~ /fontcustom-manifest/ ) }
48
- fail '[hubstaff-icons] Put hubstaff-icon changes into their own commit' + short
73
+ if c.diff_parent.any? { |f| !(f.path =~ /hubstaff-(icons|font)/ || f.path =~ /fontcustom-manifest/) }
74
+ fail 'hubstaff-icons: Put hubstaff-icon changes into their own commit' + short
49
75
  end
50
76
  end
51
77
 
52
- has_gemfile_changes = c.diff_parent.any? {|f| f.path =~ /Gemfile|gemspec/ }
53
- has_gemfile_msg = c.message =~ /\A\[gemfile\]/
78
+ has_gemfile_changes = c.diff_parent.any? { |f| f.path =~ /Gemfile|gemspec/ }
79
+ old_gemfile_msg = c.message.start_with?('[gemfile]')
80
+ has_gemfile_msg = old_gemfile_msg || c.message.match?(/\Agemfile(\([A-Za-z]+\))?:/)
54
81
  if has_gemfile_changes
55
82
  unless has_gemfile_msg
56
- fail '[gemfile] Gemfile commits need to be prefixed with [gemfile] ' + short
83
+ fail 'gemfile: Gemfile commits needs to be tagged with (gemfile). e.g. gemfile(Module): ' + short
84
+ end
85
+ if old_migration_msg
86
+ warn 'gemfile: Please switch to the new conventional commit format.'
57
87
  end
58
- if c.diff_parent.any? {|f| !( f.path =~ /Gemfile|gemspec/ ) }
59
- fail '[gemfile] Gemfile commit contains non-gemfile changes' + short
88
+ if c.diff_parent.any? { |f| f.path !~ /Gemfile|gemspec/ }
89
+ fail 'gemfile: Gemfile commit contains non-gemfile changes' + short
60
90
  end
61
- if c.diff_parent.any? {|f| f.path == 'Gemfile.lock' }
62
- unless `grep -e '^ 1.15.2$' Gemfile.lock`.length > 1
63
- fail("[gemfile] Gemfile not bundled with bundler 1.15.2")
91
+ if c.diff_parent.any? { |f| f.path == 'Gemfile.lock' }
92
+ unless `grep -E -- '^BUNDLED WITH\s*\n\s+(1\\.15\\.2|1\\.17\\.3)$' Gemfile.lock`.length > 1
93
+ fail('gemfile: Gemfile not bundled with bundler 1.15.2 or 1.17.3')
64
94
  end
65
95
  end
66
96
  elsif has_gemfile_msg
67
- fail '[gemfile] Gemfile commit has no gemfile changes!' + short
97
+ fail 'gemfile: Gemfile commit has no gemfile changes!' + short
68
98
  end
69
99
 
70
- has_package_changes = c.diff_parent.any? {|f| f.path =~ /package\.json|yarn\.lock/ }
71
- has_package_msg = c.message =~ /\A\[package\.json\]/
100
+ has_package_changes = c.diff_parent.any? { |f| f.path =~ /package\.json|yarn\.lock/ }
101
+ old_package_msg = c.message.start_with?('[package.json]')
102
+ has_package_msg = old_package_msg || c.message.match?(/\Apackage(\([A-Za-z]+\))?:/)
72
103
  if has_package_changes
73
104
  unless has_package_msg
74
- fail '[package.json] Package.json commits need to be prefixed with [package.json] ' + short
105
+ fail 'package: Package.json commits needs to be tagged with package. e.g package(Module): ' + short
106
+ end
107
+ if old_package_msg
108
+ warn 'package: Please switch to the new conventional commit format.'
75
109
  end
76
- if c.diff_parent.any? {|f| !( f.path =~ /package\.json|yarn\.lock/ ) }
77
- fail '[package.json] Package.json commit contains non-package changes' + short
110
+ if c.diff_parent.any? { |f| f.path !~ /package\.json|yarn\.lock/ }
111
+ fail 'package: Package.json commit contains non-package changes' + short
78
112
  end
79
113
  elsif has_package_msg
80
- fail '[package.json] Pacakge.json commit has no package changes!' + short
114
+ fail 'package: Pacakge.json commit has no package changes!' + short
81
115
  end
82
116
  end
83
117
 
84
- require 'open-uri'
85
-
86
- artifact_url = "https://circleci.com/api/v1.1/project/github/#{ENV['CIRCLE_PROJECT_USERNAME']}/#{ENV["CIRCLE_PROJECT_REPONAME"]}/#{ENV['CIRCLE_BUILD_NUM']}/artifacts?circle-token=#{ENV['CIRCLE_TOKEN']}"
87
- artifacts = JSON.load(open(artifact_url).read).map{|a| a["url"]}
88
-
89
- jest = artifacts.find{ |artifact| artifact.end_with?('jest/index.html') }
90
- coverage = artifacts.find{ |artifact| artifact.end_with?('coverage/index.html') }
91
- rubocop = artifacts.find{ |artifact| artifact.end_with?('rubocop/report.html') }
92
- eslint = artifacts.find{ |artifact| artifact.end_with?('eslint/report.html') }
93
- rspec_files = artifacts.select{ |artifact| artifact =~ /rspec-(.+)\.html$/ }
94
-
95
- {}.tap do |hash|
96
- hash['Ruby coverage report'] = coverage if coverage
97
- hash['RSpec test report'] = rspec_files unless rspec_files.empty?
98
- hash['RuboCop inspection report'] = rubocop if rubocop
99
- hash['ESLint inspection report'] = eslint if eslint
100
- hash['Jest coverage report'] = jest if jest
101
- end.each do |msg, links|
102
- links = [*links]
103
- if links.size == 1
104
- message("[#{msg}](#{links[0]})")
105
- else
106
- r = /rspec-(.+)\.html$/
107
- the_links = links.map do |l|
108
- m = r.match(l)
109
- if m
110
- "[#{m[1]}](#{l})"
111
- else
112
- "[link](#{l})"
113
- end
114
- end.join(', ')
118
+ toggle_label(github, 'run migration', should_have_migration_label)
119
+
120
+ if ENV['CIRCLE_TOKEN']
121
+ require 'open-uri'
115
122
 
116
- message("#{msg} - #{the_links}")
123
+ artifact_url = "https://circleci.com/api/v1.1/project/github/#{ENV['CIRCLE_PROJECT_USERNAME']}/#{ENV['CIRCLE_PROJECT_REPONAME']}/#{ENV['CIRCLE_BUILD_NUM']}/artifacts?circle-token=#{ENV['CIRCLE_TOKEN']}"
124
+ artifacts = JSON.parse(URI.parse(artifact_url).read).map { |a| a['url'] }
125
+
126
+ jest = artifacts.find { |artifact| artifact.end_with?('jest/index.html') }
127
+ coverage = artifacts.find { |artifact| artifact.end_with?('coverage/index.html') }
128
+ rubocop = artifacts.find { |artifact| artifact.end_with?('rubocop/report.html') }
129
+ eslint = artifacts.find { |artifact| artifact.end_with?('eslint/report.html') }
130
+ rspec_files = artifacts.select { |artifact| artifact =~ /rspec-(.+)\.html$/ }
131
+
132
+ {}.tap do |hash|
133
+ hash['Ruby coverage report'] = coverage if coverage
134
+ hash['RSpec test report'] = rspec_files unless rspec_files.empty?
135
+ hash['RuboCop inspection report'] = rubocop if rubocop
136
+ hash['ESLint inspection report'] = eslint if eslint
137
+ hash['Jest coverage report'] = jest if jest
138
+ end.each do |msg, links|
139
+ links = [*links]
140
+ if links.size == 1
141
+ message("[#{msg}](#{links[0]})")
142
+ else
143
+ r = /rspec-(.+)\.html$/
144
+ the_links = links.map { |l|
145
+ m = r.match(l)
146
+ if m
147
+ "[#{m[1]}](#{l})"
148
+ else
149
+ "[link](#{l})"
150
+ end
151
+ }.join(', ')
152
+
153
+ message("#{msg} - #{the_links}")
154
+ end
117
155
  end
118
156
  end
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
4
6
  desc 'Default: run build.'
5
- task :default => :build
7
+ task default: :build
@@ -1,35 +1,36 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'thor'
4
5
  require 'fileutils'
6
+ require 'English'
5
7
 
6
- class NetsoftCircle < Thor
8
+ class NetsoftCircle < Thor # :nodoc:
7
9
  desc 'setup', 'Setup Heroku for deployment'
8
10
  def setup
9
-
10
11
  File.open("#{ENV['HOME']}/.netrc", 'a+') do |file|
11
- file << <<-EOF
12
+ file << <<~CONFIG
12
13
 
13
- machine api.heroku.com
14
- login #{ENV['HEROKU_LOGIN']}
15
- password #{ENV['HEROKU_API_KEY']}
16
- machine git.heroku.com
17
- login #{ENV['HEROKU_LOGIN']}
18
- password #{ENV['HEROKU_API_KEY']}
19
- EOF
14
+ machine api.heroku.com
15
+ login #{ENV['HEROKU_LOGIN']}
16
+ password #{ENV['HEROKU_API_KEY']}
17
+ machine git.heroku.com
18
+ login #{ENV['HEROKU_LOGIN']}
19
+ password #{ENV['HEROKU_API_KEY']}
20
+ CONFIG
20
21
  end
21
22
 
22
- Dir.mkdir("#{ENV['HOME']}/.ssh") unless Dir.exists?("#{ENV['HOME']}/.ssh")
23
+ Dir.mkdir("#{ENV['HOME']}/.ssh") unless Dir.exist?("#{ENV['HOME']}/.ssh")
23
24
  File.open("#{ENV['HOME']}/.ssh/config", 'a+') do |file|
24
- file << <<-EOF
25
+ file << <<~CONFIG
25
26
 
26
- VerifyHostKeyDNS yes
27
- StrictHostKeyChecking no
28
- EOF
27
+ VerifyHostKeyDNS yes
28
+ StrictHostKeyChecking no
29
+ CONFIG
29
30
  end
30
31
 
31
32
  system('git config --global url."https://git.heroku.com/".insteadOf heroku:')
32
- exit(1) unless $?.success?
33
+ exit(1) unless $CHILD_STATUS.success?
33
34
  end
34
35
 
35
36
  desc 'merge', 'Merges several simplecov json result files'
@@ -37,13 +38,14 @@ EOF
37
38
  def merge(*files)
38
39
  require 'simplecov'
39
40
  return if files.empty?
41
+
40
42
  results = []
41
43
 
42
44
  files.each do |file|
43
45
  json = JSON.parse(File.read(file))
44
46
  json.each do |command_name, data|
45
47
  result = SimpleCov::Result.from_hash(command_name => data)
46
- results << result
48
+ results.concat [*result]
47
49
  end
48
50
  end
49
51
 
@@ -54,7 +56,7 @@ EOF
54
56
 
55
57
  desc 'rspec', 'Run rspec'
56
58
  def rspec
57
- system <<-EOF
59
+ system <<~COMMAND
58
60
  bundle _${BUNDLE_VERSION}_ exec rspec \
59
61
  --color \
60
62
  --format RspecJunitFormatter \
@@ -63,20 +65,20 @@ EOF
63
65
  --out $CIRCLE_ARTIFACTS/rspec.html \
64
66
  --format progress \
65
67
  $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
66
- EOF
67
- exit(1) unless $?.success?
68
+ COMMAND
69
+ exit(1) unless $CHILD_STATUS.success?
68
70
  end
69
71
 
70
72
  desc 'rubocop', 'Run rubocop'
71
73
  def rubocop
72
- system <<-EOF
74
+ system <<~COMMAND
73
75
  bundle _${BUNDLE_VERSION}_ exec rubocop \
74
76
  --parallel \
75
77
  --format progress \
76
78
  --format html \
77
79
  --out $CIRCLE_ARTIFACTS/rubocop/report.html
78
- EOF
79
- exit(1) unless $?.success?
80
+ COMMAND
81
+ exit(1) unless $CHILD_STATUS.success?
80
82
  end
81
83
 
82
84
  def self.exit_on_failure?
@@ -15,8 +15,12 @@ if ((danger.github.pr.body || '').length < 5) {
15
15
  fail("Please provide a summary in the Pull Request description");
16
16
  }
17
17
 
18
- if (!labels.includes('review passed')) {
19
- fail("Has not passed code-review");
18
+ if (labels.includes('product review needed')) {
19
+ fail('Has not passed product review');
20
+ }
21
+
22
+ if (!(labels.includes('review passed') || labels.includes('code review passed'))) {
23
+ fail("Has not passed code review");
20
24
  }
21
25
 
22
26
  if (!labels.includes('QA passed')) {
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NetsoftDanger
2
- VERSION = '0.3.5'.freeze
4
+ VERSION = '0.4.0'
3
5
  end
@@ -1,5 +1,6 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
3
4
  require 'netsoft-danger/version'
4
5
 
5
6
  Gem::Specification.new do |s|
@@ -15,8 +16,15 @@ Gem::Specification.new do |s|
15
16
  s.files = `git ls-files`.split("\n")
16
17
  s.require_paths = ['lib']
17
18
 
18
- s.add_development_dependency 'rake'
19
19
  s.add_runtime_dependency 'danger', '~> 5.0'
20
+ s.add_runtime_dependency 'faraday'
20
21
  s.add_runtime_dependency 'thor'
21
- s.add_runtime_dependency 'faraday', '~> 0.15.0'
22
+
23
+ s.add_development_dependency 'rake'
24
+
25
+ s.add_development_dependency 'netsoft-rubocop', '= 1.0.1'
26
+ s.add_development_dependency 'rubocop', '= 0.74.0'
27
+ s.add_development_dependency 'rubocop-performance', '= 1.5.2'
28
+ s.add_development_dependency 'rubocop-rails', '= 2.4.2'
29
+ s.add_development_dependency 'rubocop-rspec', '= 1.38.1'
22
30
  end