Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Rubocop #17

Merged
merged 4 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ jobs:
password: ${{ secrets.PAT }}

- name: Pull web image to prevent build
env:
IMAGE_URI: '${{ env.REGISTRY }}/${{ env.GITHUB_REPOSITORY }}:${{ env.TAG }}'
run: >-
touch .env;
docker compose pull web
docker pull "$IMAGE_URI"

- name: Run Rubocop
run: >-
[ -f "db/schema.rb" ] && chmod 777 db/schema.rb;
docker compose pull web;
docker compose run -T web sh -c "bundle exec rubocop --parallel --format junit --out rubocop.xml"

- name: Publish Test Report
- name: Publish Linting Report
uses: mikepenz/action-junit-report@v3
if: always() # always run even if the previous step fails
with:
Expand Down
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

Expand All @@ -26,5 +20,5 @@
# Ignore dotenv file
.env

# Ignore node_modules
/node_modules
# Ignore rubocop report
rubocop.xml
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inherit_from: .rubocop_todo.yml
165 changes: 165 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-10-29 21:02:33 UTC using RuboCop version 1.31.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 6
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'bin/bundle'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLines:
Exclude:
- 'config/environments/development.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'config/environments/production.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented
Layout/MultilineOperationIndentation:
Exclude:
- 'bin/bundle'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
# SupportedStylesForExponentOperator: space, no_space
Layout/SpaceAroundOperators:
Exclude:
- 'config/environments/production.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBrackets: space, no_space
Layout/SpaceInsideArrayLiteralBrackets:
Exclude:
- 'config/environments/production.rb'

# Offense count: 2
Lint/UselessAssignment:
Exclude:
- 'bot/actions/modal.rb'

# Offense count: 1
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 9

# Offense count: 3
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 62

# Offense count: 1
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 9

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/CaseLikeIf:
Exclude:
- 'bot/actions/quiz.rb'

# Offense count: 2
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'app/models/application_record.rb'
- 'config/application.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/ExpandPathArguments:
Exclude:
- 'bin/bundle'

# Offense count: 44
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/GlobalStdStream:
Exclude:
- 'config/environments/production.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
Exclude:
- 'bin/bundle'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/PerlBackrefs:
Exclude:
- 'bin/bundle'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SafeForConstants.
Style/RedundantFetchBlock:
Exclude:
- 'config/puma.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: RequireEnglish.
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
Style/SpecialGlobalVars:
EnforcedStyle: use_perl_names

# Offense count: 61
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'bin/bundle'
- 'bin/rails'
- 'bin/rake'
- 'bin/setup'
- 'config/application.rb'
- 'config/boot.rb'
- 'config/environment.rb'
- 'config/environments/development.rb'
- 'config/environments/production.rb'
- 'config/environments/test.rb'
- 'config/puma.rb'
- 'config/spring.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: .
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: percent
MinSize: 10

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 198
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ gem 'bootsnap', '>= 1.15.0', require: false

gem 'activerecord', '~> 7.0.4', require: 'active_record'
gem 'otr-activerecord'
gem 'pg'
gem 'pagy_cursor'
gem 'pg'

gem 'slack-ruby-bot-server-events'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'rubocop', '1.31.2', require: false
end

group :development do
Expand All @@ -43,4 +44,3 @@ end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
# gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'rubocop', require: false
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ GEM
kaminari-grape (1.0.1)
grape
kaminari-core (~> 1.0)
language_server-protocol (3.17.0.3)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -179,6 +178,8 @@ GEM
nio4r (2.5.9)
nokogiri (1.15.4-aarch64-linux)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
otr-activerecord (2.2.0)
activerecord (>= 4.0, < 7.2)
hashie-forbidden_attributes (~> 0.1)
Expand Down Expand Up @@ -245,19 +246,17 @@ GEM
rexml (3.2.6)
roar (1.1.1)
representable (~> 3.0)
rubocop (1.57.1)
base64 (~> 0.1.1)
rubocop (1.31.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
rubocop-ast (>= 1.18.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
Expand Down Expand Up @@ -299,6 +298,7 @@ GEM

PLATFORMS
aarch64-linux
x86_64-linux

DEPENDENCIES
activerecord (~> 7.0.4)
Expand All @@ -311,7 +311,7 @@ DEPENDENCIES
pg
puma (~> 6.0.1)
rails (~> 7.0.5)
rubocop
rubocop (= 1.31.2)
slack-ruby-bot-server-events
spring
spring-watcher-listen (~> 2.0.0)
Expand Down
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,31 @@ Please follow the standard Ruby on Rails application deployment methods.

## License

**MIT**
MIT License

Copyright (c) 2023 crazyoptimist

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

## Contributing

- Fork the project (https://docs.github.com/en/get-started/quickstart/fork-a-repo)
- Create a topic branch
- Install dependencies by running `bundle install`
- Make changes and push your commits
- Create a pull request
- Add a PR description explaining what is done and why

## TODO

- [ ] Add Rubocop linting
- [x] Add Rubocop linting
- [ ] Add Specs
- [ ] Add CI/CD with Github Actions
- [ ] Add Contribution Guide
- [x] Add CI/CD with Github Actions
- [x] Add Contribution Guide

## Credit

Expand Down
10 changes: 5 additions & 5 deletions bot/actions/modal.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
SlackRubyBotServer::Events.configure do |config|
config.on :action, 'view_submission' do |action|
payload = action[:payload]
team_id = payload["team"]["id"]
username = payload["user"]["username"]
trigger_id = payload["trigger_id"]
team_id = payload['team']['id']
username = payload['user']['username']
trigger_id = payload['trigger_id']
action.logger.info "User #{username} has submitted a demo modal form"
team = Team.find_by(team_id: team_id)
team = Team.find_by(team_id:)
slack_client = Slack::Web::Client.new(token: team.token)
form_values = payload["view"]["state"]["values"]
form_values = payload['view']['state']['values']
p form_values
nil
end
Expand Down
12 changes: 6 additions & 6 deletions bot/actions/quiz.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
SlackRubyBotServer::Events.configure do |config|
config.on :action, 'block_actions' do |action|
payload = action[:payload]
action_id = payload["actions"][0]["action_id"]
channel_id = payload["channel"]["id"]
team_id = payload["team"]["id"]
action_id = payload['actions'][0]['action_id']
channel_id = payload['channel']['id']
team_id = payload['team']['id']
action.logger.info "Action #{action_id} has been processed in channel #{channel_id}"
team = Team.find_by(team_id: team_id)
team = Team.find_by(team_id:)
slack_client = Slack::Web::Client.new(token: team.token)
if action_id == 'reply_yes'
slack_client.chat_postMessage(channel: channel_id, text: "Great! I also think so! :thumbsup:")
slack_client.chat_postMessage(channel: channel_id, text: 'Great! I also think so! :thumbsup:')
elsif action_id == 'reply_no'
slack_client.chat_postMessage(channel: channel_id, text: "Oops! Try to google it... :thumbsdown:")
slack_client.chat_postMessage(channel: channel_id, text: 'Oops! Try to google it... :thumbsdown:')
end
# Do not send text message any more
nil
Expand Down
1 change: 0 additions & 1 deletion bot/events/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

SlackRubyBotServer::Events.configure do |config|
config.on :event do |event|
event.logger.info "Received #{event[:type]}, #{event[:event][:type]}."
Expand Down
Loading
Loading