Skip to content

Commit

Permalink
Merge branch 'master' into #140-client-rework
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed May 17, 2018
2 parents 348f0fe + b49df9d commit 230f50c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
14 changes: 10 additions & 4 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,16 @@ func BuildTar(dir string, outputs ...io.Writer) error {
}

// ExtractRepository gets the project name from its URL in the form [username]/[project]
func ExtractRepository(URL string) string {
r, err := regexp.Compile(`.com(/|:)(\w+/\w+)`)
func ExtractRepository(URL string) (string, error) {
const defaultName = "$YOUR_REPOSITORY"
r, err := regexp.Compile(`.com(/|:)(.+/.+)`)
if err != nil {
return ""
return defaultName, err
}
return r.FindStringSubmatch(URL)[2]

remoteString := r.FindStringSubmatch(URL)
if len(remoteString) != 3 {
return defaultName, fmt.Errorf("Failed to extract repository name with remote url %s", URL)
}
return strings.Split(remoteString[2], ".git")[0], nil
}
20 changes: 19 additions & 1 deletion common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ func TestFlushRoutine(t *testing.T) {

func TestExtract(t *testing.T) {
for _, url := range remoteURLVariations {
assert.Equal(t, "ubclaunchpad/inertia", ExtractRepository(url))
repoName, err := ExtractRepository(url)
assert.Nil(t, err)
assert.Equal(t, "ubclaunchpad/inertia", repoName)
}

repoNameWithHyphens, err := ExtractRepository("[email protected]:ubclaunchpad/inertia-deploy-test.git")
assert.Nil(t, err)
assert.Equal(t, "ubclaunchpad/inertia-deploy-test", repoNameWithHyphens)

repoNameWithDots, err := ExtractRepository("[email protected]:ubclaunchpad/inertia.deploy.test.git")
assert.Nil(t, err)
assert.Equal(t, "ubclaunchpad/inertia.deploy.test", repoNameWithDots)

repoNameWithMixed, err := ExtractRepository("[email protected]:ubclaunchpad/inertia-deploy.test.git")
assert.Nil(t, err)
assert.Equal(t, "ubclaunchpad/inertia-deploy.test", repoNameWithMixed)

repoNameWithErr, err := ExtractRepository("asdfasda")
assert.NotNil(t, err)
assert.Equal(t, "$YOUR_REPOSITORY", repoNameWithErr)
}
5 changes: 4 additions & 1 deletion deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ for updates to this repository's remote master branch.`,
if err != nil {
log.Fatal(err)
}
repoName := common.ExtractRepository(common.GetSSHRemoteURL(origin.Config().URLs[0]))
repoName, err := common.ExtractRepository(common.GetSSHRemoteURL(origin.Config().URLs[0]))
if err != nil {
log.Println(err)
}

err = cli.BootstrapRemote(repoName)
if err != nil {
Expand Down

0 comments on commit 230f50c

Please sign in to comment.