Skip to content

Commit 7f80c6f

Browse files
committed
Use postgres-CI for running tests
1 parent feef37d commit 7f80c6f

File tree

26 files changed

+352
-68
lines changed

26 files changed

+352
-68
lines changed

.postgres-ci.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
images:
2+
- postgresci/golang:1.6
3+
entrypoint:
4+
- /sbin/init
5+
commands:
6+
- go version
7+
- go get -u github.com/FiloSottile/gvt
8+
- gvt restore
9+
- mkdir -p /go/src/github.com/postgres-ci/app-server
10+
- cp -r . /go/src/github.com/postgres-ci/app-server/
11+
- echo ==== Tests ====
12+
tests:
13+
- go test -cover -v github.com/postgres-ci/app-server/src/app/models/webhooks/common
14+
- go test -cover -v github.com/postgres-ci/app-server/src/app/models/webhooks/github
15+
- go test -cover -v github.com/postgres-ci/app-server/src/tools/limit
16+
- go test -cover -v github.com/postgres-ci/app-server/src/tools/render/pagination

assets/static/js/validator.min.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/templates_src/internal/layout.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<!DOCTYPE html>
22
<html>
3-
43
<head>
54
<meta charset="utf-8">
65
<title>Postgres-CI</title>
@@ -34,15 +33,15 @@ <h1>Home<small>...</small></h1>
3433
</div>
3534
<footer class="main-footer">
3635
<div class="pull-right hidden-xs">
37-
<b>Version</b> 0.0.1
36+
<b>Version</b> 0.1
3837
</div>
3938
<strong>Postgres</strong>-CI
4039
</footer>
4140
</div>
4241
<script src="/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
4342
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
4443
<script src="/static/dist/js/app.min.js"></script>
44+
<script src="/static/js/validator.min.js"></script>
4545
<script src="/static/js/app.js"></script>
4646
</body>
47-
4847
</html>

assets/templates_src/internal/layout/header.html

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,34 @@
2323
</header>
2424
<div class="modal fade" id="changePassword" tabindex="-1" role="dialog">
2525
<div class="modal-dialog" role="document">
26-
<div class="modal-content">
27-
<div class="modal-header">
28-
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
29-
<h4 class="modal-title">Change password</h4>
30-
</div>
31-
<div class="modal-body">
32-
<div class="form-group">
33-
<label for="message-text" class="control-label">current password:</label>
34-
<input type="password" name="current_password" class="form-control">
26+
<form method="post" action="">
27+
<div class="modal-content">
28+
<div class="modal-header">
29+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
30+
<h4 class="modal-title">Change password</h4>
3531
</div>
36-
<div class="form-group">
37-
<label for="message-text" class="control-label">new password:</label>
38-
<input type="password" name="new_password" class="form-control">
32+
<div class="modal-body">
33+
<div class="form-group">
34+
<label for="message-text" class="control-label">current password:</label>
35+
<input type="password" name="current_password" class="form-control" required>
36+
<div class="help-block with-errors"></div>
37+
</div>
38+
<div class="form-group">
39+
<label for="message-text" class="control-label">new password:</label>
40+
<input type="password" name="new_password" id="new_password" class="form-control" required>
41+
<div class="help-block with-errors"></div>
42+
</div>
43+
<div class="form-group">
44+
<label for="message-text" class="control-label">confirm password:</label>
45+
<input type="password" name="confirm_password" data-match="#new_password" data-match-error="Whoops, these don't match" class="form-control" required>
46+
<div class="help-block with-errors"></div>
47+
</div>
3948
</div>
40-
<div class="form-group">
41-
<label for="message-text" class="control-label">confirm password:</label>
42-
<input type="password" name="confirm_password" class="form-control">
49+
<div class="modal-footer">
50+
<button type="button" class="btn btn-default" data-dismiss="modal">close</button>
51+
<button type="submit" class="btn btn-primary">change</button>
4352
</div>
4453
</div>
45-
<div class="modal-footer">
46-
<button type="button" class="btn btn-default" data-dismiss="modal">close</button>
47-
<button type="submit" class="btn btn-primary">change</button>
48-
</div>
49-
</div>
54+
</form>
5055
</div>
5156
</div>

assets/templates_src/project/view_build.html

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,33 @@ <h3 class="box-title">Commit {{ build.CommitSHA }}</h3>
2020
<pre>{{ build.CommitMessage }}</pre>
2121
</div>
2222
</div>
23+
24+
{% if build.Error %}
25+
<div class="box box-danger box-solid">
26+
<div class="box-header">
27+
<h3 class="box-title">Error</h3>
28+
</div>
29+
<div class="box-body">
30+
<pre>{{ build.Error }}</pre>
31+
</div>
32+
</div>
33+
{% endif %}
34+
2335
<div class="box">
2436
<div class="box-header">
2537
<h3 class="box-title">Config</h3>
26-
2738
</div>
2839
<div class="box-body">
2940
<pre>{{ build.Config }}</pre>
3041
</div>
3142
</div>
43+
3244
{% for part in build.Parts %}
3345
<div class="box collapsed-box{% if !part.Success %} box-danger box-solid{% endif %}">
3446
<div class="box-header">
3547
<h3 class="box-title">
3648
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-plus"></i></button>
37-
Image: {{ part.Image}}. Server version: {{ part.Version }}
49+
Image: {{ part.Image}}. {% if part.Version %} Server version: {{ part.Version }} {% endif %}
3850
</h3>
3951
<div class="box-tools">
4052
<strong>Duration:</strong> {{ part.FinishedAt | duration:part.StartedAt }}
@@ -43,6 +55,8 @@ <h3 class="box-title">
4355
<div class="box-body" style="display: none;">
4456
<strong>Output:</strong>
4557
<pre>{{ part.Output }}</pre>
58+
59+
{% if part.Tests %}
4660
<table class="table table-striped">
4761
<thead>
4862
<tr>
@@ -69,7 +83,7 @@ <h3 class="box-title">
6983
{% endfor %}
7084
</tbody>
7185
</table>
72-
86+
{% endif %}
7387
</div>
7488
</div>
7589
{% endfor %}

src/app/controllers/password/reset.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package password
2+
3+
import (
4+
"github.com/postgres-ci/app-server/src/app/models/auth"
5+
"github.com/postgres-ci/app-server/src/app/models/password"
6+
"github.com/postgres-ci/app-server/src/common/errors"
7+
"github.com/postgres-ci/app-server/src/tools/params"
8+
"github.com/postgres-ci/app-server/src/tools/render"
9+
"github.com/postgres-ci/http200ok"
10+
11+
"net/http"
12+
)
13+
14+
func resetHandler(c *http200ok.Context) {
15+
16+
var (
17+
currentUser = c.Get("CurrentUser").(*auth.User)
18+
newPassword = c.Request.PostFormValue("new_password")
19+
confirmPassword = c.Request.PostFormValue("confirm_password")
20+
)
21+
22+
if !currentUser.IsSuperuser {
23+
24+
render.JSONError(c, http.StatusForbidden, "Access denied")
25+
26+
return
27+
}
28+
29+
if newPassword != confirmPassword {
30+
31+
render.JSONError(c, code, "Entered password not equal confirmed")
32+
33+
return
34+
}
35+
36+
if err := password.Reset(params.ToInt32(c, "UserID"), newPassword); err != nil {
37+
38+
code := http.StatusInternalServerError
39+
40+
if e, ok := err.(*errors.Error); ok {
41+
42+
code = e.Code
43+
}
44+
45+
render.JSONError(c, code, err.Error())
46+
47+
return
48+
}
49+
50+
render.JSONok(c)
51+
}

src/app/controllers/password/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.Post("/password/change/", changeHandler)
10+
server.Post("/password/reset/:UserID/", resetHandler)
1011
}

src/app/controllers/project/add.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
11
package project
22

3-
func addHandler() {
3+
import (
4+
"github.com/postgres-ci/app-server/src/app/models/auth"
5+
"github.com/postgres-ci/app-server/src/app/models/project"
6+
"github.com/postgres-ci/app-server/src/common/errors"
7+
"github.com/postgres-ci/app-server/src/tools/render"
8+
"github.com/postgres-ci/http200ok"
49

10+
"net/http"
11+
"strconv"
12+
"strings"
13+
)
14+
15+
func addHandler(c *http200ok.Context) {
16+
17+
currentUser := c.Get("CurrentUser").(*auth.User)
18+
19+
if !currentUser.IsSuperuser {
20+
21+
render.JSONError(c, http.StatusForbidden, "Access denied")
22+
23+
return
24+
}
25+
26+
var (
27+
name = strings.TrimSpace(c.Request.PostFormValue("name"))
28+
url = strings.TrimSpace(c.Request.PostFormValue("url"))
29+
githubSecret = strings.TrimSpace(c.Request.PostFormValue("github_secret"))
30+
ownerID int32
31+
)
32+
33+
if value, err := strconv.ParseInt(c.Request.PostFormValue("owner_id"), 10, 32); err == nil {
34+
35+
ownerID = int32(value)
36+
}
37+
38+
if err := project.Add(ownerID, name, url, githubSecret); err != nil {
39+
40+
code := http.StatusInternalServerError
41+
42+
if e, ok := err.(*errors.Error); ok {
43+
44+
code = e.Code
45+
}
46+
47+
render.JSONError(c, code, err.Error())
48+
49+
return
50+
}
51+
52+
render.JSONok(c)
553
}

src/app/controllers/project/builds.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ func buildsHandler(c *http200ok.Context) {
1717

1818
if err != nil {
1919

20+
render.InternalServerError(c, err)
21+
2022
return
2123
}
2224

src/app/controllers/project/delete.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package project
33
import (
44
"github.com/postgres-ci/app-server/src/app/models/auth"
55
"github.com/postgres-ci/app-server/src/app/models/project"
6+
"github.com/postgres-ci/app-server/src/common/errors"
67
"github.com/postgres-ci/app-server/src/tools/params"
78
"github.com/postgres-ci/app-server/src/tools/render"
89
"github.com/postgres-ci/http200ok"
@@ -23,7 +24,14 @@ func deleteHandler(c *http200ok.Context) {
2324

2425
if err := project.Delete(params.ToInt32(c, "ProjectID")); err != nil {
2526

26-
render.JSONError(c, http.StatusInternalServerError, err.Error())
27+
code := http.StatusInternalServerError
28+
29+
if e, ok := err.(*errors.Error); ok {
30+
31+
code = e.Code
32+
}
33+
34+
render.JSONError(c, code, err.Error())
2735

2836
return
2937
}

src/app/controllers/project/route.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ func Route(server *http200ok.Server) {
1010
server.Get("/project/:ProjectID/builds/", buildsHandler)
1111
server.Get("/project/:ProjectID/builds/branch/:BranchID/", buildsHandler)
1212
server.Get("/project/:ProjectID/build/:BuildID/", viewBuildHandler)
13+
server.Post("/project/add/", addHandler)
14+
server.Post("/project/update/:ProjectID/", updateHandler)
1315
server.Post("/project/delete/:ProjectID/", middleware.CheckPassword, deleteHandler)
1416
}

src/app/controllers/project/update.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,54 @@
11
package project
22

3-
func updateHandler() {
3+
import (
4+
"github.com/postgres-ci/app-server/src/app/models/auth"
5+
"github.com/postgres-ci/app-server/src/app/models/project"
6+
"github.com/postgres-ci/app-server/src/common/errors"
7+
"github.com/postgres-ci/app-server/src/tools/params"
8+
"github.com/postgres-ci/app-server/src/tools/render"
9+
"github.com/postgres-ci/http200ok"
410

11+
"net/http"
12+
"strconv"
13+
"strings"
14+
)
15+
16+
func updateHandler(c *http200ok.Context) {
17+
18+
currentUser := c.Get("CurrentUser").(*auth.User)
19+
20+
if !currentUser.IsSuperuser {
21+
22+
render.JSONError(c, http.StatusForbidden, "Access denied")
23+
24+
return
25+
}
26+
27+
var (
28+
name = strings.TrimSpace(c.Request.PostFormValue("name"))
29+
url = strings.TrimSpace(c.Request.PostFormValue("url"))
30+
githubSecret = strings.TrimSpace(c.Request.PostFormValue("github_secret"))
31+
ownerID int32
32+
)
33+
34+
if value, err := strconv.ParseInt(c.Request.PostFormValue("owner_id"), 10, 32); err == nil {
35+
36+
ownerID = int32(value)
37+
}
38+
39+
if err := project.Update(params.ToInt32(c, "ProjectID"), ownerID, name, url, githubSecret); err != nil {
40+
41+
code := http.StatusInternalServerError
42+
43+
if e, ok := err.(*errors.Error); ok {
44+
45+
code = e.Code
46+
}
47+
48+
render.JSONError(c, code, err.Error())
49+
50+
return
51+
}
52+
53+
render.JSONok(c)
554
}

src/app/controllers/project/view_build.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package project
22

33
import (
44
"github.com/postgres-ci/app-server/src/app/models/build"
5+
"github.com/postgres-ci/app-server/src/common/errors"
56
"github.com/postgres-ci/app-server/src/tools/params"
67
"github.com/postgres-ci/app-server/src/tools/render"
78
"github.com/postgres-ci/http200ok"
@@ -12,6 +13,16 @@ func viewBuildHandler(c *http200ok.Context) {
1213
build, err := build.View(params.ToInt32(c, "BuildID"))
1314

1415
if err != nil {
16+
17+
if errors.IsNotFound(err) {
18+
19+
render.NotFound(c)
20+
21+
} else {
22+
23+
render.InternalServerError(c, err)
24+
}
25+
1526
return
1627
}
1728

0 commit comments

Comments
 (0)