netsoft-danger 0.3.4 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 896e582de631d926bd01d4f5d98d0bde7f20f9a0ec129600bcea3eff09ffbb53
4
- data.tar.gz: 9613d84bcd13e28594d387b66c1d1cc379d2f6ee62857e4ddcf2bce30761466a
3
+ metadata.gz: ca4dcd0963df60b652e45e3bba8ef8262b350e52c0f659b5ec6660cf6f107ffa
4
+ data.tar.gz: 351f00d2d1f090c7a97e4385adc5c40af0284055b9d5a7676bdb1aec2bc99588
5
5
  SHA512:
6
- metadata.gz: 9600eeb6dc24d45393f88ce2f4e956885209974d0910bec466354fca4950de21a78fad98986f2c1593074a44c72f95d8d0760254e6b08a5b3bd6b1a6daef5d39
7
- data.tar.gz: 244fa8e69810e66bd44b37d6b156dc58229bc6ff6fe39f736928332f1209d200fc003651dc7c8f1863cc90d57dbb24f874e4075492239d33e3506829ecd752ec
6
+ metadata.gz: 6a29a7f5ffc53604bbbde1214b6ff006b7ead9d38cfee18fc843b2f5d8df467e1c77ed8e914895bc0e0a7e0eebb85808f5d5b5f1a23500c850c9738723ec5b4c
7
+ data.tar.gz: c7ceb9f06a2815b36ae58e540197aaa7866daa3168c741dcc4ea862eb52b3496612593e9c5ff3e7ea1791be89dc99cac995d66f1f401c4243bdcf30f27e48300
@@ -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: |-
@@ -124,7 +128,9 @@ jobs:
124
128
  name: Deploy to gem server
125
129
  command: |-
126
130
  ./bin/tag_check.sh
131
+ ./bin/setup-rubygems.sh
127
132
  rm -rf pkg
128
133
  gem install geminabox
129
134
  rake build
130
135
  gem inabox -g ${HUBSTAFF_GEM_SERVER} pkg/*
136
+ gem push pkg/*.gem
@@ -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
@@ -0,0 +1,38 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Next]
8
+ ### Added
9
+ ### Changed
10
+ ### Fixed
11
+
12
+ ## [0.3.9]
13
+ ### Fixed
14
+ - correct API call to github for adding labels and fix logic in determining if we should or should not add the label
15
+
16
+ ## [0.3.8]
17
+ ### Added
18
+ - auto add/remove some labels
19
+ - allow conventional commit format for our migration, gemfile, and package.json
20
+ - add support for product review labels
21
+ - add support for renamed code review labels
22
+
23
+ ## [0.3.7]
24
+ ### Fixed
25
+ - require English in the netsoft-circle bin
26
+
27
+ ## [0.3.6]
28
+ ### Added
29
+ - rubocop checks for this gem
30
+ ### Changed
31
+ - allow bundler 1.17.3
32
+
33
+ ## [0.3.5]
34
+ ### Added
35
+ - package.json checks
36
+ ### Fixed
37
+ - requie older version of faraday until octokit is fixed (https://github.com/octokit/octokit.rb/pull/1154)
38
+
data/Dangerfile CHANGED
@@ -1,105 +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
+ puts repo_name: repo_name, pr_number: pr_number, labels: github.pr_labels, has_label: has_label, label: label, should_set: should_set
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 =~ /^\[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\// or f.path =~ /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)/ || f.path =~ /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/ || f.path =~ /gemspec/ }
53
- has_gemfile_msg = c.message =~ /^\[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
57
84
  end
58
- if c.diff_parent.any? {|f| !( f.path =~ /Gemfile/ || f.path =~ /gemspec/ ) }
59
- fail '[gemfile] Gemfile commit contains non-gemfile changes' + short
85
+ if old_migration_msg
86
+ warn 'gemfile: Please switch to the new conventional commit format.'
60
87
  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")
88
+ if c.diff_parent.any? { |f| f.path !~ /Gemfile|gemspec/ }
89
+ fail 'gemfile: Gemfile commit contains non-gemfile changes' + short
90
+ end
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
98
+ end
99
+
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]+\))?:/)
103
+ if has_package_changes
104
+ unless has_package_msg
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.'
109
+ end
110
+ if c.diff_parent.any? { |f| f.path !~ /package\.json|yarn\.lock/ }
111
+ fail 'package: Package.json commit contains non-package changes' + short
112
+ end
113
+ elsif has_package_msg
114
+ fail 'package: Pacakge.json commit has no package changes!' + short
68
115
  end
69
116
  end
70
117
 
71
- require 'open-uri'
72
-
73
- 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']}"
74
- artifacts = JSON.load(open(artifact_url).read).map{|a| a["url"]}
75
-
76
- jest = artifacts.find{ |artifact| artifact.end_with?('jest/index.html') }
77
- coverage = artifacts.find{ |artifact| artifact.end_with?('coverage/index.html') }
78
- rubocop = artifacts.find{ |artifact| artifact.end_with?('rubocop/report.html') }
79
- eslint = artifacts.find{ |artifact| artifact.end_with?('eslint/report.html') }
80
- rspec_files = artifacts.select{ |artifact| artifact =~ /rspec-(.+)\.html$/ }
81
-
82
- {}.tap do |hash|
83
- hash['Ruby coverage report'] = coverage if coverage
84
- hash['RSpec test report'] = rspec_files unless rspec_files.empty?
85
- hash['RuboCop inspection report'] = rubocop if rubocop
86
- hash['ESLint inspection report'] = eslint if eslint
87
- hash['Jest coverage report'] = jest if jest
88
- end.each do |msg, links|
89
- links = [*links]
90
- if links.size == 1
91
- message("[#{msg}](#{links[0]})")
92
- else
93
- r = /rspec-(.+)\.html$/
94
- the_links = links.map do |l|
95
- m = r.match(l)
96
- if m
97
- "[#{m[1]}](#{l})"
98
- else
99
- "[link](#{l})"
100
- end
101
- end.join(', ')
118
+ toggle_label(github, 'run migration', should_have_migration_label)
102
119
 
103
- message("#{msg} - #{the_links}")
120
+ if ENV['CIRCLE_TOKEN']
121
+ require 'open-uri'
122
+
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
104
155
  end
105
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,6 +38,7 @@ 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|
@@ -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?
@@ -0,0 +1,3 @@
1
+ mkdir ~/.gem
2
+ echo -e "---\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
3
+ chmod 0600 ~/.gem/credentials
@@ -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.4'.freeze
4
+ VERSION = '0.3.9'
3
5
  end