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

Commit

Permalink
Prepare for next patch release (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
poloka authored Mar 7, 2023
1 parent 83e6981 commit 7d1ebc5
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 47 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ name: CI

on:
push:
branches: ['**']
branches: ['main']
pull_request:
branches: ['main']
schedule:
- cron: '0 1 * * SUN'
workflow_dispatch:

jobs:
tests:
Expand All @@ -32,6 +33,13 @@ jobs:
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies
run: bundle install --jobs 4 --retry 3
- if: github.event_name == 'pull_request'
name: Danger
uses: danger/danger-js@9.1.8
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/danger/danger-js/issues/557#issuecomment-664851950
DANGER_DISABLE_TRANSPILATION: true
- name: Run tests
run: bundle exec rspec
- name: Run Rubocop
Expand Down
44 changes: 17 additions & 27 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
require:
- rubocop-performance
- rubocop-rspec
- rubocop-rake

AllCops:
TargetRubyVersion: 2.6
DisabledByDefault: true
Exclude:
- 'bin/{bundle,bundle-audit,bundler-audit,rake,rspec,rubocop}'
- 'bin/{bundle,bundle-audit,bundler-audit,rackup,rake,rspec,rubocop}'
- 'target/**/*'
- 'vendor/**/*'
- 'build/**/*'
- 'pkg/**/*'
- 'tmp/**/*'
- 'spec/**/*'
SuggestExtensions: false

# Bundler Cop Configuration
# https://docs.rubocop.org/en/stable/cops_bundler/
Expand Down Expand Up @@ -241,7 +235,7 @@ Lint/AssignmentInCondition:
Enabled: true
Lint/BigDecimalNew:
Enabled: true
# Supercedes Lint/UselessComparison in rubocop 0.89.
# Supersedes Lint/UselessComparison in rubocop 0.89.
Lint/BinaryOperatorWithIdenticalOperands:
Enabled: true
Lint/BooleanSymbol:
Expand Down Expand Up @@ -302,7 +296,7 @@ Lint/MissingCopEnableDirective:
Enabled: true
Lint/MissingSuper:
# Disabled. This cop is well-meaning, but doesn't provide exemption of cases where invocation of
# super is not possible. Supercedes Style/MethodMissingSuper in rubocop 0.89.
# super is not possible. Supersedes Style/MethodMissingSuper in rubocop 0.89.
Enabled: false
Lint/MultipleComparison:
Enabled: true
Expand Down Expand Up @@ -388,8 +382,6 @@ Lint/UselessAccessModifier:
Enabled: true
Lint/UselessAssignment:
Enabled: true
Lint/UselessElseWithoutRescue:
Enabled: true
Lint/UselessSetterCall:
Enabled: true
Lint/Void:
Expand Down Expand Up @@ -452,7 +444,7 @@ Naming/MemoizedInstanceVariableName:
Enabled: true
Naming/MethodName:
Enabled: true
IgnoredPatterns:
AllowedPatterns:
- 'do_GET'
- 'do_POST'
- 'do_PUT'
Expand All @@ -468,9 +460,10 @@ Naming/RescuedExceptionsVariableName:
Enabled: false
Naming/VariableName:
Enabled: true
# Disabled. It's acceptable (and in heavy usage already) to name things like "data_model_1"
# instead of forcing "data_model1".
Naming/VariableNumber:
Enabled: true

Enabled: false

# Performance Cop Configuration
# https://rubocop-performance.readthedocs.io/en/stable/cops_performance/
Expand Down Expand Up @@ -605,15 +598,11 @@ Style/DefWithParentheses:
Style/Dir:
Enabled: true
Style/Documentation:
Enabled: true
Exclude:
- test/**/*
- spec/**/*
# Disabled. Documentation is required, but enforcement here does not seem to work.
Enabled: false
Style/DocumentationMethod:
Enabled: true
Exclude:
- test/**/*
- spec/**/*
# Disabled. Documentation is required, but enforcement here does not seem to work.
Enabled: false
Style/DoubleCopDisableDirective:
Enabled: true
Style/DoubleNegation:
Expand Down Expand Up @@ -704,7 +693,7 @@ Style/MethodCallWithoutArgsParentheses:
Enabled: true
Style/MethodCalledOnDoEndBlock:
# Disabled. It is acceptable to call a method at the end of a do/end block. In particular, this is
# occationally needed in RSpec code.
# occasionally needed in RSpec code.
Enabled: false
Style/MethodDefParentheses:
Enabled: true
Expand Down Expand Up @@ -804,7 +793,8 @@ Style/RedundantCondition:
Style/RedundantConditional:
Enabled: true
Style/RedundantException:
Enabled: true
# Disabled. With ImplicitRuntimeError enabled, disable subsequent warning if consumer wishes to continue using RuntimeError
Enabled: false
Style/RedundantFreeze:
Enabled: true
Style/RedundantInterpolation:
Expand Down Expand Up @@ -856,8 +846,8 @@ Style/SpecialGlobalVars:
Style/StabbyLambdaParentheses:
Enabled: true
Style/StderrPuts:
# Disabled. This cop functionally equates use of STDERR with optional warnings. This may be true in some use cases, but there
# are times when using STDERR in CLIs is not an optional warning.
# Disabled. This cop functionally equates use of STDERR with optional warnings. This may be true
# in some use cases, but there are times when using STDERR in CLIs is not an optional warning.
Enabled: false
Style/StringHashKeys:
# Disabled. There are many use cases where using Strings for Hash keys is required.
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# 0.1.0
Initial release
- Initial release

# 0.2.3
- Add Danger validation for changelog and prepare for next patch release ([#7](https://github.com/cerner/github_bot-ruby/pull/7))
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,3 @@ gem 'rubocop-rake', '~> 0.5', require: false
gem 'rubocop-rspec', '~> 2.1', require: false
gem 'simplecov', '~> 0.19', require: false
gem 'timecop', '~> 0.9'

# debugging
gem 'debase', '~> 0.2.5.beta2'
gem 'ruby-debug-ide'
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# GitHub Bot

![CI](https://github.com/cerner/github_bot-ruby/actions/workflows/ci.yml/badge.svg)
[![Cerner OSS](https://badgen.net/badge/Cerner/OSS/blue)](http://engineering.cerner.com/2014/01/cerner-and-open-source/)
[![License](https://badgen.net/github/license/cerner/github_bot-ruby)](https://github.com/cerner/github_bot-ruby/blob/main/LICENSE)
[![Build Status](https://github.com/cerner/github_bot-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/cerner/github_bot-ruby/actions/workflows/ci.yml)

This library is a ruby implementation necessary for beginning your GitHub bot development for Ruby-based projects. The key items this project provides to consumers are the following:

Expand Down
97 changes: 97 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
const PR_LINK = `([#${danger.github.pr.number}](${danger.github.pr.html_url}))`;

const CHANGELOG_SUMMARY_TITLE = `Instructions and example for changelog`;
const CHANGELOG_BODY = `Please add an entry to \`CHANGELOG.md\` to the "Unreleased" section. Make sure the entry includes this PR's number.
Example:`;

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.`;

function getCleanTitleWithPrLink() {
const title = danger.github.pr.title;
return title.split(": ").slice(-1)[0].trim().replace(/\.+$/, "") + ` ` + PR_LINK;
}

function getChangelogDetailsHtml() {
return `
### ${CHANGELOG_SUMMARY_TITLE}
${CHANGELOG_BODY}
\`\`\`markdown
- ${getCleanTitleWithPrLink()}
\`\`\`
${CHANGELOG_END_BODY}
`;
}

function getChangelogDetailsTxt() {
return (
CHANGELOG_SUMMARY_TITLE +
"\n" +
CHANGELOG_BODY +
"\n" +
getCleanTitleWithPrLink() +
"\n" +
CHANGELOG_END_BODY
);
}

function HasPermissionToComment() {
return (
danger.github.pr.head.repo.git_url == danger.github.pr.base.repo.git_url
);
}

async function containsChangelog(path) {
const contents = await danger.github.utils.fileContents(path);
return contents.includes(PR_LINK);
}

async function checkChangelog() {
const skipChangelog =
danger.github && (danger.github.pr.body + "").toLowerCase().includes("#skip-changelog");
if (skipChangelog) {
return;
}

const hasChangelog = await containsChangelog("CHANGELOG.md");

if (!hasChangelog) {
if (HasPermissionToComment()) {
fail("Please consider adding a changelog entry for the next release.");
markdown(getChangelogDetailsHtml());
} else {
//Fallback
console.log(
"Please consider adding a changelog entry for the next release."
);
console.log(getChangelogDetailsTxt());
process.exitCode = 1;
}
}
}

async function checkIfFeature() {
const title = danger.github.pr.title;
if (title.startsWith("feat:") && HasPermissionToComment()) {
message(
'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.'
);
}
}

async function checkAll() {
// See: https://spectrum.chat/danger/javascript/support-for-github-draft-prs~82948576-ce84-40e7-a043-7675e5bf5690
const isDraft = danger.github.pr.mergeable_state === "draft";

if (isDraft) {
return;
}

await checkIfFeature();
await checkChangelog();
}

schedule(checkAll);
2 changes: 1 addition & 1 deletion lib/github_bot/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module GithubBot
VERSION = '0.2.2'
VERSION = '0.2.3'

# version module
module Version
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/github_bot/github/check_run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
RSpec.describe GithubBot::Github::CheckRun do
let(:client) { double }

subject do
subject do
described_class.new(
name: 'foo',
repo: 'bar',
Expand All @@ -27,7 +27,7 @@
time = Time.iso8601('2020-04-21T00:00:00Z')
Timecop.freeze(time) do
expect(subject).to receive(:update).with(status: 'in_progress', started_at: time)
subject.in_progress!
subject.in_progress!
end
end

Expand All @@ -39,7 +39,7 @@
conclusion: 'success',
completed_at: time
)
subject.complete!
subject.complete!
end
end

Expand All @@ -51,7 +51,7 @@
conclusion: 'action_required',
completed_at: time
)
subject.action_required!
subject.action_required!
end
end

Expand All @@ -66,4 +66,4 @@
subject.neutral!
end
end
end
end
4 changes: 2 additions & 2 deletions spec/lib/github_bot/github/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
context 'when too_large' do
let(:exception) { Octokit::Forbidden.new(body: { errors: [code: 'too_large'] }) }
let(:uri_object) { double }
let(:raw_url) { 'https://raw.github.com/foo/bar/main/file.rb'}
let(:raw_url) { 'https://raw.github.com/foo/bar/main/file.rb' }
let(:parsed_url) { double }

it 'uses the raw url for retrieval' do
Expand Down Expand Up @@ -153,4 +153,4 @@
expect(subject.pull_request_details).to eq(pull_request_response)
end
end
end
end
8 changes: 4 additions & 4 deletions spec/lib/github_bot/validator/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
RSpec.describe GithubBot::Validator::Base do
let(:client_api) { double }
let(:check_run) { double }
let(:warning_feedback) {
let(:warning_feedback) do
{
path: '/foo/bar.rb',
annotation_level: 'warning',
message: 'this is my warning annotation'
}
}
let(:failure_feedback) {
end
let(:failure_feedback) do
{
path: '/bing/baz.rb',
annotation_level: 'failure',
message: 'this is my failure annotation'
}
}
end

subject { described_class.new }

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
config.expect_with :rspec do |c|
c.syntax = :expect
end
end
end

0 comments on commit 7d1ebc5

Please sign in to comment.