Skip to content

Commit c10fecf

Browse files
authored
feat: list actively polled repos (#20)
1 parent d454f26 commit c10fecf

File tree

3 files changed

+102
-3
lines changed

3 files changed

+102
-3
lines changed

lib/algora/integrations/github/poller/comments.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ defmodule Algora.Github.Poller.Comments do
8080
{:reply, {state.repo_owner, state.repo_name}, state}
8181
end
8282

83+
@impl true
84+
def handle_call(:is_paused, _from, state) do
85+
{:reply, false, state}
86+
end
87+
8388
defp schedule_poll do
8489
Process.send_after(self(), :poll, @poll_interval)
8590
end

lib/algora/integrations/github/poller/supervisor.ex

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ defmodule Algora.Github.Poller.Supervisor do
44

55
alias Algora.Comments
66
alias Algora.Github.Poller.Comments, as: CommentsPoller
7+
alias Algora.Github.TokenPool
8+
alias Algora.Workspace
79

810
require Logger
911

@@ -30,8 +32,16 @@ defmodule Algora.Github.Poller.Supervisor do
3032
end
3133

3234
def add_repo(owner, name, opts \\ []) do
33-
spec = {CommentsPoller, [repo_owner: owner, repo_name: name] ++ opts}
34-
DynamicSupervisor.start_child(__MODULE__, spec)
35+
token = TokenPool.get_token()
36+
37+
case Workspace.ensure_repository(token, owner, name) do
38+
{:ok, _repository} ->
39+
spec = {CommentsPoller, [repo_owner: owner, repo_name: name] ++ opts}
40+
DynamicSupervisor.start_child(__MODULE__, spec)
41+
42+
error ->
43+
error
44+
end
3545
end
3646

3747
def terminate_child(owner, name) do

lib/algora_web/live/swift_bounties_live.ex

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ defmodule AlgoraWeb.SwiftBountiesLive do
44

55
import AlgoraWeb.Components.Bounties
66
import AlgoraWeb.Components.Footer
7+
import Ecto.Query
78

89
alias Algora.Bounties
10+
alias Algora.Repo
11+
alias AlgoraWeb.Components.Logos
912

1013
def mount(_params, _session, socket) do
1114
if connected?(socket) do
@@ -21,6 +24,7 @@ defmodule AlgoraWeb.SwiftBountiesLive do
2124
|> assign(:page_description, "Help grow the Swift ecosystem by funding the work we all depend on.")
2225
|> assign(:page_image, "#{AlgoraWeb.Endpoint.url()}/images/og/swift.png")
2326
|> assign_tickets()
27+
|> assign_active_repos()
2428
end
2529

2630
{:ok, socket}
@@ -104,7 +108,7 @@ defmodule AlgoraWeb.SwiftBountiesLive do
104108
</.link>
105109
</div>
106110
</div>
107-
<div class="mx-auto mt-16 flex max-w-2xl sm:mt-24 lg:mt-0 lg:mr-0 lg:ml-10 lg:max-w-none xl:ml-24">
111+
<div class="mx-auto mt-16 flex max-w-2xl sm:mt-24 lg:mt-0 lg:mr-0 lg:ml-10 lg:max-w-none xl:ml-24 2xl:ml-32">
108112
<div class="max-w-3xl sm:max-w-5xl sm:flex-none lg:max-w-none">
109113
<.card class="-mx-3 bg-card/25 sm:mx-0" id="how-it-works">
110114
<.card_header class="-mx-3 sm:mx-0">
@@ -415,6 +419,45 @@ defmodule AlgoraWeb.SwiftBountiesLive do
415419
<% end %>
416420
</div>
417421
422+
<div class="mx-auto max-w-7xl py-24 sm:px-6 sm:py-32 lg:px-8">
423+
<div class="relative isolate overflow-hidden px-6 text-center shadow-2xl sm:rounded-3xl sm:px-16">
424+
<div class="flex items-center justify-center gap-4">
425+
<code class="inline-block rounded bg-orange-950/75 px-1 py-0.5 font-mono text-sm text-orange-400 ring-1 ring-orange-400/25">
426+
/bounty $1000
427+
</code>
428+
<code class="inline-block rounded bg-orange-950/75 px-1 py-0.5 font-mono text-sm text-orange-400 ring-1 ring-orange-400/25">
429+
/tip $500 @username
430+
</code>
431+
</div>
432+
<h2 class="mt-6 text-balance font-display text-4xl font-semibold tracking-tight text-white sm:text-5xl">
433+
Get Started Now
434+
</h2>
435+
<p class="mx-auto mt-6 max-w-xl font-medium text-lg/8 text-gray-300">
436+
You can create bounties and send tips on any of the Swift repositories below once you've connected your GitHub account.
437+
</p>
438+
<div class="mt-6 flex items-center justify-center gap-x-6">
439+
<.link
440+
href={Algora.Github.authorize_url()}
441+
rel="noopener"
442+
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"
443+
>
444+
<Logos.github class="-ml-1 mr-2 h-6 w-6 sm:h-8 sm:w-8" /> Connect with GitHub
445+
</.link>
446+
</div>
447+
<div class="mt-10 grid grid-cols-3 gap-4">
448+
<%= for repo <- @repos do %>
449+
<.link href={repo.url}>
450+
<img
451+
src={repo.og_image_url}
452+
alt={repo.name}
453+
class="rounded-lg aspect-[1200/630] w-full h-full bg-muted"
454+
/>
455+
</.link>
456+
<% end %>
457+
</div>
458+
</div>
459+
</div>
460+
418461
<div class="relative">
419462
<.footer />
420463
</div>
@@ -435,4 +478,45 @@ defmodule AlgoraWeb.SwiftBountiesLive do
435478

436479
assign(socket, :tickets, tickets)
437480
end
481+
482+
defp assign_active_repos(socket) do
483+
active_pollers =
484+
Enum.reduce(Algora.Github.Poller.Supervisor.which_children(), [], fn {_, pid, _, _}, acc ->
485+
{owner, name} = GenServer.call(pid, :get_repo_info)
486+
487+
case Algora.Github.Poller.Supervisor.find_child(owner, name) do
488+
{_, pid, _, _} ->
489+
if GenServer.call(pid, :is_paused) do
490+
acc
491+
else
492+
[{owner, name} | acc]
493+
end
494+
495+
_ ->
496+
acc
497+
end
498+
end)
499+
500+
# Build dynamic OR conditions for each owner/name pair
501+
conditions =
502+
Enum.reduce(active_pollers, false, fn {owner, name}, acc_query ->
503+
if acc_query do
504+
dynamic([r, u], ^acc_query or (u.provider_login == ^owner and r.name == ^name))
505+
else
506+
dynamic([r, u], u.provider_login == ^owner and r.name == ^name)
507+
end
508+
end)
509+
510+
repos =
511+
Repo.all(
512+
from(r in Algora.Workspace.Repository,
513+
join: u in assoc(r, :user),
514+
where: r.provider == "github",
515+
where: ^conditions,
516+
preload: [user: u]
517+
)
518+
)
519+
520+
assign(socket, :repos, repos)
521+
end
438522
end

0 commit comments

Comments
 (0)