Skip to content

Commit

Permalink
♻️ Full rewrite (#2)
Browse files Browse the repository at this point in the history
* 🔥 Clean existing repository

* 🎉 Initial commit

* 📝 Bring back old README

* 🚀 Bring back deployment configuration

* ➕ Add Credo dependency

* ➕ Add Dialyxir dependency

* 🚀 Integrate AppSignal

* ✨ Add more tooling

* 🔧 Add support for fetching env variables

* 👷 Initial GitHub Actions setup

* 🚚 Rename steps

* ✅ Add failing test

* ✨ Add the url_verification event handler

* ✅ Add failing test for the signature verifier's init function

* ✨ Add implementation

* ✅ Add failing test for the signature verification

* ✨ Finish implementation

* ✅ Add failing test for reaction_added event handler

* ✨ Add event handler for reaction_added event

* ✨ Add event supervisor and country to language code conversion

* ✨ Add simple translation

No advanced escaping for now

* 🎨 Code formatter gave up

* ✅ Add failing test for emoji escaping

* ✨ Add basic implementation

* ✅ Add nightmare difficulty of test

* ⚡️ Fix implementation

* ✅ Add failing test for global mentions

* 🐛 Add global mention removal

* ✅ Add failing test for username escaping

* ✨ Add implementation for username escaping

* ✅ Add failing test for escaping channel names

* ✨ Add implementation

* ✨ Add Message struct to unescape message prior to sending it

* ⚡️ Simplify channel escaping

Ref: https://api.slack.com/reference/surfaces/formatting#linking-channels

* ⚡️ Improve escape regexs

* ✅ Add test for channel unescaping

* ✨ Add implementation

* 🐛 Fix Credo warnings

* ✅ Add failing test for URL escaping

* ✨ Add implementation

* ✅ Add failing test for URL/mail link escape

* ✨ Add implementation

* ✅ Add failing test for fetching user profile

* ✨ Add implementation

* ✨ Unescape usernames, step 1

* ✨ Add querying Slack API for usernames

* ✨ Replace username placeholders with real usernames

* 📸 Add caching usernames in database

* ✨ Finish username unescaping

* ✅ Add failing test for escaping codeblocks and inline code

* ✨ Add implementation

* ✨ Add code unescaping

* ⚡️ Make escaping more robust

* ✅ Add failing test for refreshing stale username data

* ✨ Add implementation

* ✨ Add footer block with permalink to original message

* ✨ Add translation log

* 🏷️ Fix type annotations

* ✨ Add accessory menu to a translation block

* ✅ Fix tests

* ✨ Add empty action handler

* ✨ Add sending ephemeral message when translation is deleted

* ✨ Add message deletion

* ✨ Add recording translation message details

* ✅ Add failing test for translation message deletion marking

* ✨ Add implementation

* ✨ Add /translate command

* ✨ Add feedback message

* 👷 Integrate CD

* 👷 Temporarily whitelist rewrite branch to deploy

* 🐛 Last minute fixes
  • Loading branch information
Cellane authored Jul 20, 2021
1 parent 662f925 commit 4ad8c0d
Show file tree
Hide file tree
Showing 79 changed files with 2,854 additions and 1,322 deletions.
2 changes: 1 addition & 1 deletion .buildpacks
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
https://github.com/HashNuke/heroku-buildpack-elixir.git
https://github.com/gjaldon/heroku-buildpack-phoenix-static
https://github.com/gjaldon/heroku-buildpack-phoenix-static.git
189 changes: 189 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# If you find anything wrong or unclear in this file, please report an
# issue on GitHub: https://github.com/rrrene/credo/issues
#
%{
#
# You can have as many configs as you like in the `configs:` field.
configs: [
%{
#
# Run any config using `mix credo -C <name>`. If no config name is given
# "default" is used.
#
name: "default",
#
# These are the files included in the analysis:
files: %{
#
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
#
included: [
"lib/",
"src/",
"test/",
"web/",
"apps/*/lib/",
"apps/*/src/",
"apps/*/test/",
"apps/*/web/"
],
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
},
#
# Load and configure plugins here:
#
plugins: [],
#
# If you create your own checks, you must specify the source files for
# them here, so they can be loaded by Credo before running the analysis.
#
requires: [],
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: true,
#
# To modify the timeout for parsing files, change this value:
#
parse_timeout: 5000,
#
# If you want to use uncolored output by default, you can change `color`
# to `false` below:
#
color: true,
#
# You can customize the parameters of any check by adding a second element
# to the tuple.
#
# To disable a check put `false` as second element:
#
# {Credo.Check.Design.DuplicatedCode, false}
#
checks: [
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Consistency.SpaceAroundOperators, []},
{Credo.Check.Consistency.SpaceInParentheses, []},
{Credo.Check.Consistency.TabsOrSpaces, []},

#
## Design Checks
#
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage,
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
# You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).
#
{Credo.Check.Design.TagTODO, [exit_status: 2]},
{Credo.Check.Design.TagFIXME, []},

#
## Readability Checks
#
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, []},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.PredicateFunctionNames, []},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, []},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SpaceAfterCommas, []},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
{Credo.Check.Readability.VariableNames, []},

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, []},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, []},
# {Credo.Check.Refactor.MapInto, []},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},

