From 554eaedc4764d120355e7a58f94ddd57f445d3cf Mon Sep 17 00:00:00 2001 From: Jandro Oliva Date: Wed, 6 May 2026 23:37:16 +0200 Subject: [PATCH 1/6] test: verify format hook --- config/config.exs | 10 ++++++++++ mix.exs | 1 + 2 files changed, 11 insertions(+) diff --git a/config/config.exs b/config/config.exs index 1cae58c..d0f5555 100644 --- a/config/config.exs +++ b/config/config.exs @@ -20,6 +20,16 @@ import Config # # config :logger, level: :info # +config :git_hooks, + auto_install: true, + hooks: [ + pre_commit: [ + tasks: [ + {:cmd, "mix format --check-formatted"} + ] + ] + ] + config :td_cache, redis_host: System.get_env("REDIS_HOST", "redis"), port: String.to_integer(System.get_env("REDIS_PORT", "6380")) diff --git a/mix.exs b/mix.exs index 799057b..c32d9f3 100644 --- a/mix.exs +++ b/mix.exs @@ -31,6 +31,7 @@ defmodule TdCache.MixProject do {:decimal, "~> 2.3"}, {:credo, "~> 1.7.11", only: [:dev, :test], runtime: false}, {:dialyxir, "~> 1.4", only: :dev, runtime: false}, + {:git_hooks, "~> 0.7", only: :dev, runtime: false}, {:ex_machina, "~> 2.8", only: :test}, {:graph, git: "https://github.com/Bluetab/graph.git", tag: "8.3.0"}, {:jason, "~> 1.4"}, From b6d963fa2813836eff97a964f6361815c775c9fc Mon Sep 17 00:00:00 2001 From: Jandro Oliva Date: Wed, 6 May 2026 23:40:35 +0200 Subject: [PATCH 2/6] chore: update mix.lock with git_hooks dependency --- mix.lock | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mix.lock b/mix.lock index 600fe86..45456a7 100644 --- a/mix.lock +++ b/mix.lock @@ -8,9 +8,11 @@ "erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"}, "ex_machina": {:hex, :ex_machina, "2.8.0", "a0e847b5712065055ec3255840e2c78ef9366634d62390839d4880483be38abe", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "79fe1a9c64c0c1c1fab6c4fa5d871682cb90de5885320c187d117004627a7729"}, "file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"}, + "git_hooks": {:hex, :git_hooks, "0.8.1", "1f6a1b065638e07ed89a49804dac6c24d8ac8d27c8f9fd0e9620d5bef8c30f41", [:mix], [{:recase, "~> 0.8.0", [hex: :recase, repo: "hexpm", optional: false]}], "hexpm", "267d8b82615ad439177b2a4bc2efadb7491ec1c8520dacc67ddc38c251448cbc"}, "graph": {:git, "https://github.com/Bluetab/graph.git", "b71054befe048625aeff0b3e964567d1611c96fd", [tag: "8.3.0"]}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, "nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"}, + "recase": {:hex, :recase, "0.8.1", "ab98cd35857a86fa5ca99036f575241d71d77d9c2ab0c39aacf1c9b61f6f7d1d", [:mix], [], "hexpm", "9fd8d63e7e43bd9ea385b12364e305778b2bbd92537e95c4b2e26fc507d5e4c2"}, "redix": {:hex, :redix, "1.5.2", "ab854435a663f01ce7b7847f42f5da067eea7a3a10c0a9d560fa52038fd7ab48", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:nimble_options, "~> 0.5.0 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "78538d184231a5d6912f20567d76a49d1be7d3fca0e1aaaa20f4df8e1142dcb8"}, "telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"}, } From ef4b61cea0bfccdc08effad209ca159a8835e9cf Mon Sep 17 00:00:00 2001 From: Jandro Oliva Date: Thu, 7 May 2026 09:40:42 +0200 Subject: [PATCH 3/6] fix: check staged content in pre-commit format hook --- config/config.exs | 2 +- scripts/pre_commit.sh | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100755 scripts/pre_commit.sh diff --git a/config/config.exs b/config/config.exs index d0f5555..6b23bde 100644 --- a/config/config.exs +++ b/config/config.exs @@ -25,7 +25,7 @@ config :git_hooks, hooks: [ pre_commit: [ tasks: [ - {:cmd, "mix format --check-formatted"} + {:file, "scripts/pre_commit.sh"} ] ] ] diff --git a/scripts/pre_commit.sh b/scripts/pre_commit.sh new file mode 100755 index 0000000..1d08c21 --- /dev/null +++ b/scripts/pre_commit.sh @@ -0,0 +1,13 @@ +#!/bin/sh +STAGED=$(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.(ex|exs)$' || true) +[ -z "$STAGED" ] && exit 0 + +BEFORE=$(git stash list | wc -l) +git stash push --keep-index -q 2>/dev/null || true +AFTER=$(git stash list | wc -l) + +mix format --check-formatted $STAGED +RESULT=$? + +[ "$AFTER" -gt "$BEFORE" ] && git stash pop -q 2>/dev/null || true +exit $RESULT From 3c172c8626559483ff38d667b9e3a03e62a60d9a Mon Sep 17 00:00:00 2001 From: Jandro Oliva Date: Thu, 7 May 2026 11:52:30 +0200 Subject: [PATCH 4/6] chore: add quality CI check, remove git_hooks --- .github/workflows/main.yml | 2 +- config/config.exs | 10 ---------- lib/td_cache/audit.ex | 1 + lib/td_cache/permissions.ex | 2 +- lib/td_cache/session_cache.ex | 1 + mix.exs | 8 +++++++- scripts/pre_commit.sh | 13 ------------- 7 files changed, 11 insertions(+), 26 deletions(-) delete mode 100755 scripts/pre_commit.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 515309d..0093308 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,7 +23,7 @@ jobs: otp-version: "27.2" elixir-version: "1.18.1" - run: mix deps.get - - run: mix credo --strict + - run: mix quality - run: mix test env: REDIS_HOST: localhost diff --git a/config/config.exs b/config/config.exs index 6b23bde..1cae58c 100644 --- a/config/config.exs +++ b/config/config.exs @@ -20,16 +20,6 @@ import Config # # config :logger, level: :info # -config :git_hooks, - auto_install: true, - hooks: [ - pre_commit: [ - tasks: [ - {:file, "scripts/pre_commit.sh"} - ] - ] - ] - config :td_cache, redis_host: System.get_env("REDIS_HOST", "redis"), port: String.to_integer(System.get_env("REDIS_PORT", "6380")) diff --git a/lib/td_cache/audit.ex b/lib/td_cache/audit.ex index 6741a32..bfa854a 100644 --- a/lib/td_cache/audit.ex +++ b/lib/td_cache/audit.ex @@ -13,6 +13,7 @@ defmodule TdCache.Audit do events |> Enum.map(&create_event/1) + |> Publisher.publish(stream(), maxlen: maxlen) end diff --git a/lib/td_cache/permissions.ex b/lib/td_cache/permissions.ex index e84b1a7..dbac6d6 100644 --- a/lib/td_cache/permissions.ex +++ b/lib/td_cache/permissions.ex @@ -1,6 +1,6 @@ defmodule TdCache.Permissions do @moduledoc """ - Shared cache for permissions. + Shared cache for permissionss. """ alias TdCache.AclCache diff --git a/lib/td_cache/session_cache.ex b/lib/td_cache/session_cache.ex index 4598e0b..bca68d1 100644 --- a/lib/td_cache/session_cache.ex +++ b/lib/td_cache/session_cache.ex @@ -8,6 +8,7 @@ defmodule TdCache.SessionCache do @spec put(map()) :: :ok | {:error, any()} def put(%{"jti" => jti, "exp" => exp}) do + put(jti, exp) end diff --git a/mix.exs b/mix.exs index c32d9f3..568b07d 100644 --- a/mix.exs +++ b/mix.exs @@ -8,6 +8,7 @@ defmodule TdCache.MixProject do elixir: "~> 1.18", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod, + aliases: aliases(), deps: deps() ] end @@ -31,11 +32,16 @@ defmodule TdCache.MixProject do {:decimal, "~> 2.3"}, {:credo, "~> 1.7.11", only: [:dev, :test], runtime: false}, {:dialyxir, "~> 1.4", only: :dev, runtime: false}, - {:git_hooks, "~> 0.7", only: :dev, runtime: false}, {:ex_machina, "~> 2.8", only: :test}, {:graph, git: "https://github.com/Bluetab/graph.git", tag: "8.3.0"}, {:jason, "~> 1.4"}, {:redix, "~> 1.5"} ] end + + defp aliases do + [ + quality: ["format --check-formatted", "credo --strict"] + ] + end end diff --git a/scripts/pre_commit.sh b/scripts/pre_commit.sh deleted file mode 100755 index 1d08c21..0000000 --- a/scripts/pre_commit.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -STAGED=$(git diff --cached --name-only --diff-filter=ACMR | grep -E '\.(ex|exs)$' || true) -[ -z "$STAGED" ] && exit 0 - -BEFORE=$(git stash list | wc -l) -git stash push --keep-index -q 2>/dev/null || true -AFTER=$(git stash list | wc -l) - -mix format --check-formatted $STAGED -RESULT=$? - -[ "$AFTER" -gt "$BEFORE" ] && git stash pop -q 2>/dev/null || true -exit $RESULT From 740fede43a65fb01138eca5155df4c585189172f Mon Sep 17 00:00:00 2001 From: Jandro Oliva Date: Thu, 7 May 2026 12:05:25 +0200 Subject: [PATCH 5/6] fix: remove unnecessary blank lines and correct typo in module documentation --- lib/td_cache/audit.ex | 1 - lib/td_cache/permissions.ex | 2 +- lib/td_cache/session_cache.ex | 1 - mix.lock | 2 -- 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/td_cache/audit.ex b/lib/td_cache/audit.ex index bfa854a..6741a32 100644 --- a/lib/td_cache/audit.ex +++ b/lib/td_cache/audit.ex @@ -13,7 +13,6 @@ defmodule TdCache.Audit do events |> Enum.map(&create_event/1) - |> Publisher.publish(stream(), maxlen: maxlen) end diff --git a/lib/td_cache/permissions.ex b/lib/td_cache/permissions.ex index dbac6d6..e84b1a7 100644 --- a/lib/td_cache/permissions.ex +++ b/lib/td_cache/permissions.ex @@ -1,6 +1,6 @@ defmodule TdCache.Permissions do @moduledoc """ - Shared cache for permissionss. + Shared cache for permissions. """ alias TdCache.AclCache diff --git a/lib/td_cache/session_cache.ex b/lib/td_cache/session_cache.ex index bca68d1..4598e0b 100644 --- a/lib/td_cache/session_cache.ex +++ b/lib/td_cache/session_cache.ex @@ -8,7 +8,6 @@ defmodule TdCache.SessionCache do @spec put(map()) :: :ok | {:error, any()} def put(%{"jti" => jti, "exp" => exp}) do - put(jti, exp) end diff --git a/mix.lock b/mix.lock index 45456a7..600fe86 100644 --- a/mix.lock +++ b/mix.lock @@ -8,11 +8,9 @@ "erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"}, "ex_machina": {:hex, :ex_machina, "2.8.0", "a0e847b5712065055ec3255840e2c78ef9366634d62390839d4880483be38abe", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "79fe1a9c64c0c1c1fab6c4fa5d871682cb90de5885320c187d117004627a7729"}, "file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"}, - "git_hooks": {:hex, :git_hooks, "0.8.1", "1f6a1b065638e07ed89a49804dac6c24d8ac8d27c8f9fd0e9620d5bef8c30f41", [:mix], [{:recase, "~> 0.8.0", [hex: :recase, repo: "hexpm", optional: false]}], "hexpm", "267d8b82615ad439177b2a4bc2efadb7491ec1c8520dacc67ddc38c251448cbc"}, "graph": {:git, "https://github.com/Bluetab/graph.git", "b71054befe048625aeff0b3e964567d1611c96fd", [tag: "8.3.0"]}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, "nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"}, - "recase": {:hex, :recase, "0.8.1", "ab98cd35857a86fa5ca99036f575241d71d77d9c2ab0c39aacf1c9b61f6f7d1d", [:mix], [], "hexpm", "9fd8d63e7e43bd9ea385b12364e305778b2bbd92537e95c4b2e26fc507d5e4c2"}, "redix": {:hex, :redix, "1.5.2", "ab854435a663f01ce7b7847f42f5da067eea7a3a10c0a9d560fa52038fd7ab48", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:nimble_options, "~> 0.5.0 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "78538d184231a5d6912f20567d76a49d1be7d3fca0e1aaaa20f4df8e1142dcb8"}, "telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"}, } From a11f140fc8167831e9ae330601150472e16937b0 Mon Sep 17 00:00:00 2001 From: Jandro Oliva Date: Thu, 7 May 2026 22:11:01 +0200 Subject: [PATCH 6/6] chore: update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 290db4c..3172fff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Added + +- [TD-8168] Add code quality control + ## [8.3.0] 2026-03-12 ### Changed