-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow build and pipeline status to be updated automatically
Use channels to send updated status of each build, when in the build view, or of each pipeline when in the pipeline view. Closes #40
- Loading branch information
1 parent
f815f13
commit 0f2fd7f
Showing
18 changed files
with
267 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Controller } from "stimulus" | ||
import socket from "../socket" | ||
|
||
export default class extends Controller { | ||
|
||
connect() { | ||
let Ansi = require("ansi-to-html") | ||
const ansi = new Ansi() | ||
|
||
const buildName = this.data.get("name") | ||
const trace = this.data.get("trace") | ||
const id = this.data.get("id") | ||
|
||
if (trace == "") { | ||
var contents = "Build is pending" | ||
} else { | ||
var contents = ansi.toHtml(trace) | ||
} | ||
|
||
$("#output").html(`<h3>${buildName}</h3>${contents.replace(/\n/g, "<br />")}`) | ||
|
||
let channel = socket.channel(`build:${id}`, {}) | ||
channel.join() | ||
.receive("ok", data => { console.log(`Joined successfully for build ${id}`, data) }) | ||
.receive("error", data => { console.log("Unable to join", data) }) | ||
|
||
channel.on("append_trace", data => { | ||
$("#output").append(ansi.toHtml(data.trace).replace(/\n/g, "<br/>")) | ||
$(window).scrollTop($(document).height()) | ||
}) | ||
|
||
channel.on("replace_trace", data => { | ||
setTimeout(function(){ | ||
window.location.reload(true) | ||
}, 1500) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Controller } from "stimulus" | ||
import socket from "../socket" | ||
|
||
export default class extends Controller { | ||
connect() { | ||
const id = this.data.get("id") | ||
let channel = socket.channel(`pipeline:${id}`, {}) | ||
channel.join() | ||
.receive("ok", data => { console.log(`Joined successfully for pipeline ${id}`, data) }) | ||
.receive("error", data => { console.log("Unable to join", data) }) | ||
|
||
channel.on("update_status", data => { | ||
$(`#pipeline-${id}`).html(data.content) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
defmodule AlloyCi.Web.PipelinesChannel do | ||
@moduledoc false | ||
alias AlloyCi.{Pipelines, Projects, Web.Endpoint, Web.ProjectView} | ||
use AlloyCi.Web, :channel | ||
|
||
# Channels can be used in a request/response fashion | ||
# by sending replies to requests from the client | ||
def handle_in("ping", payload, socket) do | ||
{:reply, {:ok, payload}, socket} | ||
end | ||
|
||
# It is also common to receive messages from the client and | ||
# broadcast to everyone in the current topic (pipelines:lobby). | ||
def handle_in("shout", payload, socket) do | ||
broadcast(socket, "shout", payload) | ||
{:noreply, socket} | ||
end | ||
|
||
def join("pipeline:" <> pipeline_id, _payload, socket) do | ||
pipeline = Pipelines.get(pipeline_id) | ||
|
||
if Projects.can_access?(pipeline.project_id, %{id: socket.assigns.user_id}) do | ||
{:ok, socket} | ||
else | ||
{:error, %{reason: "Unauthorized"}} | ||
end | ||
end | ||
|
||
def update_status(pipeline) do | ||
Endpoint.broadcast("pipeline:#{pipeline.id}", "update_status", %{ | ||
content: render_pipeline(pipeline) | ||
}) | ||
end | ||
|
||
defp render_pipeline(pipeline) do | ||
Phoenix.View.render_to_string( | ||
ProjectView, | ||
"pipeline.html", | ||
pipeline: pipeline, | ||
project: pipeline.project, | ||
conn: %Plug.Conn{} | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div id="build-<%= @build.id %>"> | ||
<span class="user-timeline <%= timeline_status(@build.status) %>"> | ||
<li class="latest"> | ||
<div class="user-timeline-date"> | ||
<%= icon("clock-o") %> | ||
<%= build_duration(@build) %> | ||
</div> | ||
<div class="user-timeline-title"> | ||
<%= icon("terminal") %> | ||
<%= link @build.name, to: project_build_path(@conn, :show, @build.project_id, @build.id) %> | ||
</div> | ||
<div class="user-timeline-description"> | ||
<span data-toggle="tooltip" | ||
data-placement="bottom" | ||
title="Status: <%= String.capitalize(@build.status) %>"> | ||
<%= build_status_icon(@build.status) %> | ||
</span> | ||
<%= build_actions(@conn, @build, "fa-lg") %> | ||
</div> | ||
</li> | ||
</span> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.