Skip to content

Commit 7da1374

Browse files
committed
view build
1 parent 528676a commit 7da1374

File tree

7 files changed

+161
-2
lines changed

7 files changed

+161
-2
lines changed

assets/templates_src/internal/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h1>Home<small>...</small></h1>
3434
</div>
3535
<footer class="main-footer">
3636
<div class="pull-right hidden-xs">
37-
<b>Version</b> 0.0.0
37+
<b>Version</b> 0.0.1
3838
</div>
3939
<strong>Postgres</strong>-CI
4040
</footer>

assets/templates_src/internal/layout/menu.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ul class="sidebar-menu">
44
<li class="header">MAIN NAVIGATION</li>
55
<li><a href="/"><i class="fa fa-dashboard"></i> <span>Dashboard</span></a></li>
6-
<li><a href="#"><i class="fa fa-book"></i> <span>Projects</span></a></li>
6+
<!--li><a href="#"><i class="fa fa-book"></i> <span>Projects</span></a></li-->
77
<li><a href="#"><i class="fa fa-users"></i> <span>Users</span></a></li>
88
</ul>
99
</section>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{% extends "../internal/layout.html" %} {% block content_header%}
2+
<h1>Builds</h1> {% endblock %}
3+
<ol class="breadcrumb">
4+
{% block breadcrumb%}
5+
<li><a href="/"><i class="fa fa-dashboard"></i> Dashboard</a></li>
6+
{% verbatim %}<li><a href="/project/{{ build.ProjectID}}/builds/">{{ build.ProjectName}} builds</a></li>{% endverbatim %}
7+
<li class="active">build</li>
8+
{% endblock %} {% block content%} {% verbatim %}
9+
<div class="box">
10+
<div class="box-body">
11+
<strong>Commit message:</strong>
12+
<pre>{{ build.CommitMessage }}</pre>
13+
14+
<strong>Config:</strong>
15+
<pre>{{ build.Config }}</pre>
16+
17+
{% for part in build.Parts %}
18+
<h3>{{ part.DockerImage}}. Server version: {{ part.ServerVersion }}</h3>
19+
<strong>Duratin:</strong> {{ part.FinishedAt | duration:part.StartedAt }}
20+
<br>
21+
22+
<strong>Output:</strong>
23+
<pre>{{ part.Output }}</pre>
24+
<table class="table table-striped">
25+
<thead>
26+
<tr>
27+
<th>Function</th>
28+
<th width="350px">Duration</th>
29+
</tr>
30+
</thead>
31+
<tbody>
32+
{% for test in part.Tests %}
33+
<tr>
34+
<td>
35+
36+
{% if test.Errors %}
37+
<span class="label label-danger">{{ test.Namespace }}.{{ test.Procedure }}</span><br>
38+
{% for error in test.Errors %}
39+
{{ error.Message }} {{ error.Comment }} <br>
40+
{% endfor %}
41+
42+
{% else %}
43+
{{ test.Namespace }}.{{ test.Procedure }}
44+
{% endif %}
45+
</td>
46+
<td>{{ test.FinishedAt | duration:test.StartedAt }}</td>
47+
</tr>
48+
{% endfor %}
49+
</tbody>
50+
</table>
51+
{% endfor %}
52+
</div>
53+
</div>
54+
{% endverbatim %} {% endblock %}

src/app/controllers/project/builds.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,16 @@ func buildsHandler(c *http200ok.Context) {
2121
"items": list.Items,
2222
})
2323
}
24+
25+
func buildHandler(c *http200ok.Context) {
26+
27+
build, err := build.View(params.ToInt32(c, "BuildID"))
28+
29+
if err != nil {
30+
return
31+
}
32+
33+
render.HTML(c, "project/build.html", render.Context{
34+
"build": build,
35+
})
36+
}

src/app/controllers/project/route.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import (
77
func Route(server *http200ok.Server) {
88

99
server.Get("/project/:ProjectID/builds/", buildsHandler)
10+
server.Get("/project/:ProjectID/build/:BuildID/", buildHandler)
1011
}

src/app/models/build/view.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package build
2+
3+
import (
4+
log "github.com/Sirupsen/logrus"
5+
"github.com/postgres-ci/app-server/src/env"
6+
7+
"encoding/json"
8+
"fmt"
9+
"time"
10+
)
11+
12+
type build struct {
13+
ProjectID int32 `db:"project_id"`
14+
ProjectName string `db:"project_name"`
15+
BranchID int32 `db:"branch_id"`
16+
Branch string `db:"branch_name"`
17+
Config string `db:"config"`
18+
Status string `db:"status"`
19+
Error string `db:"error"`
20+
CommitSHA string `db:"commit_sha"`
21+
CommitMessage string `db:"commit_message"`
22+
CommittedAt time.Time `db:"committed_at"`
23+
CommitterName string `db:"committer_name"`
24+
CommitterEmail string `db:"committer_email"`
25+
AuthorName string `db:"author_name"`
26+
AuthorEmail string `db:"author_email"`
27+
Parts Parts `db:"parts"`
28+
}
29+
30+
type Part struct {
31+
PartID int32 `json:"part_id"`
32+
DockerImage string `json:"docker_image"`
33+
ServerVersion string `json:"server_version"`
34+
Output string `json:"output"`
35+
Success bool `json:"success"`
36+
StartedAt time.Time `json:"started_at"`
37+
FinishedAt time.Time `json:"finished_at"`
38+
Tests []Test `json:"tests"`
39+
}
40+
41+
type Parts []Part
42+
43+
func (p *Parts) Scan(src interface{}) error {
44+
45+
var source []byte
46+
47+
switch src.(type) {
48+
case string:
49+
source = []byte(src.(string))
50+
case []byte:
51+
source = src.([]byte)
52+
default:
53+
return fmt.Errorf("Incompatible type for Parts")
54+
}
55+
56+
return json.Unmarshal(source, p)
57+
}
58+
59+
type Test struct {
60+
Namespace string `json:"namespace"`
61+
Procedure string `json:"procedure"`
62+
Errors []Error `json:"errors"`
63+
StartedAt time.Time `json:"started_at"`
64+
FinishedAt time.Time `json:"finished_at"`
65+
}
66+
67+
type Error struct {
68+
Message string `json:"message"`
69+
Comment string `json:"comment"`
70+
}
71+
72+
func View(buildID int32) (*build, error) {
73+
74+
var build build
75+
76+
err := env.Connect().Get(&build, `SELECT * FROM build.view($1)`, buildID)
77+
78+
if err != nil {
79+
80+
log.Errorf("Error when fetching build: %v", err)
81+
82+
return nil, err
83+
}
84+
85+
return &build, nil
86+
}

src/tools/render/filters/time_duration.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import (
77

88
func duration(diff time.Duration) string {
99

10+
if diff < time.Second {
11+
12+
return diff.String()
13+
}
14+
1015
var (
1116
value string
1217
milliseconds = diff.Nanoseconds() / 1000000

0 commit comments

Comments
 (0)