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 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. 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 3775ad86..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. @@ -24,9 +25,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 +43,8 @@ type RequestRepo struct { } type User struct { - Login string + Login string + HTMLURL string `json:"html_url"` } var ( @@ -47,6 +52,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) @@ -67,13 +74,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(fmt.Sprintf("%s/%s", pullsPrefix, 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 { @@ -182,7 +194,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 { @@ -192,6 +204,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 +259,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)) }