Skip to content

Commit

Permalink
Added support for launchpad Bzr and Git hosting.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfarina committed Aug 4, 2015
1 parent d5b90c1 commit b64bd00
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
14 changes: 11 additions & 3 deletions vcs_remote_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ var vcsList = []*vcsInfo{
pattern: `^(bitbucket\.org/(?P<name>[A-Za-z0-9_.\-]+/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`,
addCheck: checkBitbucket,
},
{
host: "launchpad.net",
pattern: `^(launchpad\.net/(([A-Za-z0-9_.\-]+)(/[A-Za-z0-9_.\-]+)?|~[A-Za-z0-9_.\-]+/(\+junk|[A-Za-z0-9_.\-]+)/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`,
vcs: BzrType,
},
{
host: "git.launchpad.net",
vcs: GitType,
pattern: `^(git\.launchpad\.net/(([A-Za-z0-9_.\-]+)|~[A-Za-z0-9_.\-]+/(\+git|[A-Za-z0-9_.\-]+)/[A-Za-z0-9_.\-]+))$`,
},
}

func init() {
Expand Down Expand Up @@ -119,10 +129,8 @@ func checkBitbucket(i map[string]string) (VcsType, error) {

}

var client = http.DefaultClient

func get(url string) ([]byte, error) {
resp, err := client.Get(url)
resp, err := http.Get(url)
if err != nil {
return nil, err
}
Expand Down
28 changes: 20 additions & 8 deletions vcs_remote_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,36 @@ import (

func TestVCSLookup(t *testing.T) {
// TODO: Expand to make sure it detected the right vcs.
urlList := map[string]bool{
"https://github.com/masterminds": false,
"https://github.com/Masterminds/VCSTestRepo": true,
"https://bitbucket.org/mattfarina/testhgrepo": true,
urlList := map[string]struct {
work bool
t VcsType
}{
"https://github.com/masterminds": {work: false, t: GitType},
"https://github.com/Masterminds/VCSTestRepo": {work: true, t: GitType},
"https://bitbucket.org/mattfarina/testhgrepo": {work: true, t: HgType},
"https://launchpad.net/govcstestbzrrepo/trunk": {work: true, t: BzrType},
"https://launchpad.net/~mattfarina/+junk/mygovcstestbzrrepo": {work: true, t: BzrType},
"https://launchpad.net/~mattfarina/+junk/mygovcstestbzrrepo/trunk": {work: true, t: BzrType},
"https://git.launchpad.net/govcstestgitrepo": {work: true, t: GitType},
"https://git.launchpad.net/~mattfarina/+git/mygovcstestgitrepo": {work: true, t: GitType},
}

for u, c := range urlList {
_, err := detectVcsFromUrl(u)
if err == nil && c == false {
ty, err := detectVcsFromUrl(u)
if err == nil && c.work == false {
t.Errorf("Error detecting VCS from URL(%s)", u)
}

if err == ErrCannotDetectVCS && c == true {
if err == ErrCannotDetectVCS && c.work == true {
t.Errorf("Error detecting VCS from URL(%s)", u)
}

if err != nil && c == true {
if err != nil && c.work == true {
t.Errorf("Error detecting VCS from URL(%s): %s", u, err)
}

if c.work == true && ty != c.t {
t.Errorf("Incorrect VCS type returned(%s)", u)
}
}
}

0 comments on commit b64bd00

Please sign in to comment.