Skip to content

Commit dd004d6

Browse files
committed
move boilerplate to internal module
1 parent 3097633 commit dd004d6

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

lib/algora/bounties/jobs/notify_transfer.ex

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,12 @@ defmodule Algora.Bounties.Jobs.NotifyTransfer do
4949
end
5050

5151
defp do_perform(ticket_ref, body, nil) do
52-
if Github.pat_enabled() do
53-
Github.create_issue_comment(
54-
Github.pat(),
55-
ticket_ref["owner"],
56-
ticket_ref["repo"],
57-
ticket_ref["number"],
58-
body
59-
)
60-
else
61-
Logger.info("""
62-
Github.create_issue_comment(Github.pat(), "#{ticket_ref["owner"]}", "#{ticket_ref["repo"]}", #{ticket_ref["number"]},
63-
\"\"\"
64-
#{body}
65-
\"\"\")
66-
""")
67-
end
52+
Github.try_without_installation(&Github.create_issue_comment/5, [
53+
ticket_ref["owner"],
54+
ticket_ref["repo"],
55+
ticket_ref["number"],
56+
body
57+
])
6858
end
6959

7060
defp do_perform(ticket_ref, body, installation) do

lib/algora/integrations/github/github.ex

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ defmodule Algora.Github do
22
@moduledoc false
33
@behaviour Algora.Github.Behaviour
44

5+
require Logger
6+
57
@type token :: String.t()
68

79
def client_id, do: Algora.config([:github, :client_id])
@@ -43,6 +45,26 @@ defmodule Algora.Github do
4345

4446
defp client, do: Application.get_env(:algora, :github_client, Algora.Github.Client)
4547

48+
def try_without_installation(function, args) do
49+
if pat_enabled() do
50+
apply(function, [pat() | args])
51+
else
52+
{module, name} = Function.info(function, :name)
53+
function_name = "#{module}.#{name}"
54+
55+
formatted_args =
56+
Enum.map_join(args, ", ", fn
57+
arg when is_binary(arg) -> "\"#{arg}\""
58+
arg -> "#{arg}"
59+
end)
60+
61+
Logger.warning("""
62+
App installation not found and GITHUB_PAT_ENABLED is false, skipping Github call:
63+
#{function_name}(#{formatted_args})
64+
""")
65+
end
66+
end
67+
4668
@impl true
4769
def get_repository(token, owner, repo), do: client().get_repository(token, owner, repo)
4870

0 commit comments

Comments
 (0)