Skip to content

Commit 2064bbf

Browse files
authored
Merge pull request #139 from yknx4/feature/only-show-repos-you-are-admin-or-are-installed
feat: only show repos you are admin or are installed
2 parents 47f264e + 5b1aebd commit 2064bbf

File tree

8 files changed

+87
-62
lines changed

8 files changed

+87
-62
lines changed

lib/librecov/data.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ defmodule Librecov.Data do
2828
2929
"""
3030
def list_repositories(%{provider: "github", token: token, refresh_token: _refresh_token}) do
31-
Repos.available_repos(token, sort: "pushed")
31+
Repos.available_repos(token, sort: "pushed", per_page: 100)
3232
end
3333

3434
@doc """

lib/librecov_web/live/repository_live/build_row.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule Librecov.RepositoryLive.BuildRow do
66
alias Surface.Components.Link
77
alias Librecov.RepositoryLive.CoverageDiff
88
alias Surface.Components.LiveRedirect
9+
alias Librecov.Common.Icon
910

1011
prop build, :struct, required: true
1112

@@ -36,7 +37,7 @@ defmodule Librecov.RepositoryLive.BuildRow do
3637
<span class="fw-semibold">
3738
{@build.commit_message}
3839
{#if @build.commit_sha}
39-
<Link to={commit_link(@build.project, @build.commit_sha)}><i class={"fab #{repository_class(@build.project)}"} /></Link>
40+
<Link to={commit_link(@build.project, @build.commit_sha)}><Icon family="fab" icon={repository_class(@build.project)} /></Link>
4041
{/if}
4142
</span>
4243
</td>

lib/librecov_web/live/repository_live/index.html.heex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
</h2>
1414
<div class="row">
1515
<%= for repository <- @repositories do %>
16-
<div class="col-md-6">
1716
<%= live_component Librecov.RepositoryLive.RepositoryCard, repository: repository, projects: @projects %>
18-
</div>
1917
<% end %>
2018
</div>
2119
</div>

lib/librecov_web/live/repository_live/repository_card.ex

Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -31,63 +31,71 @@ defmodule Librecov.RepositoryLive.RepositoryCard do
3131

3232
topics = repo.topics || []
3333

34-
~F"""
35-
<div class="block block-rounded block-bordered block-fx-pop">
36-
<div class="block-header block-header-default">
37-
<h3 class="block-title">
38-
{#if !is_nil(project.id)}
39-
<LiveRedirect
40-
label={@repository.full_name}
41-
to={Routes.repository_show_path(@socket, :show, @repository.owner.login, @repository.name)}
42-
/>
43-
{#else}
44-
{@repository.full_name}
45-
{/if}
46-
</h3>
47-
<div class="block-options">
48-
{#if is_nil(project.id)}
49-
<Link class="btn-block-option" to={"#{@repository.html_url}/settings/installations"} opts={target: "_blank"}><i class="si si-settings" /></Link>
50-
{/if}
51-
</div>
52-
</div>
53-
<div class={"block-content block-content-full ribbon ribbon-#{coverage_badge(project.current_coverage)} ribbon-bookmark"}>
54-
{#if !is_nil(project.id)}
55-
<div class="ribbon-box">
56-
{format_coverage(project.current_coverage)}
34+
if is_nil(project.id) && repo.permissions.admin == false do
35+
~F"""
36+
37+
"""
38+
else
39+
~F"""
40+
<div class="col-md-6">
41+
<div class="block block-rounded block-bordered block-fx-pop">
42+
<div class="block-header block-header-default">
43+
<h3 class="block-title">
44+
{#if !is_nil(project.id)}
45+
<LiveRedirect
46+
label={@repository.full_name}
47+
to={Routes.repository_show_path(@socket, :show, @repository.owner.login, @repository.name)}
48+
/>
49+
{#else}
50+
{@repository.full_name}
51+
{/if}
52+
</h3>
53+
<div class="block-options">
54+
{#if is_nil(project.id)}
55+
<Link class="btn-block-option" to={"#{@repository.html_url}/settings/installations"} opts={target: "_blank"}><i class="si si-settings" /></Link>
56+
{/if}
57+
</div>
5758
</div>
58-
{/if}
59-
{#if !is_nil(@repository.description)}
60-
<p>{@repository.description}</p>
61-
{/if}
62-
{#if !is_nil(latest_build) && !is_nil(latest_build.commit_message)}
63-
<p class="card-text text-muted">
64-
<LiveRedirect
65-
class="text-muted"
66-
label={latest_build.commit_message}
67-
to={Routes.build_show_path(@socket, :show, latest_build)}
68-
/>
69-
{#if !is_nil(latest_build.branch)}
70-
on branch <span class="font-italic">{latest_build.branch}</span>
59+
<div class={"block-content block-content-full ribbon ribbon-#{coverage_badge(project.current_coverage)} ribbon-bookmark"}>
60+
{#if !is_nil(project.id)}
61+
<div class="ribbon-box">
62+
{format_coverage(project.current_coverage)}
63+
</div>
7164
{/if}
72-
</p>
73-
{/if}
74-
{#for item <- topics}
75-
<Link
76-
label={item}
77-
to={"https://github.com/topics/#{item}"}
78-
class="badge rounded-pill bg-secondary"
79-
opts={target: "_blank"}
80-
/>
81-
{/for}
82-
</div>
83-
<div class="block-content bg-light px-4 py-2 m-0">
84-
{#if !is_nil(repo.language)}
85-
<small class="text-muted pe-2"><i class="fas fa-code" /> {repo.language}
86-
</small>
87-
{/if}
88-
<small class="text-muted"><i class="fas fa-history" /> Updated {latest_update |> Timex.from_now()}</small>
65+
{#if !is_nil(@repository.description)}
66+
<p>{@repository.description}</p>
67+
{/if}
68+
{#if !is_nil(latest_build) && !is_nil(latest_build.commit_message)}
69+
<p class="card-text text-muted">
70+
<LiveRedirect
71+
class="text-muted"
72+
label={latest_build.commit_message}
73+
to={Routes.build_show_path(@socket, :show, latest_build)}
74+
/>
75+
{#if !is_nil(latest_build.branch)}
76+
on branch <span class="font-italic">{latest_build.branch}</span>
77+
{/if}
78+
</p>
79+
{/if}
80+
{#for item <- topics}
81+
<Link
82+
label={item}
83+
to={"https://github.com/topics/#{item}"}
84+
class="badge rounded-pill bg-secondary"
85+
opts={target: "_blank"}
86+
/>
87+
{/for}
88+
</div>
89+
<div class="block-content bg-light px-4 py-2 m-0">
90+
{#if !is_nil(repo.language)}
91+
<small class="text-muted pe-2"><i class="fas fa-code" /> {repo.language}
92+
</small>
93+
{/if}
94+
<small class="text-muted"><i class="fas fa-history" /> Updated {latest_update |> Timex.from_now()}</small>
95+
</div>
96+
</div>
8997
</div>
90-
</div>
91-
"""
98+
"""
99+
end
92100
end
93101
end

lib/web/services/github_service.ex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ defmodule Librecov.GithubService do
1414
handle_check_suite(payload["action"], payload)
1515
end
1616

17+
def handle("installation", payload) do
18+
handle_installation(payload["action"], payload)
19+
end
20+
1721
def handle(event, _payload) do
1822
Logger.debug("Unhandled event: #{event}")
1923
end
@@ -34,6 +38,17 @@ defmodule Librecov.GithubService do
3438
Logger.warn("Unhandled pr event: #{event}")
3539
end
3640

41+
def handle_installation("created", payload) do
42+
repos = payload["repositories"] || []
43+
44+
repos
45+
|> Enum.each(&install/1)
46+
end
47+
48+
def handle_installation(action, _payload) do
49+
Logger.warn("Unhandled installation action: #{action}")
50+
end
51+
3752
defp install(%{"id" => repo_id, "full_name" => name, "html_url" => base_url}) do
3853
with {:ok, %Project{}} <-
3954
Repo.insert(
@@ -48,4 +63,7 @@ defmodule Librecov.GithubService do
4863
Logger.info("Installed Repo #{name}")
4964
end
5065
end
66+
67+
defp install(%{"id" => _, "full_name" => name} = data),
68+
do: install(%{data | "html_url" => "https://github.com/" <> name})
5169
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"<div class=\"content\" id=\"repositories-index\"><h2 class=\"content-heading\">\n Repos\n </h2><div class=\"row\"><div class=\"col-md-6\"><div class=\"block block-rounded block-bordered block-fx-pop\"><div class=\"block-header block-header-default\"><h3 class=\"block-title\"><a data-phx-link=\"redirect\" data-phx-link-state=\"push\" href=\"/repositories/octocat/Hello-World\">octocat/Hello-World</a></h3><div class=\"block-options\"></div></div><div class=\"block-content block-content-full ribbon ribbon-danger ribbon-bookmark\"><div class=\"ribbon-box\">\n 50.0%\n </div><p>This your first repo!</p><p class=\"card-text text-muted\"><a class=\"text-muted\" data-phx-link=\"redirect\" data-phx-link-state=\"push\" href=\"/builds/443\">oie shi</a>\n\n \n on branch <span class=\"font-italic\">main</span></p><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/octocat\">octocat</a><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/atom\">atom</a><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/electron\">electron</a><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/api\">api</a></div><div class=\"block-content bg-light px-4 py-2 m-0\"><small class=\"text-muted\"><i class=\"fas fa-history\"></i> Updated now</small></div></div></div></div></div>"
1+
"<div class=\"content\" id=\"repositories-index\"><h2 class=\"content-heading\">\n Repos\n </h2><div class=\"row\"><div class=\"col-md-6\"><div class=\"block block-rounded block-bordered block-fx-pop\"><div class=\"block-header block-header-default\"><h3 class=\"block-title\"><a data-phx-link=\"redirect\" data-phx-link-state=\"push\" href=\"/repositories/octocat/Hello-World\">octocat/Hello-World</a></h3><div class=\"block-options\"></div></div><div class=\"block-content block-content-full ribbon ribbon-danger ribbon-bookmark\"><div class=\"ribbon-box\">\n 50.0%\n </div><p>This your first repo!</p><p class=\"card-text text-muted\"><a class=\"text-muted\" data-phx-link=\"redirect\" data-phx-link-state=\"push\" href=\"/builds/443\">oie shi</a>\n\n \n on branch <span class=\"font-italic\">main</span></p><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/octocat\">octocat</a><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/atom\">atom</a><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/electron\">electron</a><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/api\">api</a></div><div class=\"block-content bg-light px-4 py-2 m-0\"><small class=\"text-muted\"><i class=\"fas fa-history\"></i> Updated now</small></div></div></div></div></div>"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"<div class=\"content\" id=\"repositories-index\"><h2 class=\"content-heading\">\n Repos\n </h2><div class=\"row\"><div class=\"col-md-6\"><div class=\"block block-rounded block-bordered block-fx-pop\"><div class=\"block-header block-header-default\"><h3 class=\"block-title\">\n \n octocat/Hello-World\n \n </h3><div class=\"block-options\"><a target=\"_blank\" class=\"btn-block-option\" href=\"https://github.com/octocat/Hello-World/settings/installations\"><i class=\"si si-settings\"></i></a></div></div><div class=\"block-content block-content-full ribbon ribbon-info ribbon-bookmark\"><p>This your first repo!</p><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/octocat\">octocat</a><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/atom\">atom</a><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/electron\">electron</a><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/api\">api</a></div><div class=\"block-content bg-light px-4 py-2 m-0\"><small class=\"text-muted\"><i class=\"fas fa-history\"></i> Updated 10 years ago</small></div></div></div></div></div>"
1+
"<div class=\"content\" id=\"repositories-index\"><h2 class=\"content-heading\">\n Repos\n </h2><div class=\"row\"><div class=\"col-md-6\"><div class=\"block block-rounded block-bordered block-fx-pop\"><div class=\"block-header block-header-default\"><h3 class=\"block-title\">\n \n octocat/Hello-World\n \n </h3><div class=\"block-options\"><a target=\"_blank\" class=\"btn-block-option\" href=\"https://github.com/octocat/Hello-World/settings/installations\"><i class=\"si si-settings\"></i></a></div></div><div class=\"block-content block-content-full ribbon ribbon-info ribbon-bookmark\"><p>This your first repo!</p><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/octocat\">octocat</a><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/atom\">atom</a><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/electron\">electron</a><a target=\"_blank\" class=\"badge rounded-pill bg-secondary\" href=\"https://github.com/topics/api\">api</a></div><div class=\"block-content bg-light px-4 py-2 m-0\"><small class=\"text-muted\"><i class=\"fas fa-history\"></i> Updated 10 years ago</small></div></div></div></div></div>"

0 commit comments

Comments
 (0)