grim/convey

Parents d5308b3397a8
Children 5abe317f3969
Add support for parsing the options block in bitbucket-pipelines.yml and fix some other broken tests. Refs #92
--- a/bitbucket/loader.go Tue May 02 21:49:17 2017 -0500
+++ b/bitbucket/loader.go Tue May 02 22:25:33 2017 -0500
@@ -24,7 +24,7 @@
"bitbucket.org/rw_grim/convey/config"
"bitbucket.org/rw_grim/convey/docker"
- "bitbucket.org/rw_grim/convey/options"
+ conveyOptions "bitbucket.org/rw_grim/convey/options"
"bitbucket.org/rw_grim/convey/plans"
"bitbucket.org/rw_grim/convey/stages"
"bitbucket.org/rw_grim/convey/tasks"
@@ -123,7 +123,7 @@
return "default"
}
-func (l *Loader) ResolvePlanName(plan string, cfg *config.Config, opts *options.Options) string {
+func (l *Loader) ResolvePlanName(plan string, cfg *config.Config, opts *conveyOptions.Options) string {
if plan != "" {
// try to shortcut if we can
if plan == "default" {
--- a/bitbucket/types.go Tue May 02 21:49:17 2017 -0500
+++ b/bitbucket/types.go Tue May 02 22:25:33 2017 -0500
@@ -46,16 +46,25 @@
Services map[string]service `yaml:"services"`
}
+type options struct {
+ Docker bool `yaml:"docker"`
+}
+
+type clone struct {
+ Depth int `yaml:"depth"`
+}
+
type bitbucketPipelines struct {
Image string `yaml:"image"`
- Clone int `yaml:"clone"`
+ Clone clone `yaml:"clone"`
Pipelines pipelines `yaml:"pipelines"`
Definitions definition `yaml:"definitions"`
+ Options options `yaml:"options"`
}
func (b *bitbucketPipelines) UnmarshalYAML(unmarshal func(interface{}) error) error {
type rawBitbucketPipelines bitbucketPipelines
- raw := rawBitbucketPipelines{Clone: 50}
+ raw := rawBitbucketPipelines{Clone: clone{}}
if err := unmarshal(&raw); err != nil {
return err
@@ -65,3 +74,16 @@
return nil
}
+
+func (c *clone) UnmarshalYAML(unmarshal func(interface{}) error) error {
+ type rawClone clone
+ raw := rawClone{Depth: 50}
+
+ if err := unmarshal(&raw); err != nil {
+ return err
+ }
+
+ *c = clone(raw)
+
+ return nil
+}
--- a/bitbucket/unmarshal_test.go Tue May 02 21:49:17 2017 -0500
+++ b/bitbucket/unmarshal_test.go Tue May 02 22:25:33 2017 -0500
@@ -125,3 +125,41 @@
}
Expect(actual).To(Equal(expected))
}
+
+func (b *bitbucketSuite) TestUnmarshalWithDocker(t *testing.T) {
+ yamlData := `pipelines:
+ default:
+ - step:
+ script:
+ - docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
+ - docker build -t atlassian/my-app:$BITBUCKET_COMMIT .
+ - docker push atlassian/my-app:$BITBUCKET_COMMIT
+options:
+ docker: true
+`
+
+ var actual bitbucketPipelines
+ err := yaml.Unmarshal([]byte(yamlData), &actual)
+
+ Expect(err).To(BeNil())
+
+ expected := bitbucketPipelines{
+ Pipelines: pipelines{
+ Default: []pipeline{
+ pipeline{
+ Steps: step{
+ Script: []string{
+ "docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD",
+ "docker build -t atlassian/my-app:$BITBUCKET_COMMIT .",
+ "docker push atlassian/my-app:$BITBUCKET_COMMIT",
+ },
+ },
+ },
+ },
+ },
+ Options: options{
+ Docker: true,
+ },
+ }
+ Expect(actual).To(Equal(expected))
+}