Skip to content

Instantly share code, notes, and snippets.

@nbari
Last active September 16, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbari/c98225144dcdd8c3c1466f6af733c73a to your computer and use it in GitHub Desktop.
Save nbari/c98225144dcdd8c3c1466f6af733c73a to your computer and use it in GitHub Desktop.
find git remotes
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"github.com/nbari/violetear"
)
type Repos struct {
Remotes []string
}
func findRemotes(w http.ResponseWriter, r *http.Request) {
files, _ := filepath.Glob("*")
repos := &Repos{}
for _, f := range files {
fi, err := os.Stat(f)
if err != nil {
fmt.Println(err)
continue
}
if fi.Mode().IsDir() {
out, err := exec.Command("git",
fmt.Sprintf("--git-dir=%s/.git", f),
"remote",
"get-url",
"--push",
"--all",
"origin").Output()
if err != nil {
log.Println(err)
continue
}
if len(out) > 0 {
repos.Remotes = append(repos.Remotes, strings.TrimSpace(fmt.Sprintf("%s", out)))
}
}
}
if err := json.NewEncoder(w).Encode(repos); err != nil {
log.Println(err)
}
}
func main() {
router := violetear.New()
router.HandleFunc("*", findRemotes)
log.Fatal(http.ListenAndServe(":8080", router))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment