Skip to content

Commit

Permalink
add clone options
Browse files Browse the repository at this point in the history
  • Loading branch information
camandel committed Sep 25, 2019
1 parent bfe476c commit 4813573
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 7 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ type BaseStep struct {
}

type CloneStep struct {
BaseStep `json:",inline"`
BaseStep `json:",inline"`
Depth *int `json:"depth"`
RecurseSubmodules bool `json:"recurse_submodules"`
}

type RunStep struct {
Expand Down Expand Up @@ -793,6 +795,10 @@ func checkConfig(config *Config) error {
// TODO(sgotti) we could use the run step command as step name but when the
// command is very long or multi line it doesn't makes sense and will
// probably be quite unuseful/confusing from an UI point of view
case *CloneStep:
if step.Depth != nil && *step.Depth < 1 {
return errors.Errorf("depth value must be greater than 0 for clone step in task %q", task.Name)
}
case *RunStep:
if step.Command == "" {
return errors.Errorf("no command defined for step %d (run) in task %q", i, task.Name)
Expand Down
18 changes: 14 additions & 4 deletions internal/runconfig/runconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ func stepFromConfigStep(csi interface{}, variables map[string]string) interface{
case *config.CloneStep:
// transform a "clone" step in a "run" step command
rs := &config.RunStep{}

rs.Type = "run"
rs.Name = "Clone repository and checkout code"
rs.Command = `
rs.Command = fmt.Sprintf(`
set -x
mkdir ~/.ssh
Expand Down Expand Up @@ -96,15 +95,15 @@ Host $AGOLA_GIT_HOST
EOF
)
git clone $AGOLA_REPOSITORY_URL .
git clone %s $AGOLA_REPOSITORY_URL .
git fetch origin $AGOLA_GIT_REF
if [ -n "$AGOLA_GIT_COMMITSHA" ]; then
git checkout $AGOLA_GIT_COMMITSHA
else
git checkout FETCH_HEAD
fi
`
`, genCloneOptions(cs))

return rs

Expand Down Expand Up @@ -444,3 +443,14 @@ func genValue(val config.Value, variables map[string]string) string {
panic(fmt.Errorf("wrong value type: %q", val.Value))
}
}

func genCloneOptions(c *config.CloneStep) string {
cloneoptions := []string{}
if c.Depth != nil {
cloneoptions = append(cloneoptions, fmt.Sprintf("--depth %d", *c.Depth))
}
if c.RecurseSubmodules {
cloneoptions = append(cloneoptions, "--recurse-submodules")
}
return strings.Join(cloneoptions, " ")
}

0 comments on commit 4813573

Please sign in to comment.