Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #849

Merged
merged 5 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ jobs:
brew-deploy:
executor: mac
environment:
- USER: circleci
- TRAVIS: circleci
- DESTDIR: /Users/distiller/dest
USER: circleci
TRAVIS: circleci
DESTDIR: /Users/distiller/dest
steps:
- checkout
- force-http-1
Expand Down Expand Up @@ -335,6 +335,8 @@ workflows:
- brew-deploy:
requires:
- run-brew-deploy-gate
context:
- devex-release
- deploy:
requires:
- test
Expand All @@ -346,3 +348,5 @@ workflows:
filters:
branches:
only: main
context:
- devex-release
33 changes: 28 additions & 5 deletions cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -390,6 +391,22 @@ func orbHelpLong(config *settings.Config) string {
See a full explanation and documentation on orbs here: %s`, config.Data.Links.OrbDocs)
}

// Transform a boolean parameter into a string. Because the value can be a boolean but can also be
// a string, we need to first parse it as a boolean and then if it is not a boolean, parse it as
// a string
//
// Documentation reference: https://circleci.com/docs/reusing-config/#boolean
func booleanParameterDefaultToString(parameter api.OrbElementParameter) string {
if v, ok := parameter.Default.(bool); ok {
return fmt.Sprintf("%t", v)
}
v, ok := parameter.Default.(string)
if !ok {
log.Panicf("Unable to parse boolean parameter with value %+v", v)
}
return v
}

func parameterDefaultToString(parameter api.OrbElementParameter) string {
defaultValue := " (default: '"

Expand All @@ -401,12 +418,18 @@ func parameterDefaultToString(parameter api.OrbElementParameter) string {
}

switch parameter.Type {
case "enum":
defaultValue += parameter.Default.(string)
case "string":
defaultValue += parameter.Default.(string)
case "enum", "string":
if v, ok := parameter.Default.(string); ok {
defaultValue += v
break
}
if v, ok := parameter.Default.(fmt.Stringer); ok {
defaultValue += v.String()
break
}
log.Panicf("Unable to parse parameter default with value %+v because it's neither a string nor a stringer", parameter.Default)
case "boolean":
defaultValue += fmt.Sprintf("%t", parameter.Default.(bool))
defaultValue += booleanParameterDefaultToString(parameter)
default:
defaultValue += ""
}
Expand Down
66 changes: 66 additions & 0 deletions cmd/orb_unit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package cmd

import (
"time"

"github.com/CircleCI-Public/circleci-cli/api"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)

var _ = Describe("Orb unit tests", func() {
Describe("Orb formatters", func() {
DescribeTable(
"parameterDefaultToString",
func(input api.OrbElementParameter, expected string) {
Expect(parameterDefaultToString(input)).To(Equal(expected))
},
Entry(
"Normal behaviour for string",
api.OrbElementParameter{
Type: "string",
Description: "",
Default: "Normal behavior",
},
" (default: 'Normal behavior')",
),
Entry(
"Normal behaviour for enum",
api.OrbElementParameter{
Type: "enum",
Description: "",
Default: "Normal behavior",
},
" (default: 'Normal behavior')",
),
Entry(
"Normal behaviour for boolean",
api.OrbElementParameter{
Type: "boolean",
Description: "",
Default: true,
},
" (default: 'true')",
),
Entry(
"String value for boolean",
api.OrbElementParameter{
Type: "boolean",
Description: "",
Default: "yes",
},
" (default: 'yes')",
),
Entry(
"Time value for string",
api.OrbElementParameter{
Type: "string",
Description: "",
Default: time.Date(2023, 02, 20, 11, 9, 0, 0, time.Now().UTC().Location()),
},
" (default: '2023-02-20 11:09:00 +0000 UTC')",
),
)
})
})