We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 8f94a39 + 1cce405 commit 27ec3e7Copy full SHA for 27ec3e7
config/config.exs
@@ -59,7 +59,8 @@ config :event_bus,
59
:pull_request_synced,
60
:inserted,
61
:updated,
62
- :build_finished
+ :build_finished,
63
+ :check_suite_requested
64
]
65
66
config :ueberauth, Ueberauth,
lib/librecov_web/live/build_live/job_row.ex
@@ -29,7 +29,7 @@ defmodule Librecov.RepositoryLive.JobRow do
29
</span>
30
</td>
31
<td class="text-start d-none d-sm-table-cell">
32
- {@job.run_at |> human_time_ago}
+ {(@job.run_at || @job.updated_at) |> human_time_ago}
33
34
<td class="text-center d-none d-sm-table-cell">
35
{@job.files_count}
lib/opencov/services/github/auth.ex
@@ -18,6 +18,18 @@ defmodule Librecov.Services.Github.Auth do
18
19
def with_auth_data(nil, _), do: {:error, :nil_input}
20
21
+ def with_auth_data(
22
+ %{
23
+ "installation" => %{"id" => installation_id},
24
+ "repository" => %{"name" => repo, "owner" => %{"login" => owner}}
25
+ },
26
+ block
27
+ ) do
28
+ with {:ok, token} <- login_token_for(:installation_id, installation_id) do
+ apply(block, [%AuthData{token: token, owner: owner, repo: repo}])
+ end
+
def with_auth_data(%Project{} = project, block) do
with {owner, repo} <- Project.name_and_owner(project) do
with_auth_data(owner, repo, block)
@@ -53,6 +65,15 @@ defmodule Librecov.Services.Github.Auth do
53
jwt
54
end
55
67
68
+ def login_token_for(:installation_id, installation_id) do
69
+ with {:ok, token} <-
70
+ app_token()
71
+ |> Connection.new()
72
+ |> Apps.apps_create_installation_access_token(installation_id) do
73
+ {:ok, token.token}
74
75
76
56
77
def login_token(login) do
57
78
with {:ok, installations} <-
58
79
app_token()
lib/opencov/services/github/checks.ex
@@ -63,6 +63,8 @@ defmodule Librecov.Services.Github.Checks do
}
) do
Logger.info("Finished check of commit #{commit} with diff: #{cov_dif} coverage: #{cov}.")
+ Logger.info("#{commit_check |> inspect() |> Jason.encode!(pretty: true)}")
+ Logger.info("#{diff_check |> inspect() |> Jason.encode!(pretty: true)}")
{:ok, [commit_check, diff_check]}
lib/opencov/subscribers/github_subscriber.ex
@@ -10,7 +10,7 @@ defmodule Librecov.Subscriber.GithubSubscriber do
10
alias Librecov.Templates.CommentTemplate
11
alias Librecov.Services.Github.AuthData
12
13
- @topics [:build_finished, :pull_request_synced]
+ @topics [:build_finished, :pull_request_synced, :check_suite_requested]
14
15
def topics, do: @topics
16
@@ -39,13 +39,10 @@ defmodule Librecov.Subscriber.GithubSubscriber do
39
end)
40
41
42
- def process(%Event{topic: :pull_request_synced, data: payload}) do
43
- with %{"after" => commit, "repository" => repo} <- payload,
44
- %{"name" => repo, "owner" => %{"login" => owner}} <- repo do
45
- Auth.with_auth_data(owner, repo, fn auth ->
46
- Checks.create_check(auth, commit)
47
- end)
48
- end
+ def process(%Event{topic: :check_suite_requested, data: payload}) do
+ Auth.with_auth_data(payload, fn auth ->
+ Checks.create_check(auth, payload["check_suite"]["head_sha"])
+ end)
49
50
51
def process(%Event{}) do
lib/opencov/templates/comment_template.ex
@@ -23,7 +23,7 @@ defmodule Librecov.Templates.CommentTemplate do
} = build,
%{
- head: %{user: %{login: username}},
+ user: %{login: username},
base: %{ref: base_branch, sha: base_commit}
lib/web/services/github_service.ex
@@ -10,10 +10,22 @@ defmodule Librecov.GithubService do
install(payload["repository"])
+ def handle("check_suite", payload) do
+ handle_check_suite(payload["action"], payload)
17
def handle(event, _payload) do
Logger.debug("Unhandled event: #{event}")
+ defp handle_check_suite(action, payload) when action in ["rerequested", "requested"] do
+ %Event{id: UUID.uuid1(), topic: :check_suite_requested, data: payload} |> EventBus.notify()
+ defp handle_check_suite(action, _payload) do
+ Logger.debug("Unhandled action: #{action}")
def handle_pr("synchronize", payload) do
%Event{id: UUID.uuid1(), topic: :pull_request_synced, data: payload} |> EventBus.notify()
test/lib/templates/comments_template_test.exs
@@ -17,7 +17,7 @@ defmodule Librecov.Templates.CommentTemplateTest do
test "barebones template #1" do
template =
CommentTemplate.coverage_message(@base_build, %{
- head: %{user: %{login: "github"}},
+ user: %{login: "github"},
base: %{ref: "potato", sha: "chettos"}
})
@@ -28,7 +28,7 @@ defmodule Librecov.Templates.CommentTemplateTest do
test "barebones template #2" do
CommentTemplate.coverage_message(%Build{@base_build | coverage: 50.1234}, %{
@@ -41,7 +41,7 @@ defmodule Librecov.Templates.CommentTemplateTest do
CommentTemplate.coverage_message(
%Build{@base_build | coverage: 50.1234, previous_coverage: 30.2345},
)
test/librecov_web/live/build_live_test.exs
@@ -24,7 +24,7 @@ defmodule LibrecovWeb.BuildLiveTest do
commit_sha: "",
commit_message: "oie shi",
branch: "main",
- inserted_at: Timex.now() |> Timex.beginning_of_day() |> Timex.to_datetime(),
+ inserted_at: Timex.now() |> Timex.shift(hours: -18) |> Timex.to_datetime(),
project: project
test/librecov_web/live/repository_live_test.exs
@@ -334,7 +334,7 @@ defmodule Librecov.RepositoryLiveTest do
334
335
336
337
338
project: p
339
340
0 commit comments