-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from screwdriver-cd/https
Use https as default url for git clone operation
- Loading branch information
Showing
4 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,14 +25,19 @@ type scmPath struct { | |
var mkdirAll = os.MkdirAll | ||
var stat = os.Stat | ||
var gitClone = git.Clone | ||
var gitSetConfig = git.SetConfig | ||
|
||
func (s scmPath) String() string { | ||
return fmt.Sprintf("%s:%s/%s#%s", s.Host, s.Org, s.Repo, s.Branch) | ||
return fmt.Sprintf("git@%s:%s/%s#%s", s.Host, s.Org, s.Repo, s.Branch) | ||
} | ||
|
||
func (s scmPath) httpsString() string { | ||
return fmt.Sprintf("https://%s/%s/%s#%s", s.Host, s.Org, s.Repo, s.Branch) | ||
} | ||
|
||
// e.g. "[email protected]:screwdriver-cd/launch.git#master" | ||
func parseScmURL(url string) (scmPath, error) { | ||
r := regexp.MustCompile("(.*):(.*)/(.*)#(.*)") | ||
r := regexp.MustCompile("git@(.*):(.*)/(.*)#(.*)") | ||
matched := r.FindAllStringSubmatch(url, -1) | ||
if matched == nil || len(matched) != 1 || len(matched[0]) != 5 { | ||
return scmPath{}, fmt.Errorf("Unable to parse SCM URL %v, match: %q", url, matched) | ||
|
@@ -114,10 +119,21 @@ func launch(api screwdriver.API, buildID string, rootDir string) error { | |
return err | ||
} | ||
|
||
err = gitClone(p.ScmURL, w.Src) | ||
err = gitClone(scm.httpsString(), w.Src) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = gitSetConfig("user.name", "sd-buildbot") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = gitSetConfig("user.email", "[email protected]") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ func (f MockAPI) PipelineFromID(pipelineID string) (screwdriver.Pipeline, error) | |
func TestMain(m *testing.M) { | ||
mkdirAll = func(path string, perm os.FileMode) (err error) { return nil } | ||
stat = func(path string) (info os.FileInfo, err error) { return nil, os.ErrExist } | ||
gitSetConfig = func(setting, name string) error { return nil } | ||
os.Exit(m.Run()) | ||
} | ||
|
||
|
@@ -142,7 +143,7 @@ func TestPipelineFromIdError(t *testing.T) { | |
} | ||
|
||
func TestParseScmURL(t *testing.T) { | ||
wantHost := "git@github.com" | ||
wantHost := "github.com" | ||
wantOrg := "screwdriver-cd" | ||
wantRepo := "launcher.git" | ||
wantBranch := "master" | ||
|
@@ -219,17 +220,43 @@ func TestCreateWorkspace(t *testing.T) { | |
func TestClone(t *testing.T) { | ||
testBuildID := "BUILDID" | ||
testJobID := "JOBID" | ||
testSCMURL := "[email protected]:screwdriver-cd/launcher#master" | ||
testSCMURL := "[email protected]:screwdriver-cd/launcher.git#master" | ||
testHttps := "https://github.com/screwdriver-cd/launcher.git#master" | ||
testRoot := "/sd/workspace" | ||
api := mockAPI(t, testBuildID, testJobID, "") | ||
api.pipelineFromID = func(pipelineID string) (screwdriver.Pipeline, error) { | ||
return screwdriver.Pipeline(FakePipeline{ScmURL: testSCMURL}), nil | ||
} | ||
gitClone = func(repo, dest string) error { | ||
if repo != testSCMURL { | ||
t.Errorf("Git clone was called with repo %q, want %q", repo, testSCMURL) | ||
if repo != testHttps { | ||
t.Errorf("Git clone was called with repo %q, want %q", repo, testHttps) | ||
} | ||
return nil | ||
} | ||
launch(screwdriver.API(api), testBuildID, testRoot) | ||
} | ||
|
||
func TestHttpsString(t *testing.T) { | ||
testScmPath := scmPath{ | ||
Host: "github.com", | ||
Org: "screwdriver-cd", | ||
Repo: "launcher.git", | ||
Branch: "master", | ||
} | ||
|
||
wantHttpsString := "https://github.com/screwdriver-cd/launcher.git#master" | ||
|
||
httpsString := testScmPath.httpsString() | ||
|
||
if httpsString != wantHttpsString { | ||
t.Errorf("httpsString == %q, want %q", httpsString, wantHttpsString) | ||
} | ||
} | ||
|
||
func TestSetUserNameAndEmail(t *testing.T) { | ||
testBuildID := "BUILDID" | ||
testRoot := "/sd/workspace" | ||
api := mockAPI(t, testBuildID, "", "") | ||
|
||
launch(screwdriver.API(api), testBuildID, testRoot) | ||
} |