Skip to content
This repository has been archived by the owner on May 29, 2018. It is now read-only.

Commit

Permalink
Merge pull request #4 from ewoutp/gogs-url-fix
Browse files Browse the repository at this point in the history
Gogs url fix
  • Loading branch information
sqs committed Nov 14, 2016
2 parents 1e4dda7 + c3c0adc commit 2305ecc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions vcsurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ func (r *RepoInfo) Link() string {
}
}

var removeDotGit = regexp.MustCompile(`\.git$`)
var (
removeDotGit = regexp.MustCompile(`\.git$`)
gitPreprocessRE = regexp.MustCompile("^git@([a-zA-Z0-9-_\\.]+)\\:(.*)$")
)

// Parses a string that resembles a VCS repository URL. See TestParse for a list of supported URL
// formats.
func Parse(spec string) (info *RepoInfo, err error) {
if strings.HasPrefix(spec, "git@github.com:") {
spec = strings.Replace(spec, "git@github.com:", "git://github.com/", 1)
if parts := gitPreprocessRE.FindStringSubmatch(spec); len(parts) == 3 {
spec = fmt.Sprintf("git://%s/%s", parts[1], parts[2])
}

var parsedURL *url.URL
Expand Down
10 changes: 9 additions & 1 deletion vcsurl_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package vcsurl

import (
"github.com/kr/pretty"
"testing"

"github.com/kr/pretty"
)

var (
Expand Down Expand Up @@ -118,6 +119,13 @@ func TestParse(t *testing.T) {
Name: "foo",
FullName: "git/foo",
}},
{"git@git.private.com:org/repo.git", "git.private.com/org/repo", RepoInfo{
CloneURL: "git://git.private.com/org/repo.git",
VCS: Git,
RepoHost: "git.private.com",
Name: "repo",
FullName: "org/repo",
}},
}

for _, test := range tests {
Expand Down

0 comments on commit 2305ecc

Please sign in to comment.