|
|
|
@ -82,11 +82,8 @@ func gitCheckout(path, sha string) error {
|
|
|
|
|
return runGitCommand(path, []string{"checkout", sha})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func gitFetchAndMerge(path string) error {
|
|
|
|
|
if err := runGitCommand(path, []string{"fetch"}); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return runGitCommand(path, []string{"merge", "origin/master"})
|
|
|
|
|
func gitFetch(path string) error {
|
|
|
|
|
return runGitCommand(path, []string{"fetch"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runGitCommand(path string, args []string) error {
|
|
|
|
@ -145,7 +142,7 @@ type server struct {
|
|
|
|
|
// generateAt generates spec from repo at sha.
|
|
|
|
|
// Returns the path where the generation was done.
|
|
|
|
|
func (s *server) generateAt(sha string) (dst string, err error) {
|
|
|
|
|
err = gitFetchAndMerge(s.matrixDocCloneURL)
|
|
|
|
|
err = gitFetch(s.matrixDocCloneURL)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -162,11 +159,27 @@ func (s *server) generateAt(sha string) (dst string, err error) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *server) getSHAOf(ref string) (string, error) {
|
|
|
|
|
cmd := exec.Command("git", "rev-list", ref, "-n1")
|
|
|
|
|
cmd.Dir = path.Join(s.matrixDocCloneURL)
|
|
|
|
|
var b bytes.Buffer
|
|
|
|
|
cmd.Stdout = &b
|
|
|
|
|
err := cmd.Run()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("error generating spec: %v\nOutput from gendoc:\n%v", err, b.String())
|
|
|
|
|
}
|
|
|
|
|
return strings.TrimSpace(b.String()), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *server) serveSpec(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|
var sha string
|
|
|
|
|
|
|
|
|
|
if strings.ToLower(req.URL.Path) == "/spec/head" {
|
|
|
|
|
sha = "HEAD"
|
|
|
|
|
originHead, err := s.getSHAOf("origin/master")
|
|
|
|
|
if err != nil {
|
|
|
|
|
writeError(w, 500, err)
|
|
|
|
|
}
|
|
|
|
|
sha = originHead
|
|
|
|
|
} else {
|
|
|
|
|
pr, err := lookupPullRequest(*req.URL, "/spec")
|
|
|
|
|
if err != nil {
|
|
|
|
|