Skip to content

Commit

Permalink
more frontend work. time to switch gears
Browse files Browse the repository at this point in the history
  • Loading branch information
zeebo committed Dec 29, 2012
1 parent dcfc598 commit cf0a11d
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 29 deletions.
6 changes: 3 additions & 3 deletions app/frontend/frontend.go
Expand Up @@ -13,10 +13,10 @@ var Mux = pat.New()
//register all the handlers with the serve mux
func init() {
Mux.Add("GET", "/static/", http.StripPrefix("/static", http.FileServer(Config)))
Mux.Add("GET", "/work/{key:.+}", httputil.Handler(specifc_work))
Mux.Add("GET", "/work/{key:.+}", httputil.Handler(specificWork))
Mux.Add("GET", "/work", httputil.Handler(work))
Mux.Add("GET", "/result/{import:[^@]+}@{rev:.*}", httputil.Handler(specific_import_result))
Mux.Add("GET", "/result/{import:[^@]+}", httputil.Handler(import_result))
Mux.Add("GET", "/result/{import:[^@]+}@{rev:.*}", httputil.Handler(specificImportResult))
Mux.Add("GET", "/result/{import:[^@]+}", httputil.Handler(importResult))
Mux.Add("GET", "/result", httputil.Handler(result))
Mux.Add("GET", "/image/{import:.+}", httputil.Handler(image))
Mux.Add("GET", "/how", httputil.Handler(how))
Expand Down
45 changes: 29 additions & 16 deletions app/frontend/pages.go
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/zeebo/goci/app/entities"
"github.com/zeebo/goci/app/httputil"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"net/http"
"net/url"
"sort"
Expand Down Expand Up @@ -43,6 +44,7 @@ func index(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *h
err := ctx.DB.C("TestResult").Find(nil).Sort("-when").Limit(20).All(&res)
if err != nil {
e = httputil.Errorf(err, "couldn't query for test results")
return
}

w.Header().Set("Content-Type", "text/html")
Expand All @@ -54,23 +56,36 @@ func index(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *h

//work shows recent work items
func work(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *httputil.Error) {
var res []entities.WorkResult
err := ctx.DB.C("WorkResult").Find(nil).Sort("-when").Limit(20).All(&res)
if err != nil {
e = httputil.Errorf(err, "couldn't query for work results")
return
}

w.Header().Set("Content-Type", "text/html")
if err := T("index/index.html").Execute(w, nil); err != nil {
if err := T("work/work.html").Execute(w, res); err != nil {
e = httputil.Errorf(err, "error executing index template")
}
return
}

//specific_work shows a work item with the given key
func specifc_work(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *httputil.Error) {
//specificWork shows a work item with the given key
func specificWork(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *httputil.Error) {
w.Header().Set("Content-Type", "text/html")
if err := req.ParseForm(); err != nil {
e = httputil.Errorf(err, "error parsing form")
return
}

key := grab(req.Form, "key")
if err := T("index/index.html").Execute(w, key); err != nil {
id := bson.ObjectIdHex(grab(req.Form, "key"))
var work *entities.Work
if err := ctx.DB.C("Work").FindId(id).One(&work); err != nil {
e = httputil.Errorf(err, "error grabbing work item")
return
}

if err := T("work/specific_work.html").Execute(w, work); err != nil {
e = httputil.Errorf(err, "error executing index template")
}
return
Expand All @@ -80,37 +95,37 @@ func specifc_work(w http.ResponseWriter, req *http.Request, ctx httputil.Context
func result(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *httputil.Error) {
w.Header().Set("Content-Type", "text/html")

if err := T("index/index.html").Execute(w, nil); err != nil {
if err := T("result/result.html").Execute(w, nil); err != nil {
e = httputil.Errorf(err, "error executing index template")
}
return
}

//import_result shows recent result items for an import path
func import_result(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *httputil.Error) {
//importResult shows recent result items for an import path
func importResult(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *httputil.Error) {
w.Header().Set("Content-Type", "text/html")
if err := req.ParseForm(); err != nil {
e = httputil.Errorf(err, "error parsing form")
return
}

imp := grab(req.Form, "import")
if err := T("index/index.html").Execute(w, imp); err != nil {
if err := T("result/import_result.html").Execute(w, imp); err != nil {
e = httputil.Errorf(err, "error executing index template")
}
return
}

//specific_import_result shows a result item for an import path and given revision
func specific_import_result(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *httputil.Error) {
//specificImportResult shows a result item for an import path and given revision
func specificImportResult(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *httputil.Error) {
w.Header().Set("Content-Type", "text/html")
if err := req.ParseForm(); err != nil {
e = httputil.Errorf(err, "error parsing form")
return
}

imp, rev := grab(req.Form, "import"), grab(req.Form, "rev")
if err := T("index/index.html").Execute(w, struct{ Imp, Rev string }{imp, rev}); err != nil {
if err := T("result/specific_import_result.html").Execute(w, []string{imp, rev}); err != nil {
e = httputil.Errorf(err, "error executing index template")
}
return
Expand All @@ -125,9 +140,7 @@ func image(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *h
}

imp := grab(req.Form, "import")
if err := T("index/index.html").Execute(w, imp); err != nil {
e = httputil.Errorf(err, "error executing index template")
}
_ = imp
return
}

Expand Down Expand Up @@ -183,7 +196,7 @@ func pkg(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *htt
func how(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *httputil.Error) {
w.Header().Set("Content-Type", "text/html")

if err := T("index/index.html").Execute(w, nil); err != nil {
if err := T("how/how.html").Execute(w, nil); err != nil {
e = httputil.Errorf(err, "error executing index template")
}
return
Expand Down
4 changes: 2 additions & 2 deletions app/rpc/rpc.go
Expand Up @@ -63,7 +63,7 @@ type Work struct {
Subpackages bool

//VCSHint is an optional parameter that specifies the version control system
//used by the package. If set to the empty string, we will search for the
//used by the package. If set to the empty string, we will search for the
//system by looking for the metadata directory.
VCSHint string
}
Expand Down Expand Up @@ -105,7 +105,7 @@ type RunTest struct {

//RunnerResponse is the response from the Runner to the tracker
type RunnerResponse struct {
Key string //the datastore key for the Work item
Key string //the key for the Work item
ID string //the ID of the test
WorkRev int //the revision of the work item
Revision string //the revision we ended up testing
Expand Down
16 changes: 8 additions & 8 deletions app/test/test.go
Expand Up @@ -37,17 +37,17 @@ func ping(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *ht

func addwork(w http.ResponseWriter, req *http.Request, ctx httputil.Context) (e *httputil.Error) {
//create our little work item
q := rpc.Work{
Revision: "8488aea525fb04d90328917112b30e5ec01f4895",
ImportPath: "github.com/zeebo/goci",
Subpackages: true,
}

// q := rpc.Work{
// Revision: "e9dd26552f10d390b5f9f59c6a9cfdc30ed1431c",
// ImportPath: "github.com/zeebo/irc",
// Revision: "8488aea525fb04d90328917112b30e5ec01f4895",
// ImportPath: "github.com/zeebo/goci",
// Subpackages: true,
// }

q := rpc.Work{
Revision: "e9dd26552f10d390b5f9f59c6a9cfdc30ed1431c",
ImportPath: "github.com/zeebo/irc",
}

//add it to the queue
if err := workqueue.QueueWork(ctx, q); err != nil {
e = httputil.Errorf(err, "error adding work item to queue")
Expand Down
107 changes: 107 additions & 0 deletions templates/how/how.html
@@ -0,0 +1,107 @@
{{ define "content" }}
<section id="info">
<div class="row">
<div class="span12">
<h2>Info</h2>
<div class="well">
<p>
GoCI tests packages by interfacing with the source control hosting
website's post-commit hook mechanism. Just add the url corresponding
to the source control hosting site you are using to the post-commit
hook area, and push a commit. This area is usually found in the admin
or project settings portion of the website. Happy testing!
</p>
</div>
</div>
</div>
</section>

<section id="hooks">
<div class="row">
<div class="span12">
<h2>URLs</h2>
<table class="table">
<thead>
<th>Website</th>
<th>URL</th>
</thead>
<tr>
<td>Github</td>
<td>http://goci.me</td>
</tr>
<tr>
<td>BitBucket</td>
<td>http://goci.me</td>
</tr>
<tr>
<td>Google Code (git)</td>
<td>http://goci.me</td>
</tr>
<tr>
<td>Google Code (hg)</td>
<td>http://goci.me</td>
</tr>
<tr>
<td>Arbitrary "go get"</td>
<td>Send a POST request to http://goci.me</td>
</tr>
</table>
</div>
</div>
</section>

<section id="images">
<div class="row">
<div class="span12">
<h2>Images</h2>
<div class="well">
<p>
If you would like to include an image of the current build status of
your project on your website or source control page, you just have to
point an image at
</p>

<pre>http://goci.me</pre>

<p>
Please be kind enough to link back to somewhere on goci.me. Here's a
nice little template to help:
</p>

<pre>&lt;a href="http://goci.me"&gt;
&lt;img src="http://goci.me" /&gt;
&lt;/a&gt;</pre>

<h3>Caching</h3>
<p>
If you're putting it in a github readme or on some site that caches
the output of the images, you might try using https. Note that the
SSL cert for https://goci.me is for *.heroku.com, so if you need a valid cert
use the domain goci.herokuapp.com.
</p>
</div>
</div>
</div>
</section>

<section id="buildtags">
<div class="row">
<div class="span12">
<h2>Build Tags</h2>
<div class="well">
<p>All of the code compiled by GoCI is passed a build tag of "goci".
This allows you to optionally include/exclude portions of your binary
or portions of your tests to be run on GoCI. For example if you have
some tests that require a C library that is not installed, you can
disable it with a build directive of</p>

<pre>// +build !goci</pre>

<p>If you would like more information about build tags and what they
can do for you, visit the <a href="http://golang.org/pkg/go/build">
go/build</a> documentation.</p>
</div>
</div>
</div>
</section>
{{ end }}
2 changes: 2 additions & 0 deletions templates/result/import_result.html
@@ -0,0 +1,2 @@
{{ define "content" }}
{{ end }}
2 changes: 2 additions & 0 deletions templates/result/result.html
@@ -0,0 +1,2 @@
{{ define "content" }}
{{ end }}
2 changes: 2 additions & 0 deletions templates/result/specific_import_result.html
@@ -0,0 +1,2 @@
{{ define "content" }}
{{ end }}
16 changes: 16 additions & 0 deletions templates/work/specific_work.html
@@ -0,0 +1,16 @@
{{ define "content" }}
<section id="work_item">
<div class="row show-grid">
<div class="span12"><span><strong>Server Name </strong>foo</span></div>
</div>
<div class="row show-grid">
<div class="span3"><span><strong>Execution Time </strong>bar</span></div>
<div class="span9"><span><strong>URI </strong>bar</span></div>
</div>
<div class="row show-grid">
<div class="span3"><span><strong>Memory Usage </strong>bar</span></div>
<div class="span9"><span><strong>Referer </strong>bar</span></div>
</div>
</div>
</section>
{{ end }}
27 changes: 27 additions & 0 deletions templates/work/work.html
@@ -0,0 +1,27 @@
{{ define "content" }}
<section id="recent">
<div class="page-header">
<h1>Recent Work Items</h1>
</div>
<div class="row">
<div class="span12">
<table class="table">
<thead>
<th>Work ID</th>
<th>Date</th>
<th>Ran</th>
<th>Success</th>
</thead>
{{ range . }}
<tr>
<td><span class="fixed"><a href="/work/{{.WorkID.Hex}}">{{.WorkID.Hex}}</a></span></td>
<td><span class="date">{{if .RevDate.IsZero}}Unknown{{else}}{{ .RevDate.Format "Jan 2, 2006 3:04:05 PM" }}{{end}}</span></td>
<td><span class="date">{{if .When.IsZero}}Unknown{{else}}{{ .When.Format "Jan 2, 2006 3:04:05 PM" }}{{end}}</span></td>
<td><a href="/work/{{.WorkID.Hex}}">{{if .Success}}Success{{else}}Failure{{end}}</a></td>
</tr>
{{ end }}
</table>
</div>
</div>
</section>
{{ end }}

0 comments on commit cf0a11d

Please sign in to comment.