Skip to content

Commit

Permalink
Merge pull request #206 from CircleCI-Public/stop-the-corruption
Browse files Browse the repository at this point in the history
[CIRCLE-14589] Allow an OrbElement to be a string pointer
  • Loading branch information
Zachary Scott authored Nov 23, 2018
2 parents 7a1de1a + c696c41 commit 7e90e68
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
28 changes: 26 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,37 @@ type OrbElementParameter struct {
Default interface{} `json:"-"`
}

// OrbElement represents the yaml-unmarshled contents of
// RealOrbElement represents the yaml-unmarshled contents of
// a named element under a command/job/executor
type OrbElement struct {
type RealOrbElement struct {
Description string `json:"-"`
Parameters map[string]OrbElementParameter `json:"-"`
}

// OrbElement implements RealOrbElement interface and allows us to deserialize by hand.
type OrbElement RealOrbElement

// UnmarshalYAML method allows OrbElement to be a string or a map.
// For now, don't even try to dereference the string, just return what is essentially
// an empty OrbElement (no description or parameters)
func (orbElement *OrbElement) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
err := unmarshal(&s)
if err == nil {
*orbElement = OrbElement{}
return nil
}

var oe RealOrbElement
err = unmarshal(&oe)
if err == nil {
*orbElement = OrbElement(oe)

return nil
}
return nil
}

// Orb is a struct for containing the yaml-unmarshaled contents of an orb
type Orb struct {
ID string
Expand Down
6 changes: 3 additions & 3 deletions cmd/orb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1262,9 +1262,9 @@ var _ = Describe("Orb integration tests", func() {
Eventually(session.Out).Should(gbytes.Say("Orbs found: 1. Showing only certified orbs. Add -u for a list of all orbs."))
Eventually(session.Out).Should(gbytes.Say("foo/test \\(0.7.0\\)"))
Eventually(session.Out).Should(gbytes.Say("Commands:"))
Eventually(session.Out).Should(gbytes.Say("- echo: 2 parameter\\(s\\)"))
Eventually(session.Out).Should(gbytes.Say("- message: string"))
Eventually(session.Out).Should(gbytes.Say("- post-steps: steps"))
Eventually(session.Out).Should(gbytes.Say("- myfoo: 0 parameter\\(s\\)"))
Eventually(session.Out).Should(gbytes.Say("- bar: 1 parameter\\(s\\)"))
Eventually(session.Out).Should(gbytes.Say("- hello: string \\(default: 'world'\\)"))
Eventually(session.Out).Should(gbytes.Say("Jobs:"))
Eventually(session.Out).Should(gbytes.Say("- hello-build: 0 parameter\\(s\\)"))
Eventually(session.Out).Should(gbytes.Say("Executors:"))
Expand Down
2 changes: 1 addition & 1 deletion cmd/testdata/gql_orb_list_details/pretty_json_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"versions": [
{
"version": "0.7.0",
"source": "version: 2.1\ndescription: An orb with some simple ways to help you with your first build.\n\ncommands:\n echo:\n parameters:\n message:\n type: string\n post-steps:\n type: steps\n default: []\n steps:\n - run: echo \u003c\u003c parameters.message \u003e\u003e\n\nexecutors:\n default:\n parameters:\n tag:\n type: string\n default: \"curl-browsers\"\n docker:\n - image: circleci/buildpack-deps:\u003c\u003c parameters.tag \u003e\u003e\n\njobs:\n hello-build:\n executor: default\n steps:\n - echo:\n message: \"Hello, build!\"\n"
"source": "version: 2.1\norbs:\n foo:\n commands:\n foo:\n steps:\n - checkout\ncommands:\n myfoo: foo/foo\n bar:\n parameters:\n hello:\n type: string\n default: world\n steps:\n - echo \u003c\u003cparameters.hello\u003e\u003e\n\nexecutors:\n default:\n parameters:\n tag:\n type: string\n default: \"curl-browsers\"\n docker:\n - image: circleci/buildpack-deps:\u003c\u003c parameters.tag \u003e\u003e\n\njobs:\n hello-build:\n executor: default\n steps:\n - echo:\n message: \"Hello, build!\"\n"
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/testdata/gql_orb_list_details/response.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"name": "foo/test",
"versions": [
{
"source": "version: 2.1\ndescription: An orb with some simple ways to help you with your first build.\n\ncommands:\n echo:\n parameters:\n message:\n type: string\n post-steps:\n type: steps\n default: []\n steps:\n - run: echo << parameters.message >>\n\nexecutors:\n default:\n parameters:\n tag:\n type: string\n default: \"curl-browsers\"\n docker:\n - image: circleci/buildpack-deps:<< parameters.tag >>\n\njobs:\n hello-build:\n executor: default\n steps:\n - echo:\n message: \"Hello, build!\"\n",
"version": "0.7.0"
"source": "version: 2.1\norbs:\n foo:\n commands:\n foo:\n steps:\n - checkout\ncommands:\n myfoo: foo/foo\n bar:\n parameters:\n hello:\n type: string\n default: world\n steps:\n - echo <<parameters.hello>>\n\nexecutors:\n default:\n parameters:\n tag:\n type: string\n default: \"curl-browsers\"\n docker:\n - image: circleci/buildpack-deps:<< parameters.tag >>\n\njobs:\n hello-build:\n executor: default\n steps:\n - echo:\n message: \"Hello, build!\"\n",
"version": "0.7.0"
}
]
}
Expand Down

0 comments on commit 7e90e68

Please sign in to comment.