-
Notifications
You must be signed in to change notification settings - Fork 237
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
Ext 283 remove legacy org slug #717
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -513,16 +513,14 @@ func WhoamiQuery(cl *graphql.Client) (*WhoamiResponse, error) { | |
return &response, nil | ||
} | ||
|
||
// ConfigQuery calls the GQL API to validate and process config | ||
func ConfigQuery(cl *graphql.Client, configPath string, orgSlug string, params pipeline.Parameters, values pipeline.Values) (*ConfigResponse, error) { | ||
// ConfigQueryLegacy calls the GQL API to validate and process config with the legacy orgSlug | ||
func ConfigQueryLegacy(cl *graphql.Client, configPath string, orgSlug string, params pipeline.Parameters, values pipeline.Values) (*ConfigResponse, error) { | ||
var response BuildConfigResponse | ||
var query string | ||
|
||
config, err := loadYaml(configPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// GraphQL isn't forwards-compatible, so we are unusually selective here about | ||
// passing only non-empty fields on to the API, to minimize user impact if the | ||
// backend is out of date. | ||
|
@@ -546,6 +544,7 @@ func ConfigQuery(cl *graphql.Client, configPath string, orgSlug string, params p | |
|
||
request := graphql.NewRequest(query) | ||
request.Var("config", config) | ||
|
||
if values != nil { | ||
request.Var("pipelineValues", pipeline.PrepareForGraphQL(values)) | ||
} | ||
|
@@ -556,17 +555,76 @@ func ConfigQuery(cl *graphql.Client, configPath string, orgSlug string, params p | |
} | ||
request.Var("pipelineParametersJson", string(pipelineParameters)) | ||
} | ||
|
||
if orgSlug != "" { | ||
request.Var("orgSlug", orgSlug) | ||
} | ||
|
||
request.SetToken(cl.Token) | ||
|
||
err = cl.Run(request, &response) | ||
|
||
if err != nil { | ||
return nil, errors.Wrap(err, "Unable to validate config") | ||
} | ||
if len(response.BuildConfig.ConfigResponse.Errors) > 0 { | ||
return nil, &response.BuildConfig.ConfigResponse.Errors | ||
} | ||
|
||
return &response.BuildConfig.ConfigResponse, nil | ||
} | ||
|
||
// ConfigQuery calls the GQL API to validate and process config with the org id | ||
func ConfigQuery(cl *graphql.Client, configPath string, orgId string, params pipeline.Parameters, values pipeline.Values) (*ConfigResponse, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick so optional, but I think we're capitalizing ID in the rest of the project, so orgID. |
||
var response BuildConfigResponse | ||
var query string | ||
config, err := loadYaml(configPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// GraphQL isn't forwards-compatible, so we are unusually selective here about | ||
// passing only non-empty fields on to the API, to minimize user impact if the | ||
// backend is out of date. | ||
var fieldAddendums string | ||
if orgId != "" { | ||
joeyorlando marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fieldAddendums += ", orgId: $orgId" | ||
} | ||
if len(params) > 0 { | ||
fieldAddendums += ", pipelineParametersJson: $pipelineParametersJson" | ||
} | ||
query = fmt.Sprintf( | ||
`query ValidateConfig ($config: String!, $pipelineParametersJson: String, $pipelineValues: [StringKeyVal!], $orgId: UUID!) { | ||
buildConfig(configYaml: $config, pipelineValues: $pipelineValues%s) { | ||
valid, | ||
errors { message }, | ||
sourceYaml, | ||
outputYaml | ||
} | ||
}`, | ||
fieldAddendums) | ||
|
||
request := graphql.NewRequest(query) | ||
request.Var("config", config) | ||
|
||
if values != nil { | ||
request.Var("pipelineValues", pipeline.PrepareForGraphQL(values)) | ||
} | ||
if params != nil { | ||
pipelineParameters, err := json.Marshal(params) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to serialize pipeline values: %s", err.Error()) | ||
} | ||
request.Var("pipelineParametersJson", string(pipelineParameters)) | ||
} | ||
|
||
if orgId != "" { | ||
request.Var("orgId", orgId) | ||
} | ||
request.SetToken(cl.Token) | ||
|
||
err = cl.Run(request, &response) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Unable to validate config") | ||
} | ||
if len(response.BuildConfig.ConfigResponse.Errors) > 0 { | ||
return nil, &response.BuildConfig.ConfigResponse.Errors | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ func newLocalExecuteCommand(config *settings.Config) *cobra.Command { | |
|
||
local.AddFlagsForDocumentation(buildCommand.Flags()) | ||
buildCommand.Flags().StringP("org-slug", "o", "", "organization slug (for example: github/example-org), used when a config depends on private orbs belonging to that org") | ||
buildCommand.Flags().String("org-id", "", "organization id, used when a config depends on private orbs belonging to that org") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick here but I'd argue keeping the wording the same (or extract to a variable even) for the three There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you give a full example? The wording is the same as far as I can see... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in processCommand.Flags().String("org-id", "", "organization id used when a config depends on private orbs belonging to that org")
validateCommand.Flags().String("org-id", "", "organization id used when a config depends on private orbs belonging to that org") in retrospect they're almost identical (just a comma that's different). Will leave it up to you if you think it's worth extracting to a variable. |
||
|
||
return buildCommand | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can simplify these two functions (ConfigQuery, and ConfigQueryLegacy) into one. Since this is graph, couldn't we just send everything that we've collected, like both the org slug and orgID? The API should already be handling this logic so there's no need to do it here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We tried that at first, remember? Graph did not like it when one of those fields wasn't sent. Keeping the methods separate will also allow us to remove the legacy code easier in the future. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? I just tried refactoring it locally and it worked just fine? Not a big deal though but I think less code is better than more code. Let me know if you want to spend the time to refactor it and I can help ya out :D