From c74c1ab098876e26efe561a5ecd6a1cc88d76284 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Mon, 7 Sep 2015 17:09:41 +0100 Subject: [PATCH 1/6] SPEC-216: Add rooms that have been left to initial sync --- api/client-server/v1/sync.yaml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/api/client-server/v1/sync.yaml b/api/client-server/v1/sync.yaml index a08146b4..777e27db 100644 --- a/api/client-server/v1/sync.yaml +++ b/api/client-server/v1/sync.yaml @@ -285,8 +285,11 @@ paths: chunk: type: array description: |- - A list of the most recent messages for this room. This - array will consist of at most ``limit`` elements. + If the user is a member of the room this will be a + 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: type: object title: RoomEvent @@ -296,8 +299,10 @@ paths: state: type: array description: |- - A list of state events representing the current state - of the room. + If the user is a member of the room this will be the + 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: title: StateEvent type: object @@ -347,4 +352,4 @@ paths: allOf: - "$ref": "definitions/event.yaml" 404: - description: The event was not found or you do not have permission to read this event. \ No newline at end of file + description: The event was not found or you do not have permission to read this event. From ba780a589a9311dce856342d978ad3f45d10f392 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Fri, 11 Sep 2015 14:40:08 +0100 Subject: [PATCH 2/6] speculator: Add list-pull-request functionality --- scripts/speculator/main.go | 43 +++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/scripts/speculator/main.go b/scripts/speculator/main.go index 3775ad86..757c48e7 100644 --- a/scripts/speculator/main.go +++ b/scripts/speculator/main.go @@ -24,9 +24,12 @@ import ( ) type PullRequest struct { - Base Commit - Head Commit - User User + Number int + Base Commit + Head Commit + Title string + User User + HTMLURL string `json:"html_url"` } type Commit struct { @@ -39,7 +42,8 @@ type RequestRepo struct { } type User struct { - Login string + Login string + HTMLURL string `json:"html_url"` } var ( @@ -47,6 +51,8 @@ var ( allowedMembers map[string]bool ) +const pullsPrefix = "https://api.github.com/repos/matrix-org/matrix-doc/pulls" + func gitClone(url string) (string, error) { dst := path.Join("/tmp/matrix-doc", strconv.FormatInt(rand.Int63(), 10)) cmd := exec.Command("git", "clone", url, dst) @@ -68,7 +74,7 @@ func gitCheckout(path, sha string) error { } func lookupPullRequest(prNumber string) (PullRequest, error) { - resp, _ := http.Get("https://api.github.com/repos/matrix-org/matrix-doc/pulls/" + prNumber) + resp, _ := http.Get(fmt.Sprintf("%s/%s", pullsPrefix, prNumber)) defer resp.Body.Close() dec := json.NewDecoder(resp.Body) var pr PullRequest @@ -192,6 +198,32 @@ func serveRstDiff(w http.ResponseWriter, req *http.Request) { 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 := "" + io.WriteString(w, s) +} + func ignoreExitCodeOne(err error) error { if err == nil { return err @@ -221,6 +253,7 @@ func main() { http.HandleFunc("/spec/", serveSpec) http.HandleFunc("/diff/rst/", serveRstDiff) http.HandleFunc("/healthz", serveText("ok")) + http.HandleFunc("/", listPulls) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)) } From 20f0284155ed5d1a5cfe8146071f395559e93866 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Fri, 11 Sep 2015 14:40:52 +0100 Subject: [PATCH 3/6] speculator: Unified diff for rst diff --- scripts/speculator/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/speculator/main.go b/scripts/speculator/main.go index 3775ad86..d30c199c 100644 --- a/scripts/speculator/main.go +++ b/scripts/speculator/main.go @@ -182,7 +182,7 @@ func serveRstDiff(w http.ResponseWriter, req *http.Request) { 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 diffCmd.Stdout = &diff if err := ignoreExitCodeOne(diffCmd.Run()); err != nil { From b6dab0009d5533161dff92b1bdad3c664d3a5c6f Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Fri, 11 Sep 2015 14:43:26 +0100 Subject: [PATCH 4/6] speculator: Don't ignore errors --- scripts/speculator/main.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/speculator/main.go b/scripts/speculator/main.go index 3775ad86..1a474277 100644 --- a/scripts/speculator/main.go +++ b/scripts/speculator/main.go @@ -67,13 +67,18 @@ func gitCheckout(path, sha string) error { return nil } -func lookupPullRequest(prNumber string) (PullRequest, error) { - resp, _ := http.Get("https://api.github.com/repos/matrix-org/matrix-doc/pulls/" + prNumber) +func lookupPullRequest(prNumber string) (*PullRequest, error) { + resp, err := http.Get("https://api.github.com/repos/matrix-org/matrix-doc/pulls/" + prNumber) defer resp.Body.Close() + if err != nil { + return nil, fmt.Errorf("error getting pulls: %v", err) + } dec := json.NewDecoder(resp.Body) var pr PullRequest - _ = dec.Decode(&pr) - return pr, nil + if err := dec.Decode(&pr); err != nil { + return nil, fmt.Errorf("error decoding pulls: %v", err) + } + return &pr, nil } func generate(dir string) error { From d251f791fbfbe7af675f82689d51b63a79a361ff Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Fri, 11 Sep 2015 17:15:03 +0100 Subject: [PATCH 5/6] speculator: Document / --- scripts/speculator/README | 3 ++- scripts/speculator/main.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/speculator/README b/scripts/speculator/README index ae00c55a..6ab84f68 100644 --- a/scripts/speculator/README +++ b/scripts/speculator/README @@ -1,6 +1,7 @@ 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. - /diff/rst/123 which gives a diff of the spec's rst at pull request 123. diff --git a/scripts/speculator/main.go b/scripts/speculator/main.go index bcbe5514..32c015ac 100644 --- a/scripts/speculator/main.go +++ b/scripts/speculator/main.go @@ -1,5 +1,6 @@ // 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. // - /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. From b2477614658d6b4267ffcb1f35cfc9adb7f388ad Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Mon, 14 Sep 2015 10:33:25 +0100 Subject: [PATCH 6/6] .gitignore speculator --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e2250131..74b1c7d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ scripts/gen scripts/continuserv/continuserv +scripts/speculator/speculator templating/out *.pyc supporting-docs/_site