Merge branch 'master' into daniel/threepidinvites-2
This commit is contained in:
commit
b916823d0f
4 changed files with 62 additions and 16 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
|||
scripts/gen
|
||||
scripts/continuserv/continuserv
|
||||
scripts/speculator/speculator
|
||||
templating/out
|
||||
*.pyc
|
||||
supporting-docs/_site
|
||||
|
|
|
@ -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.
|
||||
description: The event was not found or you do not have permission to read this event.
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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 := "<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 {
|
||||
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))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue