Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit 1826203

Browse files
authored
Update version of thor to have a broader availability (#6)
1 parent 2e5c83a commit 1826203

File tree

13 files changed

+137
-47
lines changed

13 files changed

+137
-47
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: CI
44

55
on:
66
push:
7-
branches: ['**']
7+
branches: ['main']
88
pull_request:
99
branches: ['main']
1010
schedule:
@@ -32,6 +32,13 @@ jobs:
3232
ruby-version: ${{ matrix.ruby }}
3333
- name: Install dependencies
3434
run: bundle install --jobs 4 --retry 3
35+
- if: github.event_name == 'pull_request'
36+
name: Danger
37+
uses: danger/[email protected]
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
# https://github.com/danger/danger-js/issues/557#issuecomment-664851950
41+
DANGER_DISABLE_TRANSPILATION: true
3542
- name: Run tests
3643
run: bundle exec rspec
3744
- name: Run Rubocop

.rubocop.yml

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
require:
22
- rubocop-performance
3-
- rubocop-rspec
4-
- rubocop-rake
53

64
AllCops:
7-
TargetRubyVersion: 2.6
85
DisabledByDefault: true
96
Exclude:
10-
- 'bin/{bundle,bundle-audit,bundler-audit,rake,rspec,rubocop}'
7+
- 'bin/{bundle,bundle-audit,bundler-audit,rackup,rake,rspec,rubocop}'
118
- 'target/**/*'
129
- 'vendor/**/*'
13-
- 'build/**/*'
14-
- 'pkg/**/*'
15-
- 'tmp/**/*'
10+
SuggestExtensions: false
1611

1712
# Bundler Cop Configuration
1813
# https://docs.rubocop.org/en/stable/cops_bundler/
@@ -240,7 +235,7 @@ Lint/AssignmentInCondition:
240235
Enabled: true
241236
Lint/BigDecimalNew:
242237
Enabled: true
243-
# Supercedes Lint/UselessComparison in rubocop 0.89.
238+
# Supersedes Lint/UselessComparison in rubocop 0.89.
244239
Lint/BinaryOperatorWithIdenticalOperands:
245240
Enabled: true
246241
Lint/BooleanSymbol:
@@ -301,7 +296,7 @@ Lint/MissingCopEnableDirective:
301296
Enabled: true
302297
Lint/MissingSuper:
303298
# Disabled. This cop is well-meaning, but doesn't provide exemption of cases where invocation of
304-
# super is not possible. Supercedes Style/MethodMissingSuper in rubocop 0.89.
299+
# super is not possible. Supersedes Style/MethodMissingSuper in rubocop 0.89.
305300
Enabled: false
306301
Lint/MultipleComparison:
307302
Enabled: true
@@ -387,8 +382,6 @@ Lint/UselessAccessModifier:
387382
Enabled: true
388383
Lint/UselessAssignment:
389384
Enabled: true
390-
Lint/UselessElseWithoutRescue:
391-
Enabled: true
392385
Lint/UselessSetterCall:
393386
Enabled: true
394387
Lint/Void:
@@ -451,7 +444,7 @@ Naming/MemoizedInstanceVariableName:
451444
Enabled: true
452445
Naming/MethodName:
453446
Enabled: true
454-
IgnoredPatterns:
447+
AllowedPatterns:
455448
- 'do_GET'
456449
- 'do_POST'
457450
- 'do_PUT'
@@ -467,9 +460,10 @@ Naming/RescuedExceptionsVariableName:
467460
Enabled: false
468461
Naming/VariableName:
469462
Enabled: true
463+
# Disabled. It's acceptable (and in heavy usage already) to name things like "data_model_1"
464+
# instead of forcing "data_model1".
470465
Naming/VariableNumber:
471-
Enabled: true
472-
466+
Enabled: false
473467

474468
# Performance Cop Configuration
475469
# https://rubocop-performance.readthedocs.io/en/stable/cops_performance/
@@ -604,15 +598,11 @@ Style/DefWithParentheses:
604598
Style/Dir:
605599
Enabled: true
606600
Style/Documentation:
607-
Enabled: true
608-
Exclude:
609-
- test/**/*
610-
- spec/**/*
601+
# Disabled. Documentation is required, but enforcement here does not seem to work.
602+
Enabled: false
611603
Style/DocumentationMethod:
612-
Enabled: true
613-
Exclude:
614-
- test/**/*
615-
- spec/**/*
604+
# Disabled. Documentation is required, but enforcement here does not seem to work.
605+
Enabled: false
616606
Style/DoubleCopDisableDirective:
617607
Enabled: true
618608
Style/DoubleNegation:
@@ -703,7 +693,7 @@ Style/MethodCallWithoutArgsParentheses:
703693
Enabled: true
704694
Style/MethodCalledOnDoEndBlock:
705695
# Disabled. It is acceptable to call a method at the end of a do/end block. In particular, this is
706-
# occationally needed in RSpec code.
696+
# occasionally needed in RSpec code.
707697
Enabled: false
708698
Style/MethodDefParentheses:
709699
Enabled: true
@@ -803,7 +793,8 @@ Style/RedundantCondition:
803793
Style/RedundantConditional:
804794
Enabled: true
805795
Style/RedundantException:
806-
Enabled: true
796+
# Disabled. With ImplicitRuntimeError enabled, disable subsequent warning if consumer wishes to continue using RuntimeError
797+
Enabled: false
807798
Style/RedundantFreeze:
808799
Enabled: true
809800
Style/RedundantInterpolation:
@@ -855,8 +846,8 @@ Style/SpecialGlobalVars:
855846
Style/StabbyLambdaParentheses:
856847
Enabled: true
857848
Style/StderrPuts:
858-
# Disabled. This cop functionally equates use of STDERR with optional warnings. This may be true in some use cases, but there
859-
# are times when using STDERR in CLIs is not an optional warning.
849+
# Disabled. This cop functionally equates use of STDERR with optional warnings. This may be true
850+
# in some use cases, but there are times when using STDERR in CLIs is not an optional warning.
860851
Enabled: false
861852
Style/StringHashKeys:
862853
# Disabled. There are many use cases where using Strings for Hash keys is required.

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 0.1.0
2-
Initial release
2+
- Initial release
33

44
# 0.1.1
5-
Fix homepage reference
5+
- Fix homepage reference
6+
7+
# 0.2.0
8+
- Update version of thor to have a broader availability ([#6](https://github.com/cerner/codeowner_validator/pull/6))

Gemfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,3 @@ gem 'rubocop-performance', '~> 1.8', require: false
1414
gem 'rubocop-rake', '~> 0.5', require: false
1515
gem 'rubocop-rspec', '~> 2.1', require: false
1616
gem 'simplecov', '~> 0.19', require: false
17-
18-
# debugging
19-
gem 'debase', '~> 0.2.5.beta2'
20-
gem 'ruby-debug-ide'

codeowner_validator.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
3030
spec.required_ruby_version = '>= 2.6.2'
3131

3232
spec.add_dependency 'rainbow', '>= 2.0', '< 4.0.0'
33-
spec.add_dependency 'thor', '~> 0.19'
33+
spec.add_dependency 'thor', '>= 0.19'
3434

3535
spec.add_dependency 'tty-prompt', '~> 0.12'
3636
spec.add_dependency 'tty-spinner', '~> 0.4'

dangerfile.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
const PR_LINK = `([#${danger.github.pr.number}](${danger.github.pr.html_url}))`;
2+
3+
const CHANGELOG_SUMMARY_TITLE = `Instructions and example for changelog`;
4+
const CHANGELOG_BODY = `Please add an entry to \`CHANGELOG.md\` to the "Unreleased" section. Make sure the entry includes this PR's number.
5+
6+
Example:`;
7+
8+
const CHANGELOG_END_BODY = `If none of the above apply, you can opt out of this check by adding \`#skip-changelog\` to the PR description.`;
9+
10+
function getCleanTitleWithPrLink() {
11+
const title = danger.github.pr.title;
12+
return title.split(": ").slice(-1)[0].trim().replace(/\.+$/, "") + ` ` + PR_LINK;
13+
}
14+
15+
function getChangelogDetailsHtml() {
16+
return `
17+
### ${CHANGELOG_SUMMARY_TITLE}
18+
19+
${CHANGELOG_BODY}
20+
21+
\`\`\`markdown
22+
- ${getCleanTitleWithPrLink()}
23+
\`\`\`
24+
25+
${CHANGELOG_END_BODY}
26+
`;
27+
}
28+
29+
function getChangelogDetailsTxt() {
30+
return (
31+
CHANGELOG_SUMMARY_TITLE +
32+
"\n" +
33+
CHANGELOG_BODY +
34+
"\n" +
35+
getCleanTitleWithPrLink() +
36+
"\n" +
37+
CHANGELOG_END_BODY
38+
);
39+
}
40+
41+
function HasPermissionToComment() {
42+
return (
43+
danger.github.pr.head.repo.git_url == danger.github.pr.base.repo.git_url
44+
);
45+
}
46+
47+
async function containsChangelog(path) {
48+
const contents = await danger.github.utils.fileContents(path);
49+
return contents.includes(PR_LINK);
50+
}
51+
52+
async function checkChangelog() {
53+
const skipChangelog =
54+
danger.github && (danger.github.pr.body + "").toLowerCase().includes("#skip-changelog");
55+
if (skipChangelog) {
56+
return;
57+
}
58+
59+
const hasChangelog = await containsChangelog("CHANGELOG.md");
60+
61+
if (!hasChangelog) {
62+
if (HasPermissionToComment()) {
63+
fail("Please consider adding a changelog entry for the next release.");
64+
markdown(getChangelogDetailsHtml());
65+
} else {
66+
//Fallback
67+
console.log(
68+
"Please consider adding a changelog entry for the next release."
69+
);
70+
console.log(getChangelogDetailsTxt());
71+
process.exitCode = 1;
72+
}
73+
}
74+
}
75+
76+
async function checkIfFeature() {
77+
const title = danger.github.pr.title;
78+
if (title.startsWith("feat:") && HasPermissionToComment()) {
79+
message(
80+
'Do not forget to update <a href="https://github.com/getsentry/sentry-docs">Sentry-docs</a> with your feature once the pull request gets approved.'
81+
);
82+
}
83+
}
84+
85+
async function checkAll() {
86+
// See: https://spectrum.chat/danger/javascript/support-for-github-draft-prs~82948576-ce84-40e7-a043-7675e5bf5690
87+
const isDraft = danger.github.pr.mergeable_state === "draft";
88+
89+
if (isDraft) {
90+
return;
91+
}
92+
93+
await checkIfFeature();
94+
await checkChangelog();
95+
}
96+
97+
schedule(checkAll);

lib/codeowner_validator/code_owners.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,8 @@ def codeowner_file_paths
262262
@codeowner_file_paths = %w[CODEOWNERS docs/CODEOWNERS .github/CODEOWNERS]
263263

264264
# allow customization of the locations to search for the file
265-
if ENV['CODEOWNER_FILE_PATHS']
266-
ENV['CODEOWNER_FILE_PATHS']&.split(',')&.each(&:strip!)&.each do |str|
267-
@codeowner_file_paths << str
268-
end
265+
ENV['CODEOWNER_FILE_PATHS']&.split(',')&.each(&:strip!)&.each do |str|
266+
@codeowner_file_paths << str
269267
end
270268

271269
@codeowner_file_paths

lib/codeowner_validator/group/comment/error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Error
1212
class << self
1313
# @see CodeownerValidator::Group::Comment.match?
1414
def match?(type)
15-
Comment::TYPE_ERROR == type
15+
type == Comment::TYPE_ERROR
1616
end
1717
end
1818
end

lib/codeowner_validator/group/comment/info.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Info
1212
class << self
1313
# @see CodeownerValidator::Group::Comment.match?
1414
def match?(type)
15-
Comment::TYPE_INFO == type
15+
type == Comment::TYPE_INFO
1616
end
1717
end
1818
end

lib/codeowner_validator/group/comment/verbose.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Verbose
1212
class << self
1313
# @see CodeownerValidator::Group::Comment.match?
1414
def match?(type)
15-
Comment::TYPE_VERBOSE == type
15+
type == Comment::TYPE_VERBOSE
1616
end
1717
end
1818
end

0 commit comments

Comments
 (0)