Skip to content

Commit

Permalink
Merge pull request #12 from egze/chore_fix_elixir_1_17_warnings
Browse files Browse the repository at this point in the history
chore: fix Elixir 1.17 warnings
  • Loading branch information
remotecom authored Aug 28, 2024
2 parents e904be6 + d04af28 commit d0b281b
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 50 deletions.
50 changes: 25 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
types: [opened, reopened, synchronize]
push:
branches:
- 'master'
- 'remote'
- "master"
- "remote"

jobs:
test:
Expand All @@ -18,39 +18,39 @@ jobs:
runs-on: ubuntu-latest
name: Test (OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}})
strategy:
matrix:
elixir: ['1.12']
# All of the above can use this version. For details see: https://hexdocs.pm/elixir/compatibility-and-deprecations.html#compatibility-between-elixir-and-erlang-otp
otp: [24]
matrix:
elixir: ["1.17"]
# All of the above can use this version. For details see: https://hexdocs.pm/elixir/compatibility-and-deprecations.html#compatibility-between-elixir-and-erlang-otp
otp: [26]
services:
stripe-mock:
image: stripe/stripe-mock:v0.125.0
ports:
- 12111:12111
- 12112:12112
stripe-mock:
image: stripe/stripe-mock:v0.125.0
ports:
- 12111:12111
- 12112:12112
steps:
- name: Clone code
uses: actions/checkout@v2
- name: Setup Elixir and Erlang
uses: erlef/setup-beam@v1
with:
- name: Clone code
uses: actions/checkout@v2
- name: Setup Elixir and Erlang
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- name: Mix Dependencies
run: mix deps.get
- name: Test
run: mix test
- name: Mix Dependencies
run: mix deps.get
- name: Test
run: mix test

lint:
runs-on: ubuntu-latest
name: Linting
strategy:
matrix:
elixir: ['1.12', '1.11', '1.10']
elixir: ["1.17", "1.16"]
# All of the above can use this version. For details see: https://hexdocs.pm/elixir/compatibility-and-deprecations.html#compatibility-between-elixir-and-erlang-otp
otp: [24, 23, 22]
otp: [26, 25]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
Expand All @@ -62,15 +62,15 @@ jobs:
path: ~/.mix
key: cache-${{ runner.os }}-${{ env.cache-name }}-${{ matrix.otp }}-${{ matrix.elixir }}
restore-keys: |
cache-${{ runner.os }}-${{ env.cache-name }}-
cache-${{ runner.os }}-${{ env.cache-name }}-
- uses: actions/cache@v1
env:
cache-name: build
with:
path: _build
key: cache-${{ runner.os }}-${{ env.cache-name }}-${{ matrix.otp }}-${{ matrix.elixir }}
restore-keys: |
cache-${{ runner.os }}-${{ env.cache-name }}-
cache-${{ runner.os }}-${{ env.cache-name }}-
- run: mix deps.get
- run: mix compile --warnings-as-errors
- run: mix dialyzer --halt-exit-status
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# The directory Mix downloads your dependencies sources to.
/deps/

# Dialyzer PLT files
/priv/plts/*.plt
/priv/plts/*.plt.hash

# Where third-party dependencies like ExDoc output generated docs.
/doc/

Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 26.1.2
elixir 1.16.0-otp-26
erlang 26.2.5.1
elixir 1.17.2-otp-26
16 changes: 10 additions & 6 deletions lib/stripe/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,10 @@ defmodule Stripe.API do
defp do_perform_request_and_retry(method, url, headers, body, opts, {:attempts, attempts}) do
{idempotency_key, attempt} = log_request(method, url, headers, attempts)

response = track_request_time(method, url, idempotency_key, attempt,
fn -> http_module().request(method, url, headers, body, opts) end
)
response =
track_request_time(method, url, idempotency_key, attempt, fn ->
http_module().request(method, url, headers, body, opts)
end)

do_perform_request_and_retry(
method,
Expand All @@ -404,7 +405,8 @@ defmodule Stripe.API do
attempt: attempt
}

:telemetry.span([:stripity_stripe, :request],
:telemetry.span(
[:stripity_stripe, :request],
start_metadata,
fn ->
result = request_fn.()
Expand All @@ -424,9 +426,11 @@ defmodule Stripe.API do
# attempts are 0-index based
attempt = "attempt=#{attempts + 1}"

Logger.info("[stripity_stripe] Performing #{http_method_url} #{attempt}#{idempotency_key_msg}")
Logger.info(
"[stripity_stripe] Performing #{http_method_url} #{attempt}#{idempotency_key_msg}"
)

{idempotency_key, attempts+1}
{idempotency_key, attempts + 1}
end

defp get_idempotency_key_from_headers(method, _headers) when method in [:get, :headers], do: nil
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/converter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ defmodule Stripe.Converter do
@spec convert_stripe_object(%{String.t() => any}) :: struct
defp convert_stripe_object(%{"object" => object_name} = value) do
module = Stripe.Util.object_name_to_module(object_name)
struct_keys = Map.keys(module.__struct__) |> List.delete(:__struct__)
struct_keys = Map.keys(module.__struct__()) |> List.delete(:__struct__)
check_for_extra_keys(struct_keys, value)

processed_map =
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/core_resources/charge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ defmodule Stripe.Charge do
livemode: boolean,
metadata: Stripe.Types.metadata(),
on_behalf_of: Stripe.id() | Stripe.Account.t() | nil,
order: Stripe.id() | Stripe.Order.t() | nil,
order: Stripe.id() | nil,
outcome: charge_outcome | nil,
paid: boolean,
payment_intent: Stripe.id() | Stripe.PaymentIntent.t() | nil,
Expand Down
3 changes: 2 additions & 1 deletion lib/stripe/core_resources/customer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ defmodule Stripe.Customer do
{:ok, cash_Balance} = Stripe.Customer.update_cash_balance("cus_123")
"""
@spec update_cash_balance(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
@spec update_cash_balance(Stripe.id() | t, params, Stripe.options()) ::
{:ok, t} | {:error, Stripe.Error.t()}
when params:
%{
optional(:settings) => Stripe.Types.metadata()
Expand Down
4 changes: 0 additions & 4 deletions lib/stripe/core_resources/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@ defmodule Stripe.Event do
| Stripe.FileUpload.t()
| Stripe.Invoice.t()
| Stripe.Invoiceitem.t()
| Stripe.Order.t()
| Stripe.OrderReturn.t()
| Stripe.Payout.t()
| Stripe.Plan.t()
| Stripe.Relay.Product.t()
| Stripe.Price.t()
| Stripe.Product.t()
| Stripe.Recipient.t()
| Stripe.Review.t()
| Stripe.Sku.t()
| Stripe.Source.t()
| Stripe.Transfer.t()
| map
Expand Down
3 changes: 2 additions & 1 deletion lib/stripe/core_resources/payment_intent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ defmodule Stripe.PaymentIntent do
See the [Stripe docs](https://stripe.com/docs/api/payment_intents/apply_customer_balance).
"""

@spec apply_customer_balance(Stripe.id() | t, params, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
@spec apply_customer_balance(Stripe.id() | t, params, Stripe.options()) ::
{:ok, t} | {:error, Stripe.Error.t()}
when params: %{
optional(:amount) => non_neg_integer,
optional(:currency) => String.t()
Expand Down
4 changes: 1 addition & 3 deletions lib/stripe/error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ defmodule Stripe.Error do
source: :network,
code: :network_error,
message:
"An error occurred while making the network request. The HTTP client returned the following reason: #{
inspect(reason)
}",
"An error occurred while making the network request. The HTTP client returned the following reason: #{inspect(reason)}",
extra: %{
hackney_reason: reason
}
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/payment_methods/card.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule Stripe.Card do
last4: String.t(),
metadata: Stripe.Types.metadata(),
name: String.t() | nil,
recipient: Stripe.id() | Stripe.Recipient.t() | nil,
recipient: Stripe.id() | nil,
tokenization_method: String.t() | nil
}

Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/relay/order_item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Stripe.OrderItem do
amount: pos_integer,
currency: String.t(),
description: String.t(),
parent: nil | Stripe.id() | Stripe.Sku.t(),
parent: nil | Stripe.id(),
quantity: nil | pos_integer,
type: String.t()
}
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/subscriptions/credit_note.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule Stripe.CreditNote do

@type discount :: %{
amount: integer,
discount: String.t(),
discount: String.t()
}

@type t :: %__MODULE__{
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe/subscriptions/credit_note_line_item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Stripe.CreditNoteLineItem do

@type discount :: %{
amount: integer,
discount: String.t(),
discount: String.t()
}

@type t :: %__MODULE__{
Expand Down
5 changes: 4 additions & 1 deletion lib/stripe/subscriptions/invoice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ defmodule Stripe.Invoice do
@spec upcoming(map, Stripe.options()) :: {:ok, t} | {:error, Stripe.Error.t()}
def upcoming(params, opts \\ [])
def upcoming(params = %{customer: _customer}, opts), do: get_upcoming(params, opts)
def upcoming(params = %{customer_details: _customer_details}, opts), do: get_upcoming(params, opts)

def upcoming(params = %{customer_details: _customer_details}, opts),
do: get_upcoming(params, opts)

def upcoming(params = %{subscription: _subscription}, opts), do: get_upcoming(params, opts)

defp get_upcoming(params, opts) do
Expand Down
2 changes: 1 addition & 1 deletion test/support/stripe_mock_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Stripe.StripeMockTest do

defp assert_port_open(port) do
delay()
assert {:ok, socket} = :gen_tcp.connect('localhost', port, [])
assert {:ok, socket} = :gen_tcp.connect(~c'localhost', port, [])
:gen_tcp.close(socket)
end

Expand Down

0 comments on commit d0b281b

Please sign in to comment.