Last active
September 16, 2017 11:51
-
-
Save nbari/c98225144dcdd8c3c1466f6af733c73a to your computer and use it in GitHub Desktop.
find git remotes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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