added stage details to dashboard
parent
9d455b9e23
commit
f581e81ec4
@ -0,0 +1,77 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Dashboard</title>
|
||||
<link rel="stylesheet" type="text/css" href="/static/reset.css">
|
||||
<link rel="stylesheet" type="text/css" href="/static/style.css">
|
||||
<link rel="icon" type="image/png" id="favicon" href="/static/favicon.png">
|
||||
<script src="/static/timeago.js" type="text/javascript"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="navbar">
|
||||
<div class="logo">
|
||||
<svg viewBox="0 0 60 60" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><path d="M12.086 5.814l-.257.258 10.514 10.514C20.856 18.906 20 21.757 20 25c0 9.014 6.618 15 15 15 3.132 0 6.018-.836 8.404-2.353l10.568 10.568C48.497 55.447 39.796 60 30 60 13.434 60 0 46.978 0 30 0 19.903 4.751 11.206 12.086 5.814zm5.002-2.97C20.998 1.015 25.378 0 30 0c16.566 0 30 13.022 30 30 0 4.67-1.016 9.04-2.835 12.923l-9.508-9.509C49.144 31.094 50 28.243 50 25c0-9.014-6.618-15-15-15-3.132 0-6.018.836-8.404 2.353l-9.508-9.508zM35 34c-5.03 0-9-3.591-9-9s3.97-9 9-9c5.03 0 9 3.591 9 9s-3.97 9-9 9z" id="a"></path></defs><use fill="#FFF" xlink:href="#a" fill-rule="evenodd"></use></svg>
|
||||
</div>
|
||||
<nav class="inline-nav">
|
||||
<ul>
|
||||
<li><a href="/">Dashboard</a></li>
|
||||
<li><a href="/logs">Logging</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section>
|
||||
<header>
|
||||
<h1>{{ .Repo.Slug }}</h1>
|
||||
</header>
|
||||
|
||||
<div class="card stage">
|
||||
<h2>{{ .Build.Message }}</h2>
|
||||
<img src="{{ .Build.AuthorAvatar }}" />
|
||||
<span class="connector"></span>
|
||||
<span class="status {{ .Stage.Status }}"></span>
|
||||
{{ if eq .Build.Event "pull_request" }}
|
||||
{{ if eq .Build.Action "synchronized" }}
|
||||
<span class="desc">{{ .Build.Author }} synchronized pull request <em>#{{ pr .Build.Ref }}</em></span>
|
||||
{{ else }}
|
||||
<span class="desc">{{ .Build.Author }} opened pull request <em>#{{ pr .Build.Ref }}</em> to <em>{{ .Build.Target }}</em></span>
|
||||
{{ end }}
|
||||
{{ else if eq .Build.Event "tag" }}
|
||||
<span class="desc">{{ .Build.Author }} created reference <em>{{ tag .Build.Ref }}</em></span>
|
||||
{{ else if eq .Build.Event "promote"}}
|
||||
<span class="desc">{{ .Build.Author }} promoted build <em>#{{ .Build.Parent }}</em> to <em>{{ .Build.Deploy }}</em></span>
|
||||
{{ else }}
|
||||
<span class="desc">{{ .Build.Author }} pushed <em>{{ sha .Build.After }}</em> to <em>{{ .Build.Target }}</em></span>
|
||||
{{ end }}
|
||||
<span class="time" datetime="{{ if .Stage.Started }}{{ timestamp .Stage.Started }}{{ else }}{{ timestamp .Stage.Created }}{{ end }}"></span>
|
||||
</div>
|
||||
|
||||
{{ if .Stage.Steps }}
|
||||
<div class="card steps">
|
||||
<header>
|
||||
<span class="status {{ .Stage.Status }}"></span>
|
||||
<span class="name">{{ .Stage.Name }}</span>
|
||||
</header>
|
||||
<div class="body">
|
||||
{{ range .Stage.Steps }}
|
||||
<div class="step">
|
||||
<span class="status {{ .Status }}"></span>
|
||||
<span class="name"> {{ .Name }}</span>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer></footer>
|
||||
|
||||
<script>
|
||||
timeago.render(document.querySelectorAll('.time'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,106 @@
|
||||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Parity Public License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
addr := ":3333"
|
||||
|
||||
// serve templates with dummy data
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
path := r.FormValue("data")
|
||||
if path == "" {
|
||||
http.Error(w, "missing data parameter", 500)
|
||||
return
|
||||
}
|
||||
|
||||
tmpl := r.FormValue("template")
|
||||
if path == "" {
|
||||
http.Error(w, "missing template parameter", 500)
|
||||
return
|
||||
}
|
||||
|
||||
// read the json data from file.
|
||||
rawjson, err := ioutil.ReadFile(filepath.Join("testdata", path))
|
||||
if err != nil {
|
||||
http.Error(w, "cannot open json file", 500)
|
||||
return
|
||||
}
|
||||
|
||||
// unmarshal the json data
|
||||
data := map[string]interface{}{}
|
||||
err = json.Unmarshal(rawjson, &data)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
// load the templates
|
||||
T := template.New("_").Funcs(funcMap)
|
||||
matches, _ := filepath.Glob("files/*.tmpl")
|
||||
for _, match := range matches {
|
||||
raw, _ := ioutil.ReadFile(match)
|
||||
base := filepath.Base(match)
|
||||
T = template.Must(
|
||||
T.New(base).Parse(string(raw)),
|
||||
)
|
||||
}
|
||||
|
||||
// render the template
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
err = T.ExecuteTemplate(w, tmpl, data)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
})
|
||||
|
||||
// serve static content.
|
||||
http.Handle("/static/",
|
||||
http.StripPrefix("/static/",
|
||||
http.FileServer(
|
||||
http.Dir("../static/files"),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
log.Printf("listening at %s", addr)
|
||||
log.Fatalln(http.ListenAndServe(addr, nil))
|
||||
}
|
||||
|
||||
// regular expression to extract the pull request number
|
||||
// from the git ref (e.g. refs/pulls/{d}/head)
|
||||
var re = regexp.MustCompile("\\d+")
|
||||
|
||||
// mirros the func map in template.go
|
||||
var funcMap = map[string]interface{}{
|
||||
"timestamp": func(v float64) string {
|
||||
return time.Unix(int64(v), 0).UTC().Format("2006-01-02T15:04:05Z")
|
||||
},
|
||||
"pr": func(s string) string {
|
||||
return re.FindString(s)
|
||||
},
|
||||
"sha": func(s string) string {
|
||||
if len(s) > 8 {
|
||||
s = s[:8]
|
||||
}
|
||||
return s
|
||||
},
|
||||
"tag": func(s string) string {
|
||||
return strings.TrimPrefix(s, "refs/tags/")
|
||||
},
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
{
|
||||
"Entries": [
|
||||
{
|
||||
"Level": "trace",
|
||||
"Message": "this is a test trace message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058875
|
||||
},
|
||||
{
|
||||
"Level": "debug",
|
||||
"Message": "this is a test debug message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058875
|
||||
},
|
||||
{
|
||||
"Level": "info",
|
||||
"Message": "this is an info trace message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058975
|
||||
},
|
||||
{
|
||||
"Level": "warn",
|
||||
"Message": "this is a test warning message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058977
|
||||
},
|
||||
{
|
||||
"Level": "error",
|
||||
"Message": "this is a test error message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563059000
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"Entries": []
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
{
|
||||
"Logs": [
|
||||
{
|
||||
"Level": "trace",
|
||||
"Message": "this is a test trace message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058875
|
||||
},
|
||||
{
|
||||
"Level": "debug",
|
||||
"Message": "this is a test debug message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058875
|
||||
},
|
||||
{
|
||||
"Level": "info",
|
||||
"Message": "this is an info trace message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058975
|
||||
},
|
||||
{
|
||||
"Level": "warn",
|
||||
"Message": "this is a test warning message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058977
|
||||
},
|
||||
{
|
||||
"Level": "error",
|
||||
"Message": "this is a test error message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563059000
|
||||
}
|
||||
],
|
||||
"Repo": {
|
||||
"Slug": "octocat/hello-world"
|
||||
},
|
||||
"Build": {
|
||||
"After": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
|
||||
"Event": "push",
|
||||
"Source": "master",
|
||||
"Target": "master",
|
||||
"Message": "Merge pull request #6 from Spaceghost/patch-1",
|
||||
"Author": "octocat",
|
||||
"AuthorAvatar": "https://avatars0.githubusercontent.com/u/583231?s=460&v=4",
|
||||
"Number": 42
|
||||
},
|
||||
"Stage": {
|
||||
"Name": "test",
|
||||
"Status": "success",
|
||||
"Started": 1563059000,
|
||||
"Created": 1563059000,
|
||||
"Steps": [
|
||||
{ "Name": "clone", "Status": "success" },
|
||||
{ "Name": "build", "Status": "success" },
|
||||
{ "Name": "test", "Status": "success" },
|
||||
{ "Name": "deploy", "Status": "success" }
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
{
|
||||
"Logs": [
|
||||
{
|
||||
"Level": "trace",
|
||||
"Message": "this is a test trace message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058875
|
||||
},
|
||||
{
|
||||
"Level": "debug",
|
||||
"Message": "this is a test debug message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058875
|
||||
},
|
||||
{
|
||||
"Level": "info",
|
||||
"Message": "this is an info trace message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058975
|
||||
},
|
||||
{
|
||||
"Level": "warn",
|
||||
"Message": "this is a test warning message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058977
|
||||
},
|
||||
{
|
||||
"Level": "error",
|
||||
"Message": "this is a test error message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563059000
|
||||
}
|
||||
],
|
||||
"Repo": {
|
||||
"Slug": "octocat/hello-world"
|
||||
},
|
||||
"Build": {
|
||||
"After": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
|
||||
"Event": "promote",
|
||||
"Source": "master",
|
||||
"Target": "master",
|
||||
"Deploy": "production",
|
||||
"Message": "Merge pull request #6 from Spaceghost/patch-1",
|
||||
"Author": "octocat",
|
||||
"AuthorAvatar": "https://avatars0.githubusercontent.com/u/583231?s=460&v=4",
|
||||
"Parent": 41,
|
||||
"Number": 42
|
||||
},
|
||||
"Stage": {
|
||||
"Name": "test",
|
||||
"Status": "success",
|
||||
"Started": 1563059000,
|
||||
"Created": 1563059000,
|
||||
"Steps": [
|
||||
{ "Name": "clone", "Status": "success" },
|
||||
{ "Name": "build", "Status": "success" },
|
||||
{ "Name": "test", "Status": "success" },
|
||||
{ "Name": "deploy", "Status": "success" }
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
{
|
||||
"Repo": {
|
||||
"Slug": "octocat/hello-world"
|
||||
},
|
||||
"Build": {
|
||||
"Ref": "refs/pull/42/head",
|
||||
"After": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
|
||||
"Event": "pull_request",
|
||||
"Action": "opened",
|
||||
"Source": "master",
|
||||
"Target": "master",
|
||||
"Message": "Merge pull request #6 from Spaceghost/patch-1",
|
||||
"Author": "octocat",
|
||||
"AuthorAvatar": "https://avatars0.githubusercontent.com/u/583231?s=460&v=4",
|
||||
"Number": 42
|
||||
},
|
||||
"Stage": {
|
||||
"Name": "test",
|
||||
"Status": "success",
|
||||
"Started": 1563059000,
|
||||
"Created": 1563059000,
|
||||
"Steps": [
|
||||
{ "Name": "clone", "Status": "success" },
|
||||
{ "Name": "build", "Status": "success" },
|
||||
{ "Name": "test", "Status": "success" },
|
||||
{ "Name": "deploy", "Status": "success" }
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
{
|
||||
"Logs": [
|
||||
{
|
||||
"Level": "trace",
|
||||
"Message": "this is a test trace message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058875
|
||||
},
|
||||
{
|
||||
"Level": "debug",
|
||||
"Message": "this is a test debug message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058875
|
||||
},
|
||||
{
|
||||
"Level": "info",
|
||||
"Message": "this is an info trace message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058975
|
||||
},
|
||||
{
|
||||
"Level": "warn",
|
||||
"Message": "this is a test warning message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563058977
|
||||
},
|
||||
{
|
||||
"Level": "error",
|
||||
"Message": "this is a test error message",
|
||||
"Data": { "foo": "bar", "baz": "boo" },
|
||||
"Unix": 1563059000
|
||||
}
|
||||
],
|
||||
"Repo": {
|
||||
"Slug": "octocat/hello-world"
|
||||
},
|
||||
"Build": {
|
||||
"After": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
|
||||
"Event": "tag",
|
||||
"Source": "master",
|
||||
"Target": "master",
|
||||
"Ref": "refs/tags/v1.0.0",
|
||||
"Message": "Merge pull request #6 from Spaceghost/patch-1",
|
||||
"Author": "octocat",
|
||||
"AuthorAvatar": "https://avatars0.githubusercontent.com/u/583231?s=460&v=4",
|
||||
"Number": 42
|
||||
},
|
||||
"Stage": {
|
||||
"Name": "test",
|
||||
"Status": "success",
|
||||
"Started": 1563059000,
|
||||
"Created": 1563059000,
|
||||
"Steps": [
|
||||
{ "Name": "clone", "Status": "success" },
|
||||
{ "Name": "build", "Status": "success" },
|
||||
{ "Name": "test", "Status": "success" },
|
||||
{ "Name": "deploy", "Status": "success" }
|
||||
]
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"Items": [
|
||||
{
|
||||
"ID": 1,
|
||||
"Idle": false,
|
||||
"Repo": {
|
||||
"Slug": "octocat/hello-world"
|
||||
},
|
||||
"Build": {
|
||||
"AuthorAvatar": "https://avatars0.githubusercontent.com/u/583231?s=460&v=4",
|
||||
"Number": 42
|
||||
},
|
||||
"Stage": {
|
||||
"Name": "test",
|
||||
"Status": "running",
|
||||
"Started": 1563059000,
|
||||
"Created": 1563059000
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"Idle": true,
|
||||
"Items": []
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
{
|
||||
"Idle": true,
|
||||
"Items": [
|
||||
{
|
||||
"Repo": {
|
||||
"Slug": "octocat/hello-world"
|
||||
},
|
||||
"Build": {
|
||||
"AuthorAvatar": "https://avatars0.githubusercontent.com/u/583231?s=460&v=4",
|
||||
"Number": 42
|
||||
},
|
||||
"Stage": {
|
||||
"Name": "test",
|
||||
"Status": "success",
|
||||
"Started": 1563059000,
|
||||
"Created": 1563059000
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue