diff --git a/lib/algora/integrations/github/poller/comments.ex b/lib/algora/integrations/github/poller/comments.ex index 4377e83a0..c64973d65 100644 --- a/lib/algora/integrations/github/poller/comments.ex +++ b/lib/algora/integrations/github/poller/comments.ex @@ -80,6 +80,11 @@ defmodule Algora.Github.Poller.Comments do {:reply, {state.repo_owner, state.repo_name}, state} end + @impl true + def handle_call(:is_paused, _from, state) do + {:reply, false, state} + end + defp schedule_poll do Process.send_after(self(), :poll, @poll_interval) end diff --git a/lib/algora/integrations/github/poller/supervisor.ex b/lib/algora/integrations/github/poller/supervisor.ex index 75c27beae..e4dc3f4d5 100644 --- a/lib/algora/integrations/github/poller/supervisor.ex +++ b/lib/algora/integrations/github/poller/supervisor.ex @@ -4,6 +4,8 @@ defmodule Algora.Github.Poller.Supervisor do alias Algora.Comments alias Algora.Github.Poller.Comments, as: CommentsPoller + alias Algora.Github.TokenPool + alias Algora.Workspace require Logger @@ -30,8 +32,16 @@ defmodule Algora.Github.Poller.Supervisor do end def add_repo(owner, name, opts \\ []) do - spec = {CommentsPoller, [repo_owner: owner, repo_name: name] ++ opts} - DynamicSupervisor.start_child(__MODULE__, spec) + token = TokenPool.get_token() + + case Workspace.ensure_repository(token, owner, name) do + {:ok, _repository} -> + spec = {CommentsPoller, [repo_owner: owner, repo_name: name] ++ opts} + DynamicSupervisor.start_child(__MODULE__, spec) + + error -> + error + end end def terminate_child(owner, name) do diff --git a/lib/algora_web/live/swift_bounties_live.ex b/lib/algora_web/live/swift_bounties_live.ex index a27935190..f71e1e994 100644 --- a/lib/algora_web/live/swift_bounties_live.ex +++ b/lib/algora_web/live/swift_bounties_live.ex @@ -4,8 +4,11 @@ defmodule AlgoraWeb.SwiftBountiesLive do import AlgoraWeb.Components.Bounties import AlgoraWeb.Components.Footer + import Ecto.Query alias Algora.Bounties + alias Algora.Repo + alias AlgoraWeb.Components.Logos def mount(_params, _session, socket) do if connected?(socket) do @@ -21,6 +24,7 @@ defmodule AlgoraWeb.SwiftBountiesLive do |> assign(:page_description, "Help grow the Swift ecosystem by funding the work we all depend on.") |> assign(:page_image, "#{AlgoraWeb.Endpoint.url()}/images/og/swift.png") |> assign_tickets() + |> assign_active_repos() end {:ok, socket} @@ -104,7 +108,7 @@ defmodule AlgoraWeb.SwiftBountiesLive do -
+
<.card class="-mx-3 bg-card/25 sm:mx-0" id="how-it-works"> <.card_header class="-mx-3 sm:mx-0"> @@ -415,6 +419,45 @@ defmodule AlgoraWeb.SwiftBountiesLive do <% end %>
+
+
+
+ + /bounty $1000 + + + /tip $500 @username + +
+

+ Get Started Now +

+

+ You can create bounties and send tips on any of the Swift repositories below once you've connected your GitHub account. +

+
+ <.link + href={Algora.Github.authorize_url()} + rel="noopener" + class="inline-flex h-12 items-center justify-center whitespace-nowrap rounded-md border border-white/80 bg-white px-6 text-lg font-semibold text-gray-900 shadow transition-colors hover:border-white hover:bg-white/90 focus-visible:outline-white-600 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 phx-submit-loading:opacity-75" + > + Connect with GitHub + +
+
+ <%= for repo <- @repos do %> + <.link href={repo.url}> + {repo.name} + + <% end %> +
+
+
+
<.footer />
@@ -435,4 +478,45 @@ defmodule AlgoraWeb.SwiftBountiesLive do assign(socket, :tickets, tickets) end + + defp assign_active_repos(socket) do + active_pollers = + Enum.reduce(Algora.Github.Poller.Supervisor.which_children(), [], fn {_, pid, _, _}, acc -> + {owner, name} = GenServer.call(pid, :get_repo_info) + + case Algora.Github.Poller.Supervisor.find_child(owner, name) do + {_, pid, _, _} -> + if GenServer.call(pid, :is_paused) do + acc + else + [{owner, name} | acc] + end + + _ -> + acc + end + end) + + # Build dynamic OR conditions for each owner/name pair + conditions = + Enum.reduce(active_pollers, false, fn {owner, name}, acc_query -> + if acc_query do + dynamic([r, u], ^acc_query or (u.provider_login == ^owner and r.name == ^name)) + else + dynamic([r, u], u.provider_login == ^owner and r.name == ^name) + end + end) + + repos = + Repo.all( + from(r in Algora.Workspace.Repository, + join: u in assoc(r, :user), + where: r.provider == "github", + where: ^conditions, + preload: [user: u] + ) + ) + + assign(socket, :repos, repos) + end end