|
|
@ -57,6 +57,7 @@ type User struct {
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
port = flag.Int("port", 9000, "Port on which to listen for HTTP")
|
|
|
|
port = flag.Int("port", 9000, "Port on which to listen for HTTP")
|
|
|
|
includesDir = flag.String("includes_dir", "", "Directory containing include files for styling like matrix.org")
|
|
|
|
includesDir = flag.String("includes_dir", "", "Directory containing include files for styling like matrix.org")
|
|
|
|
|
|
|
|
accessToken = flag.String("access_token", "", "github.com access token")
|
|
|
|
allowedMembers map[string]bool
|
|
|
|
allowedMembers map[string]bool
|
|
|
|
specCache *lru.Cache // string -> map[string][]byte filename -> contents
|
|
|
|
specCache *lru.Cache // string -> map[string][]byte filename -> contents
|
|
|
|
styledSpecCache *lru.Cache // string -> map[string][]byte filename -> contents
|
|
|
|
styledSpecCache *lru.Cache // string -> map[string][]byte filename -> contents
|
|
|
@ -74,6 +75,13 @@ const (
|
|
|
|
|
|
|
|
|
|
|
|
var numericRegex = regexp.MustCompile(`^\d+$`)
|
|
|
|
var numericRegex = regexp.MustCompile(`^\d+$`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func accessTokenQuerystring() string {
|
|
|
|
|
|
|
|
if *accessToken == "" {
|
|
|
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("?access_token=%s", *accessToken)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func gitClone(url string, shared bool) (string, error) {
|
|
|
|
func gitClone(url string, shared bool) (string, error) {
|
|
|
|
directory := path.Join("/tmp/matrix-doc", strconv.FormatInt(rand.Int63(), 10))
|
|
|
|
directory := path.Join("/tmp/matrix-doc", strconv.FormatInt(rand.Int63(), 10))
|
|
|
|
if err := os.MkdirAll(directory, permissionsOwnerFull); err != nil {
|
|
|
|
if err := os.MkdirAll(directory, permissionsOwnerFull); err != nil {
|
|
|
@ -105,7 +113,7 @@ func runGitCommand(path string, args []string) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func lookupPullRequest(prNumber string) (*PullRequest, error) {
|
|
|
|
func lookupPullRequest(prNumber string) (*PullRequest, error) {
|
|
|
|
resp, err := http.Get(fmt.Sprintf("%s/%s", pullsPrefix, prNumber))
|
|
|
|
resp, err := http.Get(fmt.Sprintf("%s/%s%s", pullsPrefix, prNumber, accessTokenQuerystring()))
|
|
|
|
defer resp.Body.Close()
|
|
|
|
defer resp.Body.Close()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error getting pulls: %v", err)
|
|
|
|
return nil, fmt.Errorf("error getting pulls: %v", err)
|
|
|
@ -513,7 +521,7 @@ func findHTMLDiffer() (string, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func getPulls() ([]PullRequest, error) {
|
|
|
|
func getPulls() ([]PullRequest, error) {
|
|
|
|
resp, err := http.Get(pullsPrefix)
|
|
|
|
resp, err := http.Get(fmt.Sprintf("%s%s", pullsPrefix, accessTokenQuerystring()))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -584,7 +592,7 @@ func (srv *server) makeIndex(w http.ResponseWriter, req *http.Request) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
branchNames = append(branchNames, "HEAD")
|
|
|
|
branchNames = append(branchNames, "HEAD")
|
|
|
|
for _, branch := range branchNames {
|
|
|
|
for _, branch := range branchNames {
|
|
|
|
href := "spec/"+url.QueryEscape(branch)+"/"
|
|
|
|
href := "spec/" + url.QueryEscape(branch) + "/"
|
|
|
|
s += fmt.Sprintf(`<li><a href="%s">%s</a></li>`, href, branch)
|
|
|
|
s += fmt.Sprintf(`<li><a href="%s">%s</a></li>`, href, branch)
|
|
|
|
if *includesDir != "" {
|
|
|
|
if *includesDir != "" {
|
|
|
|
s += fmt.Sprintf(`<li><a href="%s?matrixdotorgstyle=1">%s, styled like matrix.org</a></li>`,
|
|
|
|
s += fmt.Sprintf(`<li><a href="%s?matrixdotorgstyle=1">%s, styled like matrix.org</a></li>`,
|
|
|
@ -622,7 +630,7 @@ func main() {
|
|
|
|
"Kegsay": true,
|
|
|
|
"Kegsay": true,
|
|
|
|
"NegativeMjark": true,
|
|
|
|
"NegativeMjark": true,
|
|
|
|
"richvdh": true,
|
|
|
|
"richvdh": true,
|
|
|
|
"ara4n": true,
|
|
|
|
"ara4n": true,
|
|
|
|
"leonerd": true,
|
|
|
|
"leonerd": true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := initCache(); err != nil {
|
|
|
|
if err := initCache(); err != nil {
|
|
|
|