Skip to content

Commit 764ecb4

Browse files
committed
refactor: simplify installation token resolution logic
- Replaced nested case statements with a `with` construct for clearer flow in the `resolve_installation_and_token` function. - Improved readability and maintainability by reducing indentation and handling errors more succinctly.
1 parent 812c342 commit 764ecb4

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

lib/algora/workspace/workspace.ex

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,15 @@ defmodule Algora.Workspace do
5353
@spec resolve_installation_and_token(integer() | nil, String.t(), User.t()) ::
5454
{:ok, %{installation_id: integer() | nil, token: String.t()}} | {:error, atom()}
5555
def resolve_installation_and_token(installation_id, repo_owner, fallback_user) do
56-
resolved_installation_id = installation_id || get_installation_id_by_owner(repo_owner)
57-
58-
if resolved_installation_id do
59-
case Github.get_installation_token(resolved_installation_id) do
60-
{:ok, token} -> {:ok, %{installation_id: resolved_installation_id, token: token}}
61-
error -> error
62-
end
56+
with id when not is_nil(id) <- installation_id || get_installation_id_by_owner(repo_owner),
57+
{:ok, token} <- Github.get_installation_token(id) do
58+
{:ok, %{installation_id: id, token: token}}
6359
else
64-
case Accounts.get_access_token(fallback_user) do
65-
{:ok, token} -> {:ok, %{installation_id: nil, token: token}}
66-
error -> error
67-
end
60+
_ ->
61+
case Accounts.get_access_token(fallback_user) do
62+
{:ok, token} -> {:ok, %{installation_id: nil, token: token}}
63+
error -> error
64+
end
6865
end
6966
end
7067

0 commit comments

Comments
 (0)