-
-
Notifications
You must be signed in to change notification settings - Fork 400
Allow passing variables when creating a pipeline #428
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
Conversation
lib/gitlab/client/pipelines.rb
Outdated
| { key: key, value: value } | ||
| end | ||
| body[:variables] = normalized_variables | ||
| end |
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.
How about this?
body[:variables] = variables.each_with_object([]) do |(key, value), arr|
arr << { key: key, value: value }
endThere 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.
This sets body[:variables] to an empty array if no variables where passed. I've tested this with our gitlab instance (version > 11.3) and the api threw an 500 error (same error as described here https://gitlab.com/gitlab-org/gitlab-ce/issues/52926).
So I will reduce the unnecessary assignment in line 52, but i cannot omit the condition in line 46.
Do you prefer the each_with_object([]) or the map pattern to map the variables?
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.
It would work this way:
body[:variables] = variables.map do |(key, value)|
{ key: key, value: value }
end if variables.any?But I personally do not like the trailing condition in combination with multi-line statements...
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.
The whole statement in one-line looks reasonable:
body[:variables] = variables.map { |(key, value)| { key: key, value: value } } if variables.any?What do you think?
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.
What do you think?
lgtm
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've updated the PR! See 6a3f6e6
NARKOZ
left a comment
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.
👍
|
Thank you ❤️ |
@NARKOZ as mentioned in #401, here is a new MR with the updated code. :)
Unfortunately the Gitlab API does not allow an empty
variablesparameter, so it is necessary to add thisif variables.any?check... Maybe you know a better way how to ensure that thevariablesparameter is only set when at least one variable is passed?