speculator: Allow access token to be specified

pull/977/head
Daniel Wagner-Hall 9 years ago
parent 5d2eae58bd
commit 072d285153

@ -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
} }

Loading…
Cancel
Save