From 5d4cd8287b7b301942b7e191f547d2cc4908db73 Mon Sep 17 00:00:00 2001 From: crazyoptimist Date: Sun, 29 Oct 2023 17:10:07 -0500 Subject: [PATCH 1/5] chore: better format env.example for readiblity --- .env.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index e7e1339..0691407 100644 --- a/.env.example +++ b/.env.example @@ -1,9 +1,10 @@ RAILS_ENV=development RAILS_SECRET_TOKEN="replacemeasap" RAILS_HOST_NAME=your-domain.com - BASE_URL=https://${RAILS_HOST_NAME} + MONGO_URL="mongodb://user:password@myhost1.mydomain.com:27017/my_db" + SLACK_CLIENT_ID= SLACK_CLIENT_SECRET= SLACK_SIGNING_SECRET= From 9c7cc9e7beffbdc57726786dc01bfb6bc286c98a Mon Sep 17 00:00:00 2001 From: April Rieger Date: Tue, 24 Oct 2023 20:24:03 -0700 Subject: [PATCH 2/5] Ad a few templates to start you off --- .github/ISSUE_TEMPLATE.md | 18 ++++++++++++++++++ .github/PULL_REQUEST_TEMPLATE.md | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..c174596 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,18 @@ +# Story + +# Acceptance Criteria + +- [ ] + +# Screenshots / Video + +
+ + +
+ +# Testing Instructions and Sample Files + +- + +# Notes \ No newline at end of file diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..d0ef6ae --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,16 @@ +# Story + +Refs #issuenumber + +# Expected Behavior Before Changes + +# Expected Behavior After Changes + +# Screenshots / Video + +
+ + +
+ +# Notes \ No newline at end of file From c8eead263d2a376ccca0da2d18ee892c54a90998 Mon Sep 17 00:00:00 2001 From: crazyoptimist Date: Sun, 29 Oct 2023 17:32:13 -0500 Subject: [PATCH 3/5] synced major changes from postgres branch --- .github/workflows/build-lint.yaml | 107 ++++++++++++++++++++ .gitignore | 10 +- Dockerfile | 2 +- Gemfile | 1 + Gemfile.lock | 160 +++++++++++++++++------------- README.md | 25 ++++- 6 files changed, 225 insertions(+), 80 deletions(-) create mode 100644 .github/workflows/build-lint.yaml diff --git a/.github/workflows/build-lint.yaml b/.github/workflows/build-lint.yaml new file mode 100644 index 0000000..a0c82a8 --- /dev/null +++ b/.github/workflows/build-lint.yaml @@ -0,0 +1,107 @@ +name: 'Build & Lint' +run-name: Build & Lint of ${{ github.ref_name }} by @${{ github.actor }} +on: + push: + branches: + - master + pull_request: + branches: + - master + workflow_dispatch: + inputs: + debug_enabled: + type: boolean + description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' + required: false + default: false + +env: + GITHUB_REPOSITORY: ${{ github.repository }} + REGISTRY: ghcr.io + TAG: ${{ github.sha }} + DOCKER_BUILDKIT: 1 + COMPOSE_DOCKER_CLI_BUILD: 1 + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: true + token: ${{ secrets.PAT }} + + - name: Set up QEMU + + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.PAT }} + + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} + with: + limit-access-to-actor: true + + - name: Retag action for web + id: meta-web + uses: docker/metadata-action@v4.1.1 + with: + images: | + name=${{ env.REGISTRY }}/${{ env.GITHUB_REPOSITORY }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + - name: Build and push web + uses: docker/build-push-action@v3 + with: + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.GITHUB_REPOSITORY }}:latest + context: . + file: Dockerfile + platforms: 'linux/amd64' + push: true + tags: | + ${{ steps.meta-web.outputs.tags }} + ${{ env.REGISTRY }}/${{ env.GITHUB_REPOSITORY }}:${{ env.TAG }} + target: web + + lint: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + token: ${{ secrets.PAT }} + + - name: Github Container Login + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.PAT }} + + - name: Pull web image to prevent build + env: + IMAGE_URI: '${{ env.REGISTRY }}/${{ env.GITHUB_REPOSITORY }}:${{ env.TAG }}' + run: >- + docker pull "$IMAGE_URI" + - name: Run Rubocop + run: >- + [ -f "db/schema.rb" ] && chmod 777 db/schema.rb; + docker compose run -T web sh -c "bundle exec rubocop --parallel --format junit --out rubocop.xml" + - name: Publish Linting Report + uses: mikepenz/action-junit-report@v3 + if: always() # always run even if the previous step fails + with: + report_paths: 'rubocop*.xml' diff --git a/.gitignore b/.gitignore index 2f3ed8d..257fde8 100644 --- a/.gitignore +++ b/.gitignore @@ -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 @@ -26,5 +20,5 @@ # Ignore dotenv file .env -# Ignore node_modules -/node_modules +# Ignore rubocop report +rubocop.xml diff --git a/Dockerfile b/Dockerfile index 2a95304..306de04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:3.1.3 +FROM ruby:3.1.3 as web WORKDIR /app COPY Gemfile* ./ diff --git a/Gemfile b/Gemfile index 9b8f8b0..edea09c 100644 --- a/Gemfile +++ b/Gemfile @@ -33,6 +33,7 @@ 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 'rubocop', '1.31.2', require: false end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 80b916f..ac26514 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,71 +1,72 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.0.4) - actionpack (= 7.0.4) - activesupport (= 7.0.4) + actioncable (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.4) - actionpack (= 7.0.4) - activejob (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) + actionmailbox (7.0.8) + actionpack (= 7.0.8) + activejob (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.4) - actionpack (= 7.0.4) - actionview (= 7.0.4) - activejob (= 7.0.4) - activesupport (= 7.0.4) + actionmailer (7.0.8) + actionpack (= 7.0.8) + actionview (= 7.0.8) + activejob (= 7.0.8) + activesupport (= 7.0.8) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.4) - actionview (= 7.0.4) - activesupport (= 7.0.4) - rack (~> 2.0, >= 2.2.0) + actionpack (7.0.8) + actionview (= 7.0.8) + activesupport (= 7.0.8) + rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.4) - actionpack (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) + actiontext (7.0.8) + actionpack (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.4) - activesupport (= 7.0.4) + actionview (7.0.8) + activesupport (= 7.0.8) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.4) - activesupport (= 7.0.4) + activejob (7.0.8) + activesupport (= 7.0.8) globalid (>= 0.3.6) - activemodel (7.0.4) - activesupport (= 7.0.4) - activerecord (7.0.4) - activemodel (= 7.0.4) - activesupport (= 7.0.4) - activestorage (7.0.4) - actionpack (= 7.0.4) - activejob (= 7.0.4) - activerecord (= 7.0.4) - activesupport (= 7.0.4) + activemodel (7.0.8) + activesupport (= 7.0.8) + activerecord (7.0.8) + activemodel (= 7.0.8) + activesupport (= 7.0.8) + activestorage (7.0.8) + actionpack (= 7.0.8) + activejob (= 7.0.8) + activerecord (= 7.0.8) + activesupport (= 7.0.8) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.4) + activesupport (7.0.8) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) + ast (2.4.2) async (2.3.0) console (~> 1.10) io-event (~> 1.1) @@ -113,8 +114,8 @@ GEM fiber-local (1.0.0) foreman (0.87.2) gli (2.21.0) - globalid (1.0.0) - activesupport (>= 5.0) + globalid (1.2.1) + activesupport (>= 6.1) grape (1.7.0) activesupport builder @@ -132,6 +133,7 @@ GEM i18n (1.12.0) concurrent-ruby (~> 1.0) io-event (1.1.4) + json (2.6.3) kaminari-core (1.2.2) kaminari-grape (1.0.1) grape @@ -145,26 +147,27 @@ GEM loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.8.0) + mail (2.8.1) mini_mime (>= 0.1.1) net-imap net-pop net-smtp marcel (1.0.2) method_source (1.0.0) - mini_mime (1.1.2) + mini_mime (1.1.5) mini_portile2 (2.8.0) minitest (5.16.3) mongo (2.18.2) bson (>= 4.14.1, < 5.0.0) - mongoid (8.0.3) - activemodel (>= 5.1, < 7.1, != 7.0.0) + mongoid (8.1.3) + activemodel (>= 5.1, < 7.2, != 7.0.0) + concurrent-ruby (>= 1.0.5, < 2.0) mongo (>= 2.18.0, < 3.0.0) ruby2_keywords (~> 0.0.5) mongoid-compatibility (0.6.0) activesupport mongoid (>= 2.0) - mongoid-scroll (0.3.7) + mongoid-scroll (1.0.1) i18n mongoid (>= 3.0) mongoid-compatibility @@ -175,19 +178,23 @@ GEM ruby2_keywords (~> 0.0.1) mustermann-grape (1.0.2) mustermann (>= 1.0.0) - net-imap (0.3.3) + net-imap (0.4.2) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.1) timeout - net-smtp (0.3.3) + net-smtp (0.4.0) net-protocol nio4r (2.5.8) nokogiri (1.13.10) mini_portile2 (~> 2.8.0) racc (~> 1.4) + parallel (1.23.0) + parser (3.2.2.4) + ast (~> 2.4.1) + racc puma (6.0.1) nio4r (~> 2.0) racc (1.6.1) @@ -201,42 +208,59 @@ GEM rack rack-test (2.0.2) rack (>= 1.3) - rails (7.0.4) - actioncable (= 7.0.4) - actionmailbox (= 7.0.4) - actionmailer (= 7.0.4) - actionpack (= 7.0.4) - actiontext (= 7.0.4) - actionview (= 7.0.4) - activejob (= 7.0.4) - activemodel (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) + rails (7.0.8) + actioncable (= 7.0.8) + actionmailbox (= 7.0.8) + actionmailer (= 7.0.8) + actionpack (= 7.0.8) + actiontext (= 7.0.8) + actionview (= 7.0.8) + activejob (= 7.0.8) + activemodel (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) bundler (>= 1.15.0) - railties (= 7.0.4) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + railties (= 7.0.8) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) rails-html-sanitizer (1.4.4) loofah (~> 2.19, >= 2.19.1) - railties (7.0.4) - actionpack (= 7.0.4) - activesupport (= 7.0.4) + railties (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) method_source rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) + rainbow (3.1.1) rake (13.0.6) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) + regexp_parser (2.8.2) representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) + rexml (3.2.6) roar (1.1.1) representable (~> 3.0) + rubocop (1.31.2) + json (~> 2.3) + parallel (~> 1.10) + 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.18.0, < 2.0) + ruby-progressbar (~> 1.7) + 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) slack-ruby-bot-server (1.2.1) async @@ -263,12 +287,13 @@ GEM listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) thor (1.2.1) - timeout (0.3.1) + timeout (0.4.0) timers (4.3.5) trailblazer-option (0.1.2) tzinfo (2.0.5) concurrent-ruby (~> 1.0) uber (0.1.0) + unicode-display_width (2.5.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -286,7 +311,8 @@ DEPENDENCIES mongoid mongoid-scroll puma (~> 6.0.1) - rails (~> 7.0.4) + rails (~> 7.0.5) + rubocop (= 1.31.2) slack-ruby-bot-server-events spring spring-watcher-listen (~> 2.0.0) diff --git a/README.md b/README.md index 5a2c2b0..b88b725 100644 --- a/README.md +++ b/README.md @@ -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 From ac0c281f0ed43fe525bfe3988242b7754f09d91b Mon Sep 17 00:00:00 2001 From: crazyoptimist Date: Sun, 29 Oct 2023 17:34:35 -0500 Subject: [PATCH 4/5] chore: ran rubocop, auto gen cops config --- .rubocop.yml | 1 + .rubocop_todo.yml | 164 ++++++++++++++++++++++++++++++++++++ Gemfile | 2 +- bot/actions/modal.rb | 10 +-- bot/actions/quiz.rb | 12 +-- bot/events/default.rb | 1 - bot/slash_commands/modal.rb | 56 ++++++------ bot/slash_commands/quiz.rb | 32 +++---- 8 files changed, 221 insertions(+), 57 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..cc32da4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1 @@ +inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..6e3e4b9 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,164 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-10-29 22:34:19 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: 1 +# Configuration parameters: AllowedConstants. +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'config/application.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/ExpandPathArguments: + Exclude: + - 'bin/bundle' + +# Offense count: 43 +# 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: 60 +# 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 diff --git a/Gemfile b/Gemfile index edea09c..9ee72c5 100644 --- a/Gemfile +++ b/Gemfile @@ -32,7 +32,7 @@ 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 diff --git a/bot/actions/modal.rb b/bot/actions/modal.rb index dc55905..55a9de2 100644 --- a/bot/actions/modal.rb +++ b/bot/actions/modal.rb @@ -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 diff --git a/bot/actions/quiz.rb b/bot/actions/quiz.rb index 3ad25b9..ac7045c 100644 --- a/bot/actions/quiz.rb +++ b/bot/actions/quiz.rb @@ -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 diff --git a/bot/events/default.rb b/bot/events/default.rb index f26ebc7..ac48d41 100644 --- a/bot/events/default.rb +++ b/bot/events/default.rb @@ -1,4 +1,3 @@ - SlackRubyBotServer::Events.configure do |config| config.on :event do |event| event.logger.info "Received #{event[:type]}, #{event[:event][:type]}." diff --git a/bot/slash_commands/modal.rb b/bot/slash_commands/modal.rb index 0f11b4f..20627ba 100644 --- a/bot/slash_commands/modal.rb +++ b/bot/slash_commands/modal.rb @@ -1,61 +1,61 @@ def modal_payload(trigger_id) { - trigger_id: trigger_id, + trigger_id:, view: { - type: "modal", + type: 'modal', title: { - type: "plain_text", - text: "Demo Modal Form", + type: 'plain_text', + text: 'Demo Modal Form', emoji: true }, submit: { - type: "plain_text", - text: "Submit", + type: 'plain_text', + text: 'Submit', emoji: true }, close: { - type: "plain_text", - text: "Cancel", + type: 'plain_text', + text: 'Cancel', emoji: true }, blocks: [ { - type: "input", + type: 'input', element: { - type: "plain_text_input", - action_id: "sl_input", + type: 'plain_text_input', + action_id: 'sl_input', placeholder: { - type: "plain_text", - text: "Placeholder text for single-line input" + type: 'plain_text', + text: 'Placeholder text for single-line input' } }, label: { - type: "plain_text", - text: "Subject" + type: 'plain_text', + text: 'Subject' }, hint: { - type: "plain_text", - text: "Short description or subject line" + type: 'plain_text', + text: 'Short description or subject line' } }, { - type: "input", + type: 'input', element: { - type: "plain_text_input", - action_id: "ml_input", + type: 'plain_text_input', + action_id: 'ml_input', multiline: true, placeholder: { - type: "plain_text", - text: "Placeholder text for multi-line input" + type: 'plain_text', + text: 'Placeholder text for multi-line input' } }, label: { - type: "plain_text", - text: "Details" + type: 'plain_text', + text: 'Details' }, hint: { - type: "plain_text", - text: "Long description" + type: 'plain_text', + text: 'Long description' } } ] @@ -69,9 +69,9 @@ def modal_payload(trigger_id) team_id = command[:team_id] trigger_id = command[:trigger_id] command.logger.info "Opening a modal with trigger_id: #{trigger_id}." - team = Team.find_by(team_id: team_id) + team = Team.find_by(team_id:) slack_client = Slack::Web::Client.new(token: team.token) - slack_client.views_open(modal_payload trigger_id) + slack_client.views_open(modal_payload(trigger_id)) nil end end diff --git a/bot/slash_commands/quiz.rb b/bot/slash_commands/quiz.rb index 6cbbc46..167c828 100644 --- a/bot/slash_commands/quiz.rb +++ b/bot/slash_commands/quiz.rb @@ -3,35 +3,35 @@ def quiz_message(question, channel_id) channel: channel_id, "blocks": [ { - "type": "section", + "type": 'section', "text": { - "type": "plain_text", + "type": 'plain_text', "text": question, "emoji": true } }, { - "type": "actions", + "type": 'actions', "elements": [ { - "type": "button", + "type": 'button', "text": { - "type": "plain_text", - "text": "Yes", + "type": 'plain_text', + "text": 'Yes', "emoji": true }, - "value": "reply_yes", - "action_id": "reply_yes" + "value": 'reply_yes', + "action_id": 'reply_yes' }, { - "type": "button", + "type": 'button', "text": { - "type": "plain_text", - "text": "No", + "type": 'plain_text', + "text": 'No', "emoji": true }, - "value": "reply_no", - "action_id": "reply_no" + "value": 'reply_no', + "action_id": 'reply_no' } ] } @@ -45,10 +45,10 @@ def quiz_message(question, channel_id) team_id = command[:team_id] channel_id = command[:channel_id] command.logger.info "Someone started a quiz in channel #{channel_id}." - question = "Can octopuses change their color? :octopus:" - team = Team.find_by(team_id: team_id) + question = 'Can octopuses change their color? :octopus:' + team = Team.find_by(team_id:) slack_client = Slack::Web::Client.new(token: team.token) - slack_client.chat_postMessage(quiz_message question, channel_id) + slack_client.chat_postMessage(quiz_message(question, channel_id)) nil end end From b011d81005196106b34dadef20b19eb3636696f7 Mon Sep 17 00:00:00 2001 From: crazyoptimist Date: Sun, 29 Oct 2023 18:20:38 -0500 Subject: [PATCH 5/5] chore: tinker ci --- .env.example | 6 +++++- .github/workflows/build-lint.yaml | 2 ++ docker-compose.yaml | 33 +++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 0691407..29a9c1d 100644 --- a/.env.example +++ b/.env.example @@ -3,7 +3,11 @@ RAILS_SECRET_TOKEN="replacemeasap" RAILS_HOST_NAME=your-domain.com BASE_URL=https://${RAILS_HOST_NAME} -MONGO_URL="mongodb://user:password@myhost1.mydomain.com:27017/my_db" +DATABASE_USER=user +DATABASE_PASSWORD=password +DATABASE_HOST=db +DATABASE_NAME=slack_bot_dev +MONGO_URL="mongodb://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}:27017/${DATABASE_NAME}" SLACK_CLIENT_ID= SLACK_CLIENT_SECRET= diff --git a/.github/workflows/build-lint.yaml b/.github/workflows/build-lint.yaml index a0c82a8..fb21182 100644 --- a/.github/workflows/build-lint.yaml +++ b/.github/workflows/build-lint.yaml @@ -21,6 +21,7 @@ env: TAG: ${{ github.sha }} DOCKER_BUILDKIT: 1 COMPOSE_DOCKER_CLI_BUILD: 1 + MONGO_URL: "mongodb://user:password@db:27017/slack_bot_dev" jobs: build: @@ -99,6 +100,7 @@ jobs: - name: Run Rubocop run: >- [ -f "db/schema.rb" ] && chmod 777 db/schema.rb; + cp .env.example .env; docker compose run -T web sh -c "bundle exec rubocop --parallel --format junit --out rubocop.xml" - name: Publish Linting Report uses: mikepenz/action-junit-report@v3 diff --git a/docker-compose.yaml b/docker-compose.yaml index 1981f3d..4aa1f72 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,10 +1,15 @@ version: "3.9" -services: +volumes: + db: - rails_api: - container_name: rails_api - build: . +services: + web: + image: "${IMAGE_URI}" + build: + target: web + context: . + dockerfile: Dockerfile volumes: - "./:/app/" - "./log:/app/log" @@ -12,3 +17,23 @@ services: - "3000:3000" command: bash -c "rails s -b 0.0.0.0" restart: unless-stopped + depends_on: + db: + condition: service_started + + db: + image: mongo:4 + volumes: + - db:/data/db/ + ports: + - 27017:27017 + restart: always + environment: + MONGO_INITDB_ROOT_USERNAME: ${DATABASE_USER} + MONGO_INITDB_ROOT_PASSWORD: ${DATABASE_PASSWORD} + command: --quiet + logging: + driver: "json-file" + options: + max-size: "200k" + max-file: "10"