Merge branch 'master' into daniel/threepidinvites-2

This commit is contained in:
Daniel Wagner-Hall 2015-09-14 17:08:22 +01:00
commit b916823d0f
4 changed files with 62 additions and 16 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
scripts/gen scripts/gen
scripts/continuserv/continuserv scripts/continuserv/continuserv
scripts/speculator/speculator
templating/out templating/out
*.pyc *.pyc
supporting-docs/_site supporting-docs/_site

View file

@ -285,8 +285,11 @@ paths:
chunk: chunk:
type: array type: array
description: |- description: |-
A list of the most recent messages for this room. This If the user is a member of the room this will be a
array will consist of at most ``limit`` elements. list of the most recent messages for this room. If
the user has left the room this will be the
messages that preceeded them leaving. This array
will consist of at most ``limit`` elements.
items: items:
type: object type: object
title: RoomEvent title: RoomEvent
@ -296,8 +299,10 @@ paths:
state: state:
type: array type: array
description: |- description: |-
A list of state events representing the current state If the user is a member of the room this will be the
of the room. current state of the room as a list of events. If the
user has left the room this will be the state of the
room when they left it.
items: items:
title: StateEvent title: StateEvent
type: object type: object
@ -347,4 +352,4 @@ paths:
allOf: allOf:
- "$ref": "definitions/event.yaml" - "$ref": "definitions/event.yaml"
404: 404:
description: The event was not found or you do not have permission to read this event. description: The event was not found or you do not have permission to read this event.

View file

@ -1,6 +1,7 @@
speculator allows you to preview pull requests to the matrix.org specification. speculator allows you to preview pull requests to the matrix.org specification.
It serves two HTTP endpoints: It serves the following HTTP endpoints:
- / lists open pull requests
- /spec/123 which renders the spec as html at pull request 123. - /spec/123 which renders the spec as html at pull request 123.
- /diff/rst/123 which gives a diff of the spec's rst at pull request 123. - /diff/rst/123 which gives a diff of the spec's rst at pull request 123.

View file

@ -1,5 +1,6 @@
// speculator allows you to preview pull requests to the matrix.org specification. // speculator allows you to preview pull requests to the matrix.org specification.
// It serves two HTTP endpoints: // It serves the following HTTP endpoints:
// - / lists open pull requests
// - /spec/123 which renders the spec as html at pull request 123. // - /spec/123 which renders the spec as html at pull request 123.
// - /diff/rst/123 which gives a diff of the spec's rst at pull request 123. // - /diff/rst/123 which gives a diff of the spec's rst at pull request 123.
// It is currently woefully inefficient, and there is a lot of low hanging fruit for improvement. // It is currently woefully inefficient, and there is a lot of low hanging fruit for improvement.
@ -24,9 +25,12 @@ import (
) )
type PullRequest struct { type PullRequest struct {
Base Commit Number int
Head Commit Base Commit
User User Head Commit
Title string
User User
HTMLURL string `json:"html_url"`
} }
type Commit struct { type Commit struct {
@ -39,7 +43,8 @@ type RequestRepo struct {
} }
type User struct { type User struct {
Login string Login string
HTMLURL string `json:"html_url"`
} }
var ( var (
@ -47,6 +52,8 @@ var (
allowedMembers map[string]bool allowedMembers map[string]bool
) )
const pullsPrefix = "https://api.github.com/repos/matrix-org/matrix-doc/pulls"
func gitClone(url string) (string, error) { func gitClone(url string) (string, error) {
dst := path.Join("/tmp/matrix-doc", strconv.FormatInt(rand.Int63(), 10)) dst := path.Join("/tmp/matrix-doc", strconv.FormatInt(rand.Int63(), 10))
cmd := exec.Command("git", "clone", url, dst) cmd := exec.Command("git", "clone", url, dst)
@ -67,13 +74,18 @@ func gitCheckout(path, sha string) error {
return nil return nil
} }
func lookupPullRequest(prNumber string) (PullRequest, error) { func lookupPullRequest(prNumber string) (*PullRequest, error) {
resp, _ := http.Get("https://api.github.com/repos/matrix-org/matrix-doc/pulls/" + prNumber) resp, err := http.Get(fmt.Sprintf("%s/%s", pullsPrefix, prNumber))
defer resp.Body.Close() defer resp.Body.Close()
if err != nil {
return nil, fmt.Errorf("error getting pulls: %v", err)
}
dec := json.NewDecoder(resp.Body) dec := json.NewDecoder(resp.Body)
var pr PullRequest var pr PullRequest
_ = dec.Decode(&pr) if err := dec.Decode(&pr); err != nil {
return pr, nil return nil, fmt.Errorf("error decoding pulls: %v", err)
}
return &pr, nil
} }
func generate(dir string) error { func generate(dir string) error {
@ -182,7 +194,7 @@ func serveRstDiff(w http.ResponseWriter, req *http.Request) {
return return
} }
diffCmd := exec.Command("diff", path.Join(base, "scripts", "tmp", "full_spec.rst"), path.Join(head, "scripts", "tmp", "full_spec.rst")) diffCmd := exec.Command("diff", "-u", path.Join(base, "scripts", "tmp", "full_spec.rst"), path.Join(head, "scripts", "tmp", "full_spec.rst"))
var diff bytes.Buffer var diff bytes.Buffer
diffCmd.Stdout = &diff diffCmd.Stdout = &diff
if err := ignoreExitCodeOne(diffCmd.Run()); err != nil { if err := ignoreExitCodeOne(diffCmd.Run()); err != nil {
@ -192,6 +204,32 @@ func serveRstDiff(w http.ResponseWriter, req *http.Request) {
w.Write(diff.Bytes()) w.Write(diff.Bytes())
} }
func listPulls(w http.ResponseWriter, req *http.Request) {
resp, err := http.Get(pullsPrefix)
if err != nil {
writeError(w, err)
return
}
defer resp.Body.Close()
dec := json.NewDecoder(resp.Body)
var pulls []PullRequest
if err := dec.Decode(&pulls); err != nil {
writeError(w, err)
return
}
if len(pulls) == 0 {
io.WriteString(w, "No pull requests found")
return
}
s := "<body><ul>"
for _, pull := range pulls {
s += fmt.Sprintf(`<li>%d: <a href="%s">%s</a>: <a href="%s">%s</a>: <a href="spec/%d">spec</a> <a href="diff/rst/%d">rst diff</a></li>`,
pull.Number, pull.User.HTMLURL, pull.User.Login, pull.HTMLURL, pull.Title, pull.Number, pull.Number)
}
s += "</ul></body>"
io.WriteString(w, s)
}
func ignoreExitCodeOne(err error) error { func ignoreExitCodeOne(err error) error {
if err == nil { if err == nil {
return err return err
@ -221,6 +259,7 @@ func main() {
http.HandleFunc("/spec/", serveSpec) http.HandleFunc("/spec/", serveSpec)
http.HandleFunc("/diff/rst/", serveRstDiff) http.HandleFunc("/diff/rst/", serveRstDiff)
http.HandleFunc("/healthz", serveText("ok")) http.HandleFunc("/healthz", serveText("ok"))
http.HandleFunc("/", listPulls)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
} }