-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgit.go
More file actions
31 lines (27 loc) · 671 Bytes
/
Copy pathgit.go
File metadata and controls
31 lines (27 loc) · 671 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package github
import (
"errors"
"os/exec"
"regexp"
"strings"
)
var repoRE *regexp.Regexp
func init() {
var err error
repoRE, err = regexp.Compile("github\\.com/([^/]+)/([^/]+?)(?:\\.git)?$")
if err != nil {
panic(err)
}
}
func GetUserAndRepo() (string, string, error) {
data, err := exec.Command("git", "config", "remote.origin.url").Output()
if err != nil {
return "", "", errors.New("'git config remote.origin.url' failed")
}
url := strings.TrimSpace(string(data))
matches := repoRE.FindStringSubmatch(url)
if matches == nil {
return "", "", errors.New("Could not understand remote origin url: " + url)
}
return matches[1], matches[2], nil
}