diff --git a/c_src/git_nif.c b/c_src/git_nif.c
index ea04ccc..a01f603 100644
--- a/c_src/git_nif.c
+++ b/c_src/git_nif.c
@@ -596,15 +596,16 @@ static ERL_NIF_TERM log_push_commit (ErlNifEnv *env,
int i;
int count;
const git_signature *sig;
- ERL_NIF_TERM k[6] = {
+ ERL_NIF_TERM k[7] = {
enif_make_atom(env, "author_email"),
enif_make_atom(env, "message"),
enif_make_atom(env, "author"),
enif_make_atom(env, "parents"),
enif_make_atom(env, "hash"),
- enif_make_atom(env, "date")
+ enif_make_atom(env, "date"),
+ enif_make_atom(env, "ci_status")
};
- ERL_NIF_TERM v[6];
+ ERL_NIF_TERM v[7];
ERL_NIF_TERM parent_sha;
ERL_NIF_TERM parents = enif_make_list(env, 0);
git_oid_tostr(buf, sizeof(buf), git_commit_id(commit));
@@ -624,8 +625,9 @@ static ERL_NIF_TERM log_push_commit (ErlNifEnv *env,
v[2] = enif_string_to_term(env, sig->name);
v[0] = enif_string_to_term(env, sig->email);
}
- enif_make_map_from_arrays(env, k, v, 6, &res);
- return enif_make_list_cell(env, res, (ERL_NIF_TERM)acc);
+ v[6] = enif_make_atom(env, "nil");
+ enif_make_map_from_arrays(env, k, v, 7, &res);
+ return enif_make_list_cell(env, res, (ERL_NIF_TERM) acc);
}
ERL_NIF_TERM log_nif (ErlNifEnv *env, int argc,
diff --git a/lib/kmxgit_web/controllers/repository_controller.ex b/lib/kmxgit_web/controllers/repository_controller.ex
index c2e8932..946f64a 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -202,7 +202,7 @@ defmodule KmxgitWeb.RepositoryController do
|> Enum.reject(&(!&1 || &1 == ""))
|> Enum.join("/")
path3 = if path2 != "", do: path2
- %OpParams{path: path3}
+ %OpParams{path: "/#{path3}"}
_ ->
nil
end
@@ -370,7 +370,14 @@ defmodule KmxgitWeb.RepositoryController do
defp git_put_log1(git = %{valid: true}, repo, tree, path) do
slug = Repository.full_slug(repo)
log1 = case Git.log(slug, tree, path || "", 0, 1) do
- {:ok, [log1]} -> log1
+ {:ok, [log1]} ->
+ ci_status_path = "priv/ci/#{Repository.full_slug(repo)}/ci/status/#{repo.slug}.ci.commit_#{log1.hash}.status"
+ if File.exists?(ci_status_path) do
+ {:ok, ci_status} = File.read(ci_status_path)
+ %{log1 | ci_status: ci_status}
+ else
+ log1
+ end
{:ok, result} ->
#IO.inspect({:log1, result})
nil
@@ -416,7 +423,15 @@ defmodule KmxgitWeb.RepositoryController do
defp git_log(repo, tree, path) do
slug = Repository.full_slug(repo)
case Git.log(slug, tree, path || "") do
- {:ok, log} -> log
+ {:ok, log} -> Enum.map log, fn log1 ->
+ ci_status_path = "priv/ci/#{Repository.full_slug(repo)}/ci/status/#{repo.slug}.ci.commit_#{log1.hash}.status"
+ if File.exists?(ci_status_path) do
+ {:ok, ci_status} = File.read(ci_status_path)
+ %{log1 | ci_status: ci_status}
+ else
+ log1
+ end
+ end
{:error, reason} ->
Logger.error(inspect(reason))
nil
@@ -489,19 +504,25 @@ defmodule KmxgitWeb.RepositoryController do
if ci.content == nil && ci.files == nil do
not_found(conn)
else
- if ci.content_lang == "html" do
+ if Path.extname(path) == ".log" || ci.content_type && String.match?(ci.content_type, ~r(^image/)) do
conn
- |> put_resp_content_type("text/html")
+ |> put_resp_content_type(ci.content_type)
|> resp(200, ci.content)
else
- conn
- |> assign(:ci, ci)
- |> assign_current_organisation(org)
- |> assign(:current_repository, repo)
- |> assign(:owner, org || user)
- |> assign(:path, path)
- |> assign(:repo, repo)
- |> render("ci.html")
+ if ci.content_lang == "html" do
+ conn
+ |> put_resp_content_type("text/html")
+ |> resp(200, ci.content)
+ else
+ conn
+ |> assign(:ci, ci)
+ |> assign_current_organisation(org)
+ |> assign(:current_repository, repo)
+ |> assign(:owner, org || user)
+ |> assign(:path, path)
+ |> assign(:repo, repo)
+ |> render("ci.html")
+ end
end
end
end
diff --git a/lib/kmxgit_web/templates/repository/log.html.heex b/lib/kmxgit_web/templates/repository/log.html.heex
index 7332b27..175ac11 100644
--- a/lib/kmxgit_web/templates/repository/log.html.heex
+++ b/lib/kmxgit_web/templates/repository/log.html.heex
@@ -23,6 +23,7 @@
<tr>
<th class="author"><%= gettext "Author" %></th>
<th class="commit"><%= gettext "Commit" %></th>
+ <th class="ci"><%= gettext "CI" %></th>
<th class="date"><%= gettext "Date" %></th>
<th class="message"><%= gettext "Message" %></th>
</tr>
@@ -36,6 +37,14 @@
<td class="hash">
<%= link String.slice(commit.hash, 0..7), id: commit.hash, to: Routes.repository_path(@conn, :show, Repository.owner_slug(@repo), Repository.splat(@repo, ["_commit", commit.hash])) %>
</td>
+ <td class="ci">
+ <%= if File.exists?("priv/ci/#{Repository.full_slug(@repo)}/ci/log/#{@repo.slug}.ci.commit_#{commit.hash}.log.html") do %>
+ <% ci_status_path = Routes.repository_path(@conn, :show, Repository.owner_slug(@repo), Repository.splat(@repo, ["_ci", "ci", "log", "#{@repo.slug}.ci.commit_#{commit.hash}.log.html"])) %>
+ <%= link to: ci_status_path do %>
+ <img src={"/_images/status_#{commit.ci_status}.32.png"} alt={commit.ci_status} class="status-#{@git.log1.ci_status}" />
+ <% end %>
+ <% end %>
+ </td>
<td class="date">
<%= NaiveDateTime.add(~N[1970-01-01 00:00:00], commit.date) %>
</td>
diff --git a/lib/kmxgit_web/templates/repository/show_commit_message.html.heex b/lib/kmxgit_web/templates/repository/show_commit_message.html.heex
index 121cde9..7af1220 100644
--- a/lib/kmxgit_web/templates/repository/show_commit_message.html.heex
+++ b/lib/kmxgit_web/templates/repository/show_commit_message.html.heex
@@ -15,6 +15,14 @@
<br/>
<span class="property"><%= gettext "Date" %> :</span>
<%= NaiveDateTime.add(~N[1970-01-01 00:00:00], @git.log1.date) %>
+ <br/>
+ <%= if File.exists?("priv/ci/#{Repository.full_slug(@repo)}/ci/log/#{@repo.slug}.ci.commit_#{@git.log1.hash}.log.html") do %>
+ <span class="property"><%= gettext "CI" %> :</span>
+ <% ci_status_html = Routes.repository_path(@conn, :show, Repository.owner_slug(@repo), Repository.splat(@repo, ["_ci", "ci", "log", "#{@repo.slug}.ci.commit_#{@git.log1.hash}.log.html"])) %>
+ <%= link to: ci_status_html do %>
+ <img src={"/_images/status_#{@git.log1.ci_status}.32.png"} alt="" class="status-#{@git.log1.ci_status}" />
+ <% end %>
+ <% end %>
</p>
<pre><%= @git.log1.message %></pre>
</li>