Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/algora_web/live/user/profile_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ defmodule AlgoraWeb.User.ProfileLive do
<h2 class="text-lg font-semibold">Top Contributions</h2>
<%= for {owner, contributions} <- aggregate_contributions(@contributions) do %>
<.link
href={"https://github.com/#{owner.provider_login}/#{List.first(contributions).repository.name}/pulls?q=author%3A#{@user.provider_login}+is%3Amerged+"}
href={contribution_search_url(owner, @user)}
target="_blank"
rel="noopener"
class="flex items-center gap-3 rounded-xl pr-2 bg-card/50 border border-border/50 hover:border-border transition-all group"
Expand Down Expand Up @@ -345,4 +345,11 @@ defmodule AlgoraWeb.User.ProfileLive do
|> Enum.map(& &1.contribution_count)
|> Enum.sum()
end

defp contribution_search_url(owner, user) do
scope = if owner.type in [:organization, "organization"], do: "org", else: "user"
query = "author:#{user.provider_login} is:merged #{scope}:#{owner.provider_login}"

"https://github.com/pulls?q=#{URI.encode_www_form(query)}"
end
end
39 changes: 39 additions & 0 deletions test/algora_web/live/user/profile_live_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
defmodule AlgoraWeb.User.ProfileLiveTest do
use AlgoraWeb.ConnCase, async: false

import Algora.Factory
import Phoenix.LiveViewTest

alias Algora.Repo
alias Algora.Workspace.UserContribution

test "links organization contribution cards to owner-wide pull search", %{conn: conn} do
user = insert(:user, handle: "contributor", provider_login: "contributor")
org = insert(:organization, display_name: "Transloadit", provider_login: "transloadit")

repo_a = insert(:repository, user_id: org.id, name: "uppy", tech_stack: ["TypeScript"], stargazers_count: 500)

repo_b =
insert(:repository, user_id: org.id, name: "tus-js-client", tech_stack: ["TypeScript"], stargazers_count: 250)

insert_contribution!(user, repo_a, 2)
insert_contribution!(user, repo_b, 3)

{:ok, _view, html} = live(conn, ~p"/#{user.handle}/profile")
assert html =~ "Transloadit"
assert html =~ "github.com/pulls"
assert html =~ "author%3Acontributor+is%3Amerged+org%3Atransloadit"
refute html =~ "github.com/transloadit/uppy/pulls"
end

defp insert_contribution!(user, repository, contribution_count) do
%UserContribution{}
|> UserContribution.changeset(%{
user_id: user.id,
repository_id: repository.id,
contribution_count: contribution_count,
last_fetched_at: DateTime.utc_now()
})
|> Repo.insert!()
end
end