#
## Warnings
#
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
# {Credo.Check.Warning.LazyLogging, []},
{Credo.Check.Warning.MixEnv, false},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
{Credo.Check.Warning.UnusedEnumOperation, []},
{Credo.Check.Warning.UnusedFileOperation, []},
{Credo.Check.Warning.UnusedKeywordOperation, []},
{Credo.Check.Warning.UnusedListOperation, []},
{Credo.Check.Warning.UnusedPathOperation, []},
{Credo.Check.Warning.UnusedRegexOperation, []},
{Credo.Check.Warning.UnusedStringOperation, []},
{Credo.Check.Warning.UnusedTupleOperation, []},
{Credo.Check.Warning.UnsafeExec, []},

#
# Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`)

#
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
#
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
{Credo.Check.Consistency.UnusedVariableNames, false},
{Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Readability.AliasAs, false},
{Credo.Check.Readability.BlockPipe, false},
{Credo.Check.Readability.ImplTrue, false},
{Credo.Check.Readability.MultiAlias, false},
{Credo.Check.Readability.SeparateAliasRequire, false},
{Credo.Check.Readability.SinglePipe, false},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Readability.StrictModuleLayout, false},
{Credo.Check.Readability.WithCustomTaggedTuple, false},
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false},
{Credo.Check.Refactor.DoubleBooleanNegation, false},
{Credo.Check.Refactor.ModuleDependencies, false},
{Credo.Check.Refactor.NegatedIsNil, false},
{Credo.Check.Refactor.PipeChainStart, false},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.LeakyEnvironment, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Warning.UnsafeToAtom, false}

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
]
}
26 changes: 26 additions & 0 deletions .doctor.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
%Doctor.Config{
exception_moduledoc_required: true,
failed: false,
ignore_modules: [
DeepThought.Application,
DeepThought.Repo,
DeepThoughtWeb,
DeepThoughtWeb.Endpoint,
DeepThoughtWeb.ErrorHelpers,
DeepThoughtWeb.ErrorView,
DeepThoughtWeb.LayoutView,
DeepThoughtWeb.Router,
DeepThoughtWeb.Telemetry,
DeepThoughtWeb.UserSocket
],
ignore_paths: [],
min_module_doc_coverage: 100,
min_module_spec_coverage: 100,
min_overall_doc_coverage: 100,
min_overall_spec_coverage: 100,
moduledoc_required: true,
raise: true,
reporter: Doctor.Reporters.Full,
struct_type_spec_required: true,
umbrella: false
}
98 changes: 98 additions & 0 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: default

on: [push]

env:
APPSIGNAL_OTP_APP: deep_thought
APPSIGNAL_APP_NAME: Deep Thought
APPSIGNAL_APP_ENV: ci
APPSIGNAL_PUSH_API_KEY: ${{ secrets.APPSIGNAL_PUSH_API_KEY }}
DEEPL_AUTH_KEY: auth_key
ELIXIR_VERSION: 1.12.1
MIX_ENV: dev
OTP_VERSION: 24.0.3
SLACK_BOT_TOKEN: bot_token
SLACK_SIGNING_SECRET: signing_secret

jobs:
test:
name: Test
runs-on: ubuntu-latest

services:
db:
image: postgres:latest
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Erlang/OTP and Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}

- name: Restore dependencies cache
uses: actions/cache@v2
with:
path: |
deps
_build
key: ${{ runner.os }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-mix-
- name: Fetch dependencies
run: mix deps.get

- name: Check code formatting
run: mix format --check-formatted

- name: Compile the code
run: mix compile --warnings-as-errors

- name: Run a test suite
run: MIX_ENV=test mix test

- name: Run the Credo static code analysis tool
run: mix credo --strict

- name: Run Doctor
run: mix doctor

- name: Restore PLTs cache
uses: actions/cache@v2
with:
path: priv/plts
key: ${{ runner.os }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-plts-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.OTP_VERSION }}-${{ env.ELIXIR_VERSION }}-plts-
- name: Run Dialyzer
run: mix dialyzer

deploy:
if: github.ref == 'refs/heads/master'
name: Deploy
needs: [test]
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Deploy to Lightsail
uses: dokku/[email protected]
with:
git_push_flags: --force
git_remote_url: ${{ secrets.GIT_REMOTE_URL }}
ssh_host_key: ${{ secrets.SSH_HOST_KEY }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ npm-debug.log
/priv/static/

/.env
/.vscode
/priv/plts/*.plt
/priv/plts/*.plt.hash
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ To deploy _Deep Thought_, you first need to create a Slack application, then con
always_online: true
slash_commands:
- command: /translate
url: https://YOUR.DOMAIN.HERE/slack/commands/translate
url: https://YOUR.DOMAIN.HERE/slack/commands
description:
Translate your message, sending both the translation and original
text to the channel
Expand Down
Loading

0 comments on commit 4ad8c0d

Please sign in to comment.