Merge pull request #81 from matrix-org/daniel/speculatormerge

speculator: Merge after fetching, so that /spec/head works
pull/977/head
Daniel Wagner-Hall 9 years ago
commit 7df3d9090a

@ -60,11 +60,10 @@ func (u *User) IsTrusted() bool {
} }
const ( const (
pullsPrefix = "https://api.github.com/repos/matrix-org/matrix-doc/pulls" pullsPrefix = "https://api.github.com/repos/matrix-org/matrix-doc/pulls"
matrixDocCloneURL = "https://github.com/matrix-org/matrix-doc.git" matrixDocCloneURL = "https://github.com/matrix-org/matrix-doc.git"
) )
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))
cmd := exec.Command("git", "clone", url, directory) cmd := exec.Command("git", "clone", url, directory)
@ -80,21 +79,22 @@ func gitClone(url string, shared bool) (string, error) {
} }
func gitCheckout(path, sha string) error { func gitCheckout(path, sha string) error {
cmd := exec.Command("git", "checkout", sha) return runGitCommand(path, []string{"checkout", sha})
cmd.Dir = path }
err := cmd.Run()
if err != nil { func gitFetchAndMerge(path string) error {
return fmt.Errorf("error checking out repo: %v", err) if err := runGitCommand(path, []string{"fetch"}); err != nil {
return err
} }
return nil return runGitCommand(path, []string{"merge"})
} }
func gitFetch(path string) error { func runGitCommand(path string, args []string) error {
cmd := exec.Command("git", "fetch") cmd := exec.Command("git", args...)
cmd.Dir = path cmd.Dir = path
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
return fmt.Errorf("error fetching repo: %v", err) return fmt.Errorf("error running %q: %v", strings.Join(cmd.Args, " "), err)
} }
return nil return nil
} }
@ -145,7 +145,7 @@ type server struct {
// generateAt generates spec from repo at sha. // generateAt generates spec from repo at sha.
// Returns the path where the generation was done. // Returns the path where the generation was done.
func (s *server) generateAt(sha string) (dst string, err error) { func (s *server) generateAt(sha string) (dst string, err error) {
err = gitFetch(s.matrixDocCloneURL) err = gitFetchAndMerge(s.matrixDocCloneURL)
if err != nil { if err != nil {
return return
} }

Loading…
Cancel
Save