Skip to content

Commit

Permalink
Add Quality check.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpursley committed Dec 29, 2023
1 parent 38f7b68 commit 5cda574
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ jobs:
run: mix deps.get
- name: Run tests
run: mix test --exclude skip_ci
- name: Check code quality, security and format
run: |
mix quality --strict
working-directory: libraries/elixir
1 change: 0 additions & 1 deletion lib/mix/tasks/database/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ defmodule Mix.Tasks.Helpers do
{output, _status} ->
output
end
|> IO.inspect()
end
end
8 changes: 4 additions & 4 deletions lib/walex/decoder/decoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ defmodule WalEx.Postgres.Decoder do
alias Messages.{
Begin,
Commit,
Delete,
Insert,
Origin,
Relation,
Relation.Column,
Insert,
Update,
Delete,
Truncate,
Type,
Unsupported
Unsupported,
Update
}

alias WalEx.Postgres.OidDatabase
Expand Down
2 changes: 1 addition & 1 deletion lib/walex/destinations/destinations.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule WalEx.Destinations do
use GenServer

alias WalEx.{Event, Destinations, Helpers, TransactionFilter}
alias WalEx.{Destinations, Event, Helpers, TransactionFilter}
alias Destinations.{EventRelay, Webhooks}

def start_link(_) do
Expand Down
4 changes: 2 additions & 2 deletions lib/walex/destinations/event_relay.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ defmodule WalEx.Destinations.EventRelay do

alias ERWeb.Grpc.Eventrelay
alias Eventrelay.Events.Stub, as: Client
alias Eventrelay.PublishEventsRequest
alias Eventrelay.NewEvent
alias Eventrelay.{NewEvent, PublishEventsRequest}

alias WalEx.{Config, Helpers}

@spec start_link(any()) :: :ignore | {:error, any()} | {:ok, pid()}
def start_link(_) do
GenServer.start_link(__MODULE__, %{}, name: __MODULE__)
end
Expand Down
16 changes: 8 additions & 8 deletions lib/walex/replication/publisher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ defmodule WalEx.Replication.Publisher do
@impl true
def handle_cast(
%{message: %Messages.Insert{relation_id: relation_id, tuple_data: tuple_data}},
%State{
state = %State{
transaction: {lsn, %{commit_timestamp: commit_timestamp, changes: changes} = txn},
relations: relations
} = state
}
)
when is_map(relations) do
case Map.fetch(relations, relation_id) do
Expand Down Expand Up @@ -130,10 +130,10 @@ defmodule WalEx.Replication.Publisher do
tuple_data: tuple_data
}
},
%State{
state = %State{
relations: relations,
transaction: {lsn, %{commit_timestamp: commit_timestamp, changes: changes} = txn}
} = state
}
)
when is_map(relations) do
case Map.fetch(relations, relation_id) do
Expand Down Expand Up @@ -172,10 +172,10 @@ defmodule WalEx.Replication.Publisher do
changed_key_tuple_data: changed_key_tuple_data
}
},
%State{
state = %State{
relations: relations,
transaction: {lsn, %{commit_timestamp: commit_timestamp, changes: changes} = txn}
} = state
}
)
when is_map(relations) do
case Map.fetch(relations, relation_id) do
Expand Down Expand Up @@ -206,10 +206,10 @@ defmodule WalEx.Replication.Publisher do
@impl true
def handle_cast(
%{message: %Messages.Truncate{truncated_relations: truncated_relations}},
%State{
state = %State{
relations: relations,
transaction: {lsn, %{commit_timestamp: commit_timestamp, changes: changes} = txn}
} = state
}
)
when is_list(truncated_relations) and is_list(changes) and is_map(relations) do
new_changes =
Expand Down
2 changes: 1 addition & 1 deletion lib/walex/replication/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule WalEx.Replication.Server do
end

@impl true
def handle_result([%Postgrex.Result{rows: rows} | _results], %{step: :create_slot} = state) do
def handle_result([%Postgrex.Result{rows: rows} | _results], state = %{step: :create_slot}) do
slot_name = rows |> hd |> hd

publication =
Expand Down
2 changes: 1 addition & 1 deletion lib/walex/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ defmodule WalEx.Supervisor do
use Supervisor

alias WalEx.Config, as: WalExConfig
alias WalExConfig.Registry, as: WalExRegistry
alias WalEx.Replication.Supervisor, as: ReplicationSupervisor
alias WalEx.{Destinations, Events}
alias WalExConfig.Registry, as: WalExRegistry
alias Destinations.{EventRelay, Webhooks}

def child_spec(opts) do
Expand Down
4 changes: 2 additions & 2 deletions lib/walex/transaction_filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ defmodule WalEx.TransactionFilter do
alias WalEx.Changes.{
DeletedRecord,
NewRecord,
UpdatedRecord,
Transaction
Transaction,
UpdatedRecord
}

alias WalEx.Postgres.Decoder.Messages.Relation.Column
Expand Down
2 changes: 1 addition & 1 deletion lib/walex/types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ defmodule WalEx.Types do
# |> String.split(",")
# end

# # TODO: Before extracting out WalEx, create a dynamic function that can take custom decoders
# # TODO: Create a dynamic function that can take custom decoders
# defp cast_record(record, "geography") when is_binary(record) do
# case Geo.WKB.decode(record) do
# {:ok, geo} ->
Expand Down
24 changes: 22 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ defmodule WalEx.MixProject do
description: description(),
package: package(),
deps: deps(),
aliases: aliases(),
name: "WalEx",
source_url: "https://github.com/cpursley/walex"
source_url: "https://github.com/cpursley/walex",
test_coverage: [tool: ExCoveralls]
]
end

Expand All @@ -36,7 +38,12 @@ defmodule WalEx.MixProject do
{:uniq, "~> 0.6.1"},
{:eventrelay_client, "~> 0.1.0"},
# {:eventrelay_client, github: "eventrelay/eventrelay_client_elixir", branch: "main"},
{:webhoox, "~> 0.3.0"}
{:webhoox, "~> 0.3.0"},

# Test
{:sobelow, "~> 0.12", only: [:dev, :test], runtime: false},
{:credo, "~> 1.6", only: [:dev, :test], runtime: false},
{:excoveralls, "~> 0.10", only: [:dev, :test], runtime: false}
]
end

Expand All @@ -52,4 +59,17 @@ defmodule WalEx.MixProject do
links: %{"GitHub" => "https://github.com/cpursley/walex"}
]
end

defp aliases do
[
# Run tests and check coverage
test: ["test", "coveralls"],
# Run to check the quality of your code
quality: [
"format --check-formatted",
"sobelow --config",
"credo"
]
]
end
end
5 changes: 5 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
%{
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"castore": {:hex, :castore, "1.0.5", "9eeebb394cc9a0f3ae56b813459f990abb0a3dedee1be6b27fdb50301930502f", [:mix], [], "hexpm", "8d7c597c3e4a64c395980882d4bca3cebb8d74197c590dc272cfd3b6a6310578"},
"certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"},
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"},
"cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"},
"cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"},
"credo": {:hex, :credo, "1.7.2", "fdee3a7cb553d8f2e773569181f0a4a2bb7d192e27e325404cc31b354f59d68c", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "dd15d6fbc280f6cf9b269f41df4e4992dee6615939653b164ef951f60afcb68e"},
"db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"eventrelay_client": {:hex, :eventrelay_client, "0.1.0", "b81a469f573fc418171995d1816da3bac96450b5a9cc0cb998b0eba2f0803e6c", [:mix], [{:grpc, "~> 0.7.0", [hex: :grpc, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:protobuf, "~> 0.11", [hex: :protobuf, repo: "hexpm", optional: false]}], "hexpm", "29909f607248848d3bd62983382d7dd82c93325fad3b4c4b967f4f70823101f7"},
"ex_doc": {:hex, :ex_doc, "0.31.0", "06eb1dfd787445d9cab9a45088405593dd3bb7fe99e097eaa71f37ba80c7a676", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5350cafa6b7f77bdd107aa2199fe277acf29d739aba5aee7e865fc680c62a110"},
"excoveralls": {:hex, :excoveralls, "0.18.0", "b92497e69465dc51bc37a6422226ee690ab437e4c06877e836f1c18daeb35da9", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1109bb911f3cb583401760be49c02cbbd16aed66ea9509fc5479335d284da60b"},
"expo": {:hex, :expo, "0.4.1", "1c61d18a5df197dfda38861673d392e642649a9cef7694d2f97a587b2cfb319b", [:mix], [], "hexpm", "2ff7ba7a798c8c543c12550fa0e2cbc81b95d4974c65855d8d15ba7b37a1ce47"},
"file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"},
"finch": {:hex, :finch, "0.16.0", "40733f02c89f94a112518071c0a91fe86069560f5dbdb39f9150042f44dcfb1a", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f660174c4d519e5fec629016054d60edd822cdfe2b7270836739ac2f97735ec5"},
"gettext": {:hex, :gettext, "0.23.1", "821e619a240e6000db2fc16a574ef68b3bd7fe0167ccc264a81563cc93e67a31", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "19d744a36b809d810d610b57c27b934425859d158ebd56561bc41f7eeb8795db"},
"grpc": {:hex, :grpc, "0.7.0", "a86eab356b0b84406b526786a947ca50e9b9eae87108c873b51e321f8a71e8ed", [:mix], [{:cowboy, "~> 2.10", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowlib, "~> 2.12", [hex: :cowlib, repo: "hexpm", optional: false]}, {:gun, "~> 2.0", [hex: :gun, repo: "hexpm", optional: false]}, {:mint, "~> 1.5", [hex: :mint, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "632a9507da8d3c12b112b197db4d60da3c95bad02594d37711eeb622d032f254"},
Expand All @@ -36,6 +40,7 @@
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
"req": {:hex, :req, "0.4.8", "2b754a3925ddbf4ad78c56f30208ced6aefe111a7ea07fb56c23dccc13eb87ae", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.9", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "7146e51d52593bb7f20d00b5308a5d7d17d663d6e85cd071452b613a8277100c"},
"retry": {:hex, :retry, "0.18.0", "dc58ebe22c95aa00bc2459f9e0c5400e6005541cf8539925af0aa027dc860543", [:mix], [], "hexpm", "9483959cc7bf69c9e576d9dfb2b678b71c045d3e6f39ab7c9aa1489df4492d73"},
"sobelow": {:hex, :sobelow, "0.13.0", "218afe9075904793f5c64b8837cc356e493d88fddde126a463839351870b8d1e", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cd6e9026b85fc35d7529da14f95e85a078d9dd1907a9097b3ba6ac7ebbe34a0d"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"timex": {:hex, :timex, "3.7.11", "bb95cb4eb1d06e27346325de506bcc6c30f9c6dea40d1ebe390b262fad1862d1", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.20", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 1.1", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "8b9024f7efbabaf9bd7aa04f65cf8dcd7c9818ca5737677c7b76acbc6a94d1aa"},
Expand Down

0 comments on commit 5cda574

Please sign in to comment.