-
Notifications
You must be signed in to change notification settings - Fork 234
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 #405 from CircleCI-Public/pipeline-parameters
Send fabricated pipeline values when validating config
- Loading branch information
Showing
5 changed files
with
81 additions
and
20 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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package pipeline | ||
|
||
import "sort" | ||
|
||
// CircleCI provides various `<< pipeline.x >>` values to be used in your config, but sometimes we need to fabricate those values when validating config. | ||
type Values map[string]string | ||
|
||
|
||
func FabricatedValues() Values { | ||
return map[string]string{ | ||
"id": "00000000-0000-0000-0000-000000000001", | ||
"number": "1", | ||
// TODO: Could these be grabbed from git? | ||
"project.git_url": "https://test.vcs/test/test", | ||
"project.type": "vcs_type", | ||
"git.tag": "test_git_tag", | ||
"git.branch": "test_git_branch", | ||
"git.revision": "0123456789abcdef0123456789abcdef0123", | ||
"git.base_revision": "0123456789abcdef0123456789abcdef0123", | ||
} | ||
} | ||
|
||
// TODO: type Parameters map[string]string | ||
|
||
// KeyVal is a data structure specifically for passing pipeline data to GraphQL which doesn't support free-form maps. | ||
type KeyVal struct { | ||
Key string `json:"key"` | ||
Val string `json:"val"` | ||
} | ||
|
||
// PrepareForGraphQL takes a golang homogenous map, and transforms it into a list of keyval pairs, since GraphQL does not support homogenous maps. | ||
func PrepareForGraphQL(kvMap Values) []KeyVal { | ||
// we need to create the slice of KeyVals in a deterministic order for testing purposes | ||
keys := make([]string, 0, len(kvMap)) | ||
for k := range kvMap { | ||
keys = append(keys, k) | ||
} | ||
sort.Strings(keys) | ||
|
||
kvs := make([]KeyVal, 0, len(kvMap)) | ||
for _, k := range keys { | ||
kvs = append(kvs, KeyVal{Key: k, Val: kvMap[k]}) | ||
} | ||
return kvs | ||
} |