提交 84743b5e 编写于 作者: J Jingwen Owen Ou

Introduce GitHubProject

上级 bc096990
......@@ -5,6 +5,27 @@ import (
"regexp"
)
type GitHubProject struct {
Name string
Owner string
}
func CurrentProject() *GitHubProject {
owner, name := parseOwnerAndName()
return &GitHubProject{name, owner}
}
func parseOwnerAndName() (name, remote string) {
remote, err := git.Remote()
check(err)
url, err := mustMatchGitUrl(remote)
check(err)
return url[1], url[2]
}
func mustMatchGitUrl(url string) ([]string, error) {
httpRegex := regexp.MustCompile("https://.+/(.+)/(.+).git")
if httpRegex.MatchString(url) {
......
......@@ -5,6 +5,12 @@ import (
"testing"
)
func TestParseNameAndOwner(t *testing.T) {
owner, name := parseOwnerAndName()
assert.Equal(t, "gh", name)
assert.Equal(t, "jingweno", owner)
}
func TestMustMatchGitUrl(t *testing.T) {
url, _ := mustMatchGitUrl("git://github.com/jingweno/gh.git")
assert.Equal(t, "git://github.com/jingweno/gh.git", url[0])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册