Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
22185aed
Commit
22185aed
authored
Feb 06, 2012
by
Andrew Gerrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: update to go1beta
R=golang-dev, dsymonds CC=golang-dev
https://golang.org/cl/5624056
parent
c06bd52a
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
78 additions
and
77 deletions
+78
-77
misc/dashboard/app/app.yaml
misc/dashboard/app/app.yaml
+1
-1
misc/dashboard/app/build/build.go
misc/dashboard/app/build/build.go
+23
-22
misc/dashboard/app/build/handler.go
misc/dashboard/app/build/handler.go
+24
-23
misc/dashboard/app/build/init.go
misc/dashboard/app/build/init.go
+1
-1
misc/dashboard/app/build/key.go
misc/dashboard/app/build/key.go
+1
-1
misc/dashboard/app/build/notify.go
misc/dashboard/app/build/notify.go
+8
-7
misc/dashboard/app/build/test.go
misc/dashboard/app/build/test.go
+10
-10
misc/dashboard/app/build/ui.go
misc/dashboard/app/build/ui.go
+8
-10
misc/dashboard/app/cache/cache.go
misc/dashboard/app/cache/cache.go
+2
-2
No files found.
misc/dashboard/app/app.yaml
View file @
22185aed
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
application
:
golang-org
application
:
golang-org
version
:
build
version
:
build
runtime
:
go
runtime
:
go
api_version
:
3
api_version
:
go1beta
handlers
:
handlers
:
-
url
:
/static
-
url
:
/static
...
...
misc/dashboard/app/build/build.go
View file @
22185aed
...
@@ -8,11 +8,12 @@ import (
...
@@ -8,11 +8,12 @@ import (
"bytes"
"bytes"
"compress/gzip"
"compress/gzip"
"crypto/sha1"
"crypto/sha1"
"errors"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
"os"
"strings"
"strings"
"time"
"appengine"
"appengine"
"appengine/datastore"
"appengine/datastore"
...
@@ -41,7 +42,7 @@ func (p *Package) Key(c appengine.Context) *datastore.Key {
...
@@ -41,7 +42,7 @@ func (p *Package) Key(c appengine.Context) *datastore.Key {
}
}
// LastCommit returns the most recent Commit for this Package.
// LastCommit returns the most recent Commit for this Package.
func
(
p
*
Package
)
LastCommit
(
c
appengine
.
Context
)
(
*
Commit
,
os
.
E
rror
)
{
func
(
p
*
Package
)
LastCommit
(
c
appengine
.
Context
)
(
*
Commit
,
e
rror
)
{
var
commits
[]
*
Commit
var
commits
[]
*
Commit
_
,
err
:=
datastore
.
NewQuery
(
"Commit"
)
.
_
,
err
:=
datastore
.
NewQuery
(
"Commit"
)
.
Ancestor
(
p
.
Key
(
c
))
.
Ancestor
(
p
.
Key
(
c
))
.
...
@@ -58,7 +59,7 @@ func (p *Package) LastCommit(c appengine.Context) (*Commit, os.Error) {
...
@@ -58,7 +59,7 @@ func (p *Package) LastCommit(c appengine.Context) (*Commit, os.Error) {
}
}
// GetPackage fetches a Package by path from the datastore.
// GetPackage fetches a Package by path from the datastore.
func
GetPackage
(
c
appengine
.
Context
,
path
string
)
(
*
Package
,
os
.
E
rror
)
{
func
GetPackage
(
c
appengine
.
Context
,
path
string
)
(
*
Package
,
e
rror
)
{
p
:=
&
Package
{
Path
:
path
}
p
:=
&
Package
{
Path
:
path
}
err
:=
datastore
.
Get
(
c
,
p
.
Key
(
c
),
p
)
err
:=
datastore
.
Get
(
c
,
p
.
Key
(
c
),
p
)
if
err
==
datastore
.
ErrNoSuchEntity
{
if
err
==
datastore
.
ErrNoSuchEntity
{
...
@@ -80,7 +81,7 @@ type Commit struct {
...
@@ -80,7 +81,7 @@ type Commit struct {
User
string
User
string
Desc
string
`datastore:",noindex"`
Desc
string
`datastore:",noindex"`
Time
datastor
e
.
Time
Time
tim
e
.
Time
// ResultData is the Data string of each build Result for this Commit.
// ResultData is the Data string of each build Result for this Commit.
// For non-Go commits, only the Results for the current Go tip, weekly,
// For non-Go commits, only the Results for the current Go tip, weekly,
...
@@ -100,19 +101,19 @@ func (com *Commit) Key(c appengine.Context) *datastore.Key {
...
@@ -100,19 +101,19 @@ func (com *Commit) Key(c appengine.Context) *datastore.Key {
return
datastore
.
NewKey
(
c
,
"Commit"
,
key
,
0
,
p
.
Key
(
c
))
return
datastore
.
NewKey
(
c
,
"Commit"
,
key
,
0
,
p
.
Key
(
c
))
}
}
func
(
c
*
Commit
)
Valid
()
os
.
E
rror
{
func
(
c
*
Commit
)
Valid
()
e
rror
{
if
!
validHash
(
c
.
Hash
)
{
if
!
validHash
(
c
.
Hash
)
{
return
os
.
NewError
(
"invalid Hash"
)
return
errors
.
New
(
"invalid Hash"
)
}
}
if
c
.
ParentHash
!=
""
&&
!
validHash
(
c
.
ParentHash
)
{
// empty is OK
if
c
.
ParentHash
!=
""
&&
!
validHash
(
c
.
ParentHash
)
{
// empty is OK
return
os
.
NewError
(
"invalid ParentHash"
)
return
errors
.
New
(
"invalid ParentHash"
)
}
}
return
nil
return
nil
}
}
// AddResult adds the denormalized Reuslt data to the Commit's Result field.
// AddResult adds the denormalized Reuslt data to the Commit's Result field.
// It must be called from inside a datastore transaction.
// It must be called from inside a datastore transaction.
func
(
com
*
Commit
)
AddResult
(
c
appengine
.
Context
,
r
*
Result
)
os
.
E
rror
{
func
(
com
*
Commit
)
AddResult
(
c
appengine
.
Context
,
r
*
Result
)
e
rror
{
if
err
:=
datastore
.
Get
(
c
,
com
.
Key
(
c
),
com
);
err
!=
nil
{
if
err
:=
datastore
.
Get
(
c
,
com
.
Key
(
c
),
com
);
err
!=
nil
{
return
fmt
.
Errorf
(
"getting Commit: %v"
,
err
)
return
fmt
.
Errorf
(
"getting Commit: %v"
,
err
)
}
}
...
@@ -192,12 +193,12 @@ func (r *Result) Key(c appengine.Context) *datastore.Key {
...
@@ -192,12 +193,12 @@ func (r *Result) Key(c appengine.Context) *datastore.Key {
return
datastore
.
NewKey
(
c
,
"Result"
,
key
,
0
,
p
.
Key
(
c
))
return
datastore
.
NewKey
(
c
,
"Result"
,
key
,
0
,
p
.
Key
(
c
))
}
}
func
(
r
*
Result
)
Valid
()
os
.
E
rror
{
func
(
r
*
Result
)
Valid
()
e
rror
{
if
!
validHash
(
r
.
Hash
)
{
if
!
validHash
(
r
.
Hash
)
{
return
os
.
NewError
(
"invalid Hash"
)
return
errors
.
New
(
"invalid Hash"
)
}
}
if
r
.
PackagePath
!=
""
&&
!
validHash
(
r
.
GoHash
)
{
if
r
.
PackagePath
!=
""
&&
!
validHash
(
r
.
GoHash
)
{
return
os
.
NewError
(
"invalid GoHash"
)
return
errors
.
New
(
"invalid GoHash"
)
}
}
return
nil
return
nil
}
}
...
@@ -214,7 +215,7 @@ type Log struct {
...
@@ -214,7 +215,7 @@ type Log struct {
CompressedLog
[]
byte
CompressedLog
[]
byte
}
}
func
(
l
*
Log
)
Text
()
([]
byte
,
os
.
E
rror
)
{
func
(
l
*
Log
)
Text
()
([]
byte
,
e
rror
)
{
d
,
err
:=
gzip
.
NewReader
(
bytes
.
NewBuffer
(
l
.
CompressedLog
))
d
,
err
:=
gzip
.
NewReader
(
bytes
.
NewBuffer
(
l
.
CompressedLog
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"reading log data: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"reading log data: %v"
,
err
)
...
@@ -226,14 +227,14 @@ func (l *Log) Text() ([]byte, os.Error) {
...
@@ -226,14 +227,14 @@ func (l *Log) Text() ([]byte, os.Error) {
return
b
,
nil
return
b
,
nil
}
}
func
PutLog
(
c
appengine
.
Context
,
text
string
)
(
hash
string
,
err
os
.
E
rror
)
{
func
PutLog
(
c
appengine
.
Context
,
text
string
)
(
hash
string
,
err
e
rror
)
{
h
:=
sha1
.
New
()
h
:=
sha1
.
New
()
io
.
WriteString
(
h
,
text
)
io
.
WriteString
(
h
,
text
)
b
:=
new
(
bytes
.
Buffer
)
b
:=
new
(
bytes
.
Buffer
)
z
,
_
:=
gzip
.
NewWriterLevel
(
b
,
gzip
.
BestCompression
)
z
,
_
:=
gzip
.
NewWriterLevel
(
b
,
gzip
.
BestCompression
)
io
.
WriteString
(
z
,
text
)
io
.
WriteString
(
z
,
text
)
z
.
Close
()
z
.
Close
()
hash
=
fmt
.
Sprintf
(
"%x"
,
h
.
Sum
())
hash
=
fmt
.
Sprintf
(
"%x"
,
h
.
Sum
(
nil
))
key
:=
datastore
.
NewKey
(
c
,
"Log"
,
hash
,
0
,
nil
)
key
:=
datastore
.
NewKey
(
c
,
"Log"
,
hash
,
0
,
nil
)
_
,
err
=
datastore
.
Put
(
c
,
key
,
&
Log
{
b
.
Bytes
()})
_
,
err
=
datastore
.
Put
(
c
,
key
,
&
Log
{
b
.
Bytes
()})
return
return
...
@@ -252,29 +253,29 @@ func (t *Tag) Key(c appengine.Context) *datastore.Key {
...
@@ -252,29 +253,29 @@ func (t *Tag) Key(c appengine.Context) *datastore.Key {
return
datastore
.
NewKey
(
c
,
"Tag"
,
t
.
Kind
,
0
,
p
.
Key
(
c
))
return
datastore
.
NewKey
(
c
,
"Tag"
,
t
.
Kind
,
0
,
p
.
Key
(
c
))
}
}
func
(
t
*
Tag
)
Valid
()
os
.
E
rror
{
func
(
t
*
Tag
)
Valid
()
e
rror
{
if
t
.
Kind
!=
"weekly"
&&
t
.
Kind
!=
"release"
&&
t
.
Kind
!=
"tip"
{
if
t
.
Kind
!=
"weekly"
&&
t
.
Kind
!=
"release"
&&
t
.
Kind
!=
"tip"
{
return
os
.
NewError
(
"invalid Kind"
)
return
errors
.
New
(
"invalid Kind"
)
}
}
if
!
validHash
(
t
.
Hash
)
{
if
!
validHash
(
t
.
Hash
)
{
return
os
.
NewError
(
"invalid Hash"
)
return
errors
.
New
(
"invalid Hash"
)
}
}
return
nil
return
nil
}
}
// Commit returns the Commit that corresponds with this Tag.
// Commit returns the Commit that corresponds with this Tag.
func
(
t
*
Tag
)
Commit
(
c
appengine
.
Context
)
(
*
Commit
,
os
.
E
rror
)
{
func
(
t
*
Tag
)
Commit
(
c
appengine
.
Context
)
(
*
Commit
,
e
rror
)
{
com
:=
&
Commit
{
Hash
:
t
.
Hash
}
com
:=
&
Commit
{
Hash
:
t
.
Hash
}
err
:=
datastore
.
Get
(
c
,
com
.
Key
(
c
),
com
)
err
:=
datastore
.
Get
(
c
,
com
.
Key
(
c
),
com
)
return
com
,
err
return
com
,
err
}
}
// GetTag fetches a Tag by name from the datastore.
// GetTag fetches a Tag by name from the datastore.
func
GetTag
(
c
appengine
.
Context
,
tag
string
)
(
*
Tag
,
os
.
E
rror
)
{
func
GetTag
(
c
appengine
.
Context
,
tag
string
)
(
*
Tag
,
e
rror
)
{
t
:=
&
Tag
{
Kind
:
tag
}
t
:=
&
Tag
{
Kind
:
tag
}
if
err
:=
datastore
.
Get
(
c
,
t
.
Key
(
c
),
t
);
err
!=
nil
{
if
err
:=
datastore
.
Get
(
c
,
t
.
Key
(
c
),
t
);
err
!=
nil
{
if
err
==
datastore
.
ErrNoSuchEntity
{
if
err
==
datastore
.
ErrNoSuchEntity
{
return
nil
,
os
.
NewError
(
"tag not found: "
+
tag
)
return
nil
,
errors
.
New
(
"tag not found: "
+
tag
)
}
}
return
nil
,
err
return
nil
,
err
}
}
...
@@ -286,11 +287,11 @@ func GetTag(c appengine.Context, tag string) (*Tag, os.Error) {
...
@@ -286,11 +287,11 @@ func GetTag(c appengine.Context, tag string) (*Tag, os.Error) {
// Packages returns packages of the specified kind.
// Packages returns packages of the specified kind.
// Kind must be one of "external" or "subrepo".
// Kind must be one of "external" or "subrepo".
func
Packages
(
c
appengine
.
Context
,
kind
string
)
([]
*
Package
,
os
.
E
rror
)
{
func
Packages
(
c
appengine
.
Context
,
kind
string
)
([]
*
Package
,
e
rror
)
{
switch
kind
{
switch
kind
{
case
"external"
,
"subrepo"
:
case
"external"
,
"subrepo"
:
default
:
default
:
return
nil
,
os
.
NewError
(
`kind must be one of "external" or "subrepo"`
)
return
nil
,
errors
.
New
(
`kind must be one of "external" or "subrepo"`
)
}
}
var
pkgs
[]
*
Package
var
pkgs
[]
*
Package
q
:=
datastore
.
NewQuery
(
"Package"
)
.
Filter
(
"Kind="
,
kind
)
q
:=
datastore
.
NewQuery
(
"Package"
)
.
Filter
(
"Kind="
,
kind
)
...
...
misc/dashboard/app/build/handler.go
View file @
22185aed
...
@@ -6,10 +6,11 @@ package build
...
@@ -6,10 +6,11 @@ package build
import
(
import
(
"crypto/hmac"
"crypto/hmac"
"crypto/md5"
"encoding/json"
"errors"
"fmt"
"fmt"
"http"
"net/http"
"json"
"os"
"appengine"
"appengine"
"appengine/datastore"
"appengine/datastore"
...
@@ -28,7 +29,7 @@ const commitsPerPage = 30
...
@@ -28,7 +29,7 @@ const commitsPerPage = 30
// each new commit at tip.
// each new commit at tip.
//
//
// This handler is used by a gobuilder process in -commit mode.
// This handler is used by a gobuilder process in -commit mode.
func
commitHandler
(
r
*
http
.
Request
)
(
interface
{},
os
.
E
rror
)
{
func
commitHandler
(
r
*
http
.
Request
)
(
interface
{},
e
rror
)
{
c
:=
appengine
.
NewContext
(
r
)
c
:=
appengine
.
NewContext
(
r
)
com
:=
new
(
Commit
)
com
:=
new
(
Commit
)
...
@@ -56,7 +57,7 @@ func commitHandler(r *http.Request) (interface{}, os.Error) {
...
@@ -56,7 +57,7 @@ func commitHandler(r *http.Request) (interface{}, os.Error) {
return
nil
,
fmt
.
Errorf
(
"validating Commit: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"validating Commit: %v"
,
err
)
}
}
defer
cache
.
Tick
(
c
)
defer
cache
.
Tick
(
c
)
tx
:=
func
(
c
appengine
.
Context
)
os
.
E
rror
{
tx
:=
func
(
c
appengine
.
Context
)
e
rror
{
return
addCommit
(
c
,
com
)
return
addCommit
(
c
,
com
)
}
}
return
nil
,
datastore
.
RunInTransaction
(
c
,
tx
,
nil
)
return
nil
,
datastore
.
RunInTransaction
(
c
,
tx
,
nil
)
...
@@ -64,7 +65,7 @@ func commitHandler(r *http.Request) (interface{}, os.Error) {
...
@@ -64,7 +65,7 @@ func commitHandler(r *http.Request) (interface{}, os.Error) {
// addCommit adds the Commit entity to the datastore and updates the tip Tag.
// addCommit adds the Commit entity to the datastore and updates the tip Tag.
// It must be run inside a datastore transaction.
// It must be run inside a datastore transaction.
func
addCommit
(
c
appengine
.
Context
,
com
*
Commit
)
os
.
E
rror
{
func
addCommit
(
c
appengine
.
Context
,
com
*
Commit
)
e
rror
{
var
tc
Commit
// temp value so we don't clobber com
var
tc
Commit
// temp value so we don't clobber com
err
:=
datastore
.
Get
(
c
,
com
.
Key
(
c
),
&
tc
)
err
:=
datastore
.
Get
(
c
,
com
.
Key
(
c
),
&
tc
)
if
err
!=
datastore
.
ErrNoSuchEntity
{
if
err
!=
datastore
.
ErrNoSuchEntity
{
...
@@ -94,7 +95,7 @@ func addCommit(c appengine.Context, com *Commit) os.Error {
...
@@ -94,7 +95,7 @@ func addCommit(c appengine.Context, com *Commit) os.Error {
return
fmt
.
Errorf
(
"testing for parent Commit: %v"
,
err
)
return
fmt
.
Errorf
(
"testing for parent Commit: %v"
,
err
)
}
}
if
n
==
0
{
if
n
==
0
{
return
os
.
NewError
(
"parent commit not found"
)
return
errors
.
New
(
"parent commit not found"
)
}
}
}
}
// update the tip Tag if this is the Go repo
// update the tip Tag if this is the Go repo
...
@@ -115,7 +116,7 @@ func addCommit(c appengine.Context, com *Commit) os.Error {
...
@@ -115,7 +116,7 @@ func addCommit(c appengine.Context, com *Commit) os.Error {
// request body and updates the Tag entity for the Kind of tag provided.
// request body and updates the Tag entity for the Kind of tag provided.
//
//
// This handler is used by a gobuilder process in -commit mode.
// This handler is used by a gobuilder process in -commit mode.
func
tagHandler
(
r
*
http
.
Request
)
(
interface
{},
os
.
E
rror
)
{
func
tagHandler
(
r
*
http
.
Request
)
(
interface
{},
e
rror
)
{
if
r
.
Method
!=
"POST"
{
if
r
.
Method
!=
"POST"
{
return
nil
,
errBadMethod
(
r
.
Method
)
return
nil
,
errBadMethod
(
r
.
Method
)
}
}
...
@@ -143,7 +144,7 @@ type Todo struct {
...
@@ -143,7 +144,7 @@ type Todo struct {
// todoHandler returns the next action to be performed by a builder.
// todoHandler returns the next action to be performed by a builder.
// It expects "builder" and "kind" query parameters and returns a *Todo value.
// It expects "builder" and "kind" query parameters and returns a *Todo value.
// Multiple "kind" parameters may be specified.
// Multiple "kind" parameters may be specified.
func
todoHandler
(
r
*
http
.
Request
)
(
interface
{},
os
.
E
rror
)
{
func
todoHandler
(
r
*
http
.
Request
)
(
interface
{},
e
rror
)
{
c
:=
appengine
.
NewContext
(
r
)
c
:=
appengine
.
NewContext
(
r
)
now
:=
cache
.
Now
(
c
)
now
:=
cache
.
Now
(
c
)
key
:=
"build-todo-"
+
r
.
Form
.
Encode
()
key
:=
"build-todo-"
+
r
.
Form
.
Encode
()
...
@@ -151,7 +152,7 @@ func todoHandler(r *http.Request) (interface{}, os.Error) {
...
@@ -151,7 +152,7 @@ func todoHandler(r *http.Request) (interface{}, os.Error) {
if
cache
.
Get
(
r
,
now
,
key
,
&
todo
)
{
if
cache
.
Get
(
r
,
now
,
key
,
&
todo
)
{
return
todo
,
nil
return
todo
,
nil
}
}
var
err
os
.
E
rror
var
err
e
rror
builder
:=
r
.
FormValue
(
"builder"
)
builder
:=
r
.
FormValue
(
"builder"
)
for
_
,
kind
:=
range
r
.
Form
[
"kind"
]
{
for
_
,
kind
:=
range
r
.
Form
[
"kind"
]
{
var
data
interface
{}
var
data
interface
{}
...
@@ -183,7 +184,7 @@ func todoHandler(r *http.Request) (interface{}, os.Error) {
...
@@ -183,7 +184,7 @@ func todoHandler(r *http.Request) (interface{}, os.Error) {
// If provided with non-empty packagePath and goHash args, it scans the first
// If provided with non-empty packagePath and goHash args, it scans the first
// 20 Commits in Num-descending order for the specified packagePath and
// 20 Commits in Num-descending order for the specified packagePath and
// returns the first that doesn't have a Result for this builder and goHash.
// returns the first that doesn't have a Result for this builder and goHash.
func
buildTodo
(
c
appengine
.
Context
,
builder
,
packagePath
,
goHash
string
)
(
interface
{},
os
.
E
rror
)
{
func
buildTodo
(
c
appengine
.
Context
,
builder
,
packagePath
,
goHash
string
)
(
interface
{},
e
rror
)
{
p
,
err
:=
GetPackage
(
c
,
packagePath
)
p
,
err
:=
GetPackage
(
c
,
packagePath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -251,7 +252,7 @@ func buildTodo(c appengine.Context, builder, packagePath, goHash string) (interf
...
@@ -251,7 +252,7 @@ func buildTodo(c appengine.Context, builder, packagePath, goHash string) (interf
// packagesHandler returns a list of the non-Go Packages monitored
// packagesHandler returns a list of the non-Go Packages monitored
// by the dashboard.
// by the dashboard.
func
packagesHandler
(
r
*
http
.
Request
)
(
interface
{},
os
.
E
rror
)
{
func
packagesHandler
(
r
*
http
.
Request
)
(
interface
{},
e
rror
)
{
kind
:=
r
.
FormValue
(
"kind"
)
kind
:=
r
.
FormValue
(
"kind"
)
c
:=
appengine
.
NewContext
(
r
)
c
:=
appengine
.
NewContext
(
r
)
now
:=
cache
.
Now
(
c
)
now
:=
cache
.
Now
(
c
)
...
@@ -273,7 +274,7 @@ func packagesHandler(r *http.Request) (interface{}, os.Error) {
...
@@ -273,7 +274,7 @@ func packagesHandler(r *http.Request) (interface{}, os.Error) {
// creates a new Result entity, and updates the relevant Commit entity.
// creates a new Result entity, and updates the relevant Commit entity.
// If the Log field is not empty, resultHandler creates a new Log entity
// If the Log field is not empty, resultHandler creates a new Log entity
// and updates the LogHash field before putting the Commit entity.
// and updates the LogHash field before putting the Commit entity.
func
resultHandler
(
r
*
http
.
Request
)
(
interface
{},
os
.
E
rror
)
{
func
resultHandler
(
r
*
http
.
Request
)
(
interface
{},
e
rror
)
{
if
r
.
Method
!=
"POST"
{
if
r
.
Method
!=
"POST"
{
return
nil
,
errBadMethod
(
r
.
Method
)
return
nil
,
errBadMethod
(
r
.
Method
)
}
}
...
@@ -296,7 +297,7 @@ func resultHandler(r *http.Request) (interface{}, os.Error) {
...
@@ -296,7 +297,7 @@ func resultHandler(r *http.Request) (interface{}, os.Error) {
}
}
res
.
LogHash
=
hash
res
.
LogHash
=
hash
}
}
tx
:=
func
(
c
appengine
.
Context
)
os
.
E
rror
{
tx
:=
func
(
c
appengine
.
Context
)
e
rror
{
// check Package exists
// check Package exists
if
_
,
err
:=
GetPackage
(
c
,
res
.
PackagePath
);
err
!=
nil
{
if
_
,
err
:=
GetPackage
(
c
,
res
.
PackagePath
);
err
!=
nil
{
return
fmt
.
Errorf
(
"GetPackage: %v"
,
err
)
return
fmt
.
Errorf
(
"GetPackage: %v"
,
err
)
...
@@ -338,7 +339,7 @@ func logHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -338,7 +339,7 @@ func logHandler(w http.ResponseWriter, r *http.Request) {
w
.
Write
(
b
)
w
.
Write
(
b
)
}
}
type
dashHandler
func
(
*
http
.
Request
)
(
interface
{},
os
.
E
rror
)
type
dashHandler
func
(
*
http
.
Request
)
(
interface
{},
e
rror
)
type
dashResponse
struct
{
type
dashResponse
struct
{
Response
interface
{}
Response
interface
{}
...
@@ -349,7 +350,7 @@ type dashResponse struct {
...
@@ -349,7 +350,7 @@ type dashResponse struct {
// the request has an unsuitable method.
// the request has an unsuitable method.
type
errBadMethod
string
type
errBadMethod
string
func
(
e
errBadMethod
)
String
()
string
{
func
(
e
errBadMethod
)
Error
()
string
{
return
"bad method: "
+
string
(
e
)
return
"bad method: "
+
string
(
e
)
}
}
...
@@ -363,14 +364,14 @@ func AuthHandler(h dashHandler) http.HandlerFunc {
...
@@ -363,14 +364,14 @@ func AuthHandler(h dashHandler) http.HandlerFunc {
// request body when calling r.FormValue.
// request body when calling r.FormValue.
r
.
Form
=
r
.
URL
.
Query
()
r
.
Form
=
r
.
URL
.
Query
()
var
err
os
.
E
rror
var
err
e
rror
var
resp
interface
{}
var
resp
interface
{}
// Validate key query parameter for POST requests only.
// Validate key query parameter for POST requests only.
key
:=
r
.
FormValue
(
"key"
)
key
:=
r
.
FormValue
(
"key"
)
builder
:=
r
.
FormValue
(
"builder"
)
builder
:=
r
.
FormValue
(
"builder"
)
if
r
.
Method
==
"POST"
&&
!
validKey
(
c
,
key
,
builder
)
{
if
r
.
Method
==
"POST"
&&
!
validKey
(
c
,
key
,
builder
)
{
err
=
os
.
NewError
(
"invalid key: "
+
key
)
err
=
errors
.
New
(
"invalid key: "
+
key
)
}
}
// Call the original HandlerFunc and return the response.
// Call the original HandlerFunc and return the response.
...
@@ -382,7 +383,7 @@ func AuthHandler(h dashHandler) http.HandlerFunc {
...
@@ -382,7 +383,7 @@ func AuthHandler(h dashHandler) http.HandlerFunc {
dashResp
:=
&
dashResponse
{
Response
:
resp
}
dashResp
:=
&
dashResponse
{
Response
:
resp
}
if
err
!=
nil
{
if
err
!=
nil
{
c
.
Errorf
(
"%v"
,
err
)
c
.
Errorf
(
"%v"
,
err
)
dashResp
.
Error
=
err
.
String
()
dashResp
.
Error
=
err
.
Error
()
}
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
if
err
=
json
.
NewEncoder
(
w
)
.
Encode
(
dashResp
);
err
!=
nil
{
if
err
=
json
.
NewEncoder
(
w
)
.
Encode
(
dashResp
);
err
!=
nil
{
...
@@ -394,7 +395,7 @@ func AuthHandler(h dashHandler) http.HandlerFunc {
...
@@ -394,7 +395,7 @@ func AuthHandler(h dashHandler) http.HandlerFunc {
func
keyHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
keyHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
builder
:=
r
.
FormValue
(
"builder"
)
builder
:=
r
.
FormValue
(
"builder"
)
if
builder
==
""
{
if
builder
==
""
{
logErr
(
w
,
r
,
os
.
NewError
(
"must supply builder in query string"
))
logErr
(
w
,
r
,
errors
.
New
(
"must supply builder in query string"
))
return
return
}
}
c
:=
appengine
.
NewContext
(
r
)
c
:=
appengine
.
NewContext
(
r
)
...
@@ -433,12 +434,12 @@ func validKey(c appengine.Context, key, builder string) bool {
...
@@ -433,12 +434,12 @@ func validKey(c appengine.Context, key, builder string) bool {
}
}
func
builderKey
(
c
appengine
.
Context
,
builder
string
)
string
{
func
builderKey
(
c
appengine
.
Context
,
builder
string
)
string
{
h
:=
hmac
.
New
MD5
(
[]
byte
(
secretKey
(
c
)))
h
:=
hmac
.
New
(
md5
.
New
,
[]
byte
(
secretKey
(
c
)))
h
.
Write
([]
byte
(
builder
))
h
.
Write
([]
byte
(
builder
))
return
fmt
.
Sprintf
(
"%x"
,
h
.
Sum
())
return
fmt
.
Sprintf
(
"%x"
,
h
.
Sum
(
nil
))
}
}
func
logErr
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
err
os
.
E
rror
)
{
func
logErr
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
err
e
rror
)
{
appengine
.
NewContext
(
r
)
.
Errorf
(
"Error: %v"
,
err
)
appengine
.
NewContext
(
r
)
.
Errorf
(
"Error: %v"
,
err
)
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
w
.
WriteHeader
(
http
.
StatusInternalServerError
)
fmt
.
Fprint
(
w
,
"Error: "
,
err
)
fmt
.
Fprint
(
w
,
"Error: "
,
err
)
...
...
misc/dashboard/app/build/init.go
View file @
22185aed
...
@@ -6,7 +6,7 @@ package build
...
@@ -6,7 +6,7 @@ package build
import
(
import
(
"fmt"
"fmt"
"http"
"
net/
http"
"appengine"
"appengine"
"appengine/datastore"
"appengine/datastore"
...
...
misc/dashboard/app/build/key.go
View file @
22185aed
...
@@ -55,7 +55,7 @@ func secretKey(c appengine.Context) string {
...
@@ -55,7 +55,7 @@ func secretKey(c appengine.Context) string {
datastore
.
Put
(
c
,
theKey
.
Key
(
c
),
&
theKey
.
BuilderKey
)
datastore
.
Put
(
c
,
theKey
.
Key
(
c
),
&
theKey
.
BuilderKey
)
return
theKey
.
Secret
return
theKey
.
Secret
}
}
panic
(
"cannot load builder key: "
+
err
.
String
())
panic
(
"cannot load builder key: "
+
err
.
Error
())
}
}
return
theKey
.
Secret
return
theKey
.
Secret
...
...
misc/dashboard/app/build/notify.go
View file @
22185aed
...
@@ -10,10 +10,9 @@ import (
...
@@ -10,10 +10,9 @@ import (
"appengine/delay"
"appengine/delay"
"appengine/mail"
"appengine/mail"
"bytes"
"bytes"
"encoding/gob"
"fmt"
"fmt"
"gob"
"text/template"
"os"
"template"
)
)
const
(
const
(
...
@@ -30,7 +29,7 @@ const (
...
@@ -30,7 +29,7 @@ const (
//
//
// This must be run in a datastore transaction, and the provided *Commit must
// This must be run in a datastore transaction, and the provided *Commit must
// have been retrieved from the datastore within that transaction.
// have been retrieved from the datastore within that transaction.
func
notifyOnFailure
(
c
appengine
.
Context
,
com
*
Commit
,
builder
string
)
os
.
E
rror
{
func
notifyOnFailure
(
c
appengine
.
Context
,
com
*
Commit
,
builder
string
)
e
rror
{
// TODO(adg): implement notifications for packages
// TODO(adg): implement notifications for packages
if
com
.
PackagePath
!=
""
{
if
com
.
PackagePath
!=
""
{
return
nil
return
nil
...
@@ -73,7 +72,7 @@ func notifyOnFailure(c appengine.Context, com *Commit, builder string) os.Error
...
@@ -73,7 +72,7 @@ func notifyOnFailure(c appengine.Context, com *Commit, builder string) os.Error
broken
=
com
broken
=
com
}
}
}
}
var
err
os
.
E
rror
var
err
e
rror
if
broken
!=
nil
&&
!
broken
.
FailNotificationSent
{
if
broken
!=
nil
&&
!
broken
.
FailNotificationSent
{
c
.
Infof
(
"%s is broken commit; notifying"
,
broken
.
Hash
)
c
.
Infof
(
"%s is broken commit; notifying"
,
broken
.
Hash
)
sendFailMailLater
.
Call
(
c
,
broken
,
builder
)
// add task to queue
sendFailMailLater
.
Call
(
c
,
broken
,
builder
)
// add task to queue
...
@@ -84,7 +83,7 @@ func notifyOnFailure(c appengine.Context, com *Commit, builder string) os.Error
...
@@ -84,7 +83,7 @@ func notifyOnFailure(c appengine.Context, com *Commit, builder string) os.Error
}
}
// firstMatch executes the query q and loads the first entity into v.
// firstMatch executes the query q and loads the first entity into v.
func
firstMatch
(
c
appengine
.
Context
,
q
*
datastore
.
Query
,
v
interface
{})
os
.
E
rror
{
func
firstMatch
(
c
appengine
.
Context
,
q
*
datastore
.
Query
,
v
interface
{})
e
rror
{
t
:=
q
.
Limit
(
1
)
.
Run
(
c
)
t
:=
q
.
Limit
(
1
)
.
Run
(
c
)
_
,
err
:=
t
.
Next
(
v
)
_
,
err
:=
t
.
Next
(
v
)
if
err
==
datastore
.
Done
{
if
err
==
datastore
.
Done
{
...
@@ -96,7 +95,9 @@ func firstMatch(c appengine.Context, q *datastore.Query, v interface{}) os.Error
...
@@ -96,7 +95,9 @@ func firstMatch(c appengine.Context, q *datastore.Query, v interface{}) os.Error
var
(
var
(
sendFailMailLater
=
delay
.
Func
(
"sendFailMail"
,
sendFailMail
)
sendFailMailLater
=
delay
.
Func
(
"sendFailMail"
,
sendFailMail
)
sendFailMailTmpl
=
template
.
Must
(
sendFailMailTmpl
=
template
.
Must
(
template
.
New
(
"notify"
)
.
Funcs
(
tmplFuncs
)
.
ParseFile
(
"build/notify.txt"
),
template
.
New
(
"notify.txt"
)
.
Funcs
(
template
.
FuncMap
(
tmplFuncs
))
.
ParseFiles
(
"build/notify.txt"
),
)
)
)
)
...
...
misc/dashboard/app/build/test.go
View file @
22185aed
...
@@ -10,15 +10,15 @@ import (
...
@@ -10,15 +10,15 @@ import (
"appengine"
"appengine"
"appengine/datastore"
"appengine/datastore"
"bytes"
"bytes"
"encoding/json"
"errors"
"fmt"
"fmt"
"http"
"http/httptest"
"io"
"io"
"json"
"net/http"
"os"
"net/http/httptest"
"net/url"
"strings"
"strings"
"time"
"time"
"url"
)
)
func
init
()
{
func
init
()
{
...
@@ -41,14 +41,14 @@ var testPackages = []*Package{
...
@@ -41,14 +41,14 @@ var testPackages = []*Package{
testPackage
,
testPackage
,
}
}
var
tCommitTime
=
time
.
Seconds
()
-
60
*
60
*
24
*
7
var
tCommitTime
=
time
.
Now
()
.
Add
(
-
time
.
Hour
*
24
*
7
)
func
tCommit
(
hash
,
parentHash
string
)
*
Commit
{
func
tCommit
(
hash
,
parentHash
string
)
*
Commit
{
tCommitTime
+=
60
*
60
*
12
// each commit should have a different time
tCommitTime
.
Add
(
time
.
Hour
)
// each commit should have a different time
return
&
Commit
{
return
&
Commit
{
Hash
:
hash
,
Hash
:
hash
,
ParentHash
:
parentHash
,
ParentHash
:
parentHash
,
Time
:
datastore
.
Time
(
tCommitTime
*
1e6
)
,
Time
:
tCommitTime
,
User
:
"adg"
,
User
:
"adg"
,
Desc
:
"change description"
,
Desc
:
"change description"
,
}
}
...
@@ -233,9 +233,9 @@ func testHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -233,9 +233,9 @@ func testHandler(w http.ResponseWriter, r *http.Request) {
fmt
.
Fprint
(
w
,
"PASS"
)
fmt
.
Fprint
(
w
,
"PASS"
)
}
}
func
nukeEntities
(
c
appengine
.
Context
,
kinds
[]
string
)
os
.
E
rror
{
func
nukeEntities
(
c
appengine
.
Context
,
kinds
[]
string
)
e
rror
{
if
!
appengine
.
IsDevAppServer
()
{
if
!
appengine
.
IsDevAppServer
()
{
return
os
.
NewError
(
"can't nuke production data"
)
return
errors
.
New
(
"can't nuke production data"
)
}
}
var
keys
[]
*
datastore
.
Key
var
keys
[]
*
datastore
.
Key
for
_
,
kind
:=
range
kinds
{
for
_
,
kind
:=
range
kinds
{
...
...
misc/dashboard/app/build/ui.go
View file @
22185aed
...
@@ -9,14 +9,13 @@ package build
...
@@ -9,14 +9,13 @@ package build
import
(
import
(
"bytes"
"bytes"
"e
xp/template/html
"
"e
rrors
"
"ht
tp
"
"ht
ml/template
"
"
os
"
"
net/http
"
"regexp"
"regexp"
"sort"
"sort"
"strconv"
"strconv"
"strings"
"strings"
"template"
"appengine"
"appengine"
"appengine/datastore"
"appengine/datastore"
...
@@ -25,7 +24,6 @@ import (
...
@@ -25,7 +24,6 @@ import (
func
init
()
{
func
init
()
{
http
.
HandleFunc
(
"/"
,
uiHandler
)
http
.
HandleFunc
(
"/"
,
uiHandler
)
html
.
Escape
(
uiTemplate
)
}
}
// uiHandler draws the build status page.
// uiHandler draws the build status page.
...
@@ -96,7 +94,7 @@ type Pagination struct {
...
@@ -96,7 +94,7 @@ type Pagination struct {
// goCommits gets a slice of the latest Commits to the Go repository.
// goCommits gets a slice of the latest Commits to the Go repository.
// If page > 0 it paginates by commitsPerPage.
// If page > 0 it paginates by commitsPerPage.
func
goCommits
(
c
appengine
.
Context
,
page
int
)
([]
*
Commit
,
os
.
E
rror
)
{
func
goCommits
(
c
appengine
.
Context
,
page
int
)
([]
*
Commit
,
e
rror
)
{
q
:=
datastore
.
NewQuery
(
"Commit"
)
.
q
:=
datastore
.
NewQuery
(
"Commit"
)
.
Ancestor
((
&
Package
{})
.
Key
(
c
))
.
Ancestor
((
&
Package
{})
.
Key
(
c
))
.
Order
(
"-Time"
)
.
Order
(
"-Time"
)
.
...
@@ -140,7 +138,7 @@ type PackageState struct {
...
@@ -140,7 +138,7 @@ type PackageState struct {
}
}
// TagStateByName fetches the results for all Go subrepos at the specified Tag.
// TagStateByName fetches the results for all Go subrepos at the specified Tag.
func
TagStateByName
(
c
appengine
.
Context
,
name
string
)
(
*
TagState
,
os
.
E
rror
)
{
func
TagStateByName
(
c
appengine
.
Context
,
name
string
)
(
*
TagState
,
e
rror
)
{
tag
,
err
:=
GetTag
(
c
,
name
)
tag
,
err
:=
GetTag
(
c
,
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -173,7 +171,7 @@ type uiTemplateData struct {
...
@@ -173,7 +171,7 @@ type uiTemplateData struct {
}
}
var
uiTemplate
=
template
.
Must
(
var
uiTemplate
=
template
.
Must
(
template
.
New
(
"ui
"
)
.
Funcs
(
tmplFuncs
)
.
ParseFile
(
"build/ui.html"
),
template
.
New
(
"ui
.html"
)
.
Funcs
(
tmplFuncs
)
.
ParseFiles
(
"build/ui.html"
),
)
)
var
tmplFuncs
=
template
.
FuncMap
{
var
tmplFuncs
=
template
.
FuncMap
{
...
@@ -293,13 +291,13 @@ func shortUser(user string) string {
...
@@ -293,13 +291,13 @@ func shortUser(user string) string {
var
repoRe
=
regexp
.
MustCompile
(
`^code\.google\.com/p/([a-z0-9\-]+)(\.[a-z0-9\-]+)?$`
)
var
repoRe
=
regexp
.
MustCompile
(
`^code\.google\.com/p/([a-z0-9\-]+)(\.[a-z0-9\-]+)?$`
)
// repoURL returns the URL of a change at a Google Code repository or subrepo.
// repoURL returns the URL of a change at a Google Code repository or subrepo.
func
repoURL
(
hash
,
packagePath
string
)
(
string
,
os
.
E
rror
)
{
func
repoURL
(
hash
,
packagePath
string
)
(
string
,
e
rror
)
{
if
packagePath
==
""
{
if
packagePath
==
""
{
return
"https://code.google.com/p/go/source/detail?r="
+
hash
,
nil
return
"https://code.google.com/p/go/source/detail?r="
+
hash
,
nil
}
}
m
:=
repoRe
.
FindStringSubmatch
(
packagePath
)
m
:=
repoRe
.
FindStringSubmatch
(
packagePath
)
if
m
==
nil
{
if
m
==
nil
{
return
""
,
os
.
NewError
(
"unrecognized package: "
+
packagePath
)
return
""
,
errors
.
New
(
"unrecognized package: "
+
packagePath
)
}
}
url
:=
"https://code.google.com/p/"
+
m
[
1
]
+
"/source/detail?r="
+
hash
url
:=
"https://code.google.com/p/"
+
m
[
1
]
+
"/source/detail?r="
+
hash
if
len
(
m
)
>
2
{
if
len
(
m
)
>
2
{
...
...
misc/dashboard/app/cache/cache.go
View file @
22185aed
...
@@ -6,7 +6,7 @@ package cache
...
@@ -6,7 +6,7 @@ package cache
import
(
import
(
"fmt"
"fmt"
"http"
"
net/
http"
"time"
"time"
"appengine"
"appengine"
...
@@ -19,7 +19,7 @@ const (
...
@@ -19,7 +19,7 @@ const (
expiry
=
600
// 10 minutes
expiry
=
600
// 10 minutes
)
)
func
newTime
()
uint64
{
return
uint64
(
time
.
Seconds
())
<<
32
}
func
newTime
()
uint64
{
return
uint64
(
time
.
Now
()
.
Unix
())
<<
32
}
// Now returns the current logical datastore time to use for cache lookups.
// Now returns the current logical datastore time to use for cache lookups.
func
Now
(
c
appengine
.
Context
)
uint64
{
func
Now
(
c
appengine
.
Context
)
uint64
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment