Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@littldr
Copy link

@littldr littldr commented Nov 2, 2018

@NARKOZ as mentioned in #401, here is a new MR with the updated code. :)

Unfortunately the Gitlab API does not allow an empty variables parameter, so it is necessary to add this if variables.any? check... Maybe you know a better way how to ensure that the variables parameter is only set when at least one variable is passed?

{ key: key, value: value }
end
body[:variables] = normalized_variables
end
Copy link
Owner

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 }
end

Copy link
Author

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?

Copy link
Author

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...

Copy link
Author

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?

Copy link
Owner

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

Copy link
Author

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

Copy link
Owner

@NARKOZ NARKOZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@NARKOZ NARKOZ merged commit 91afbd7 into NARKOZ:master Nov 2, 2018
@NARKOZ
Copy link
Owner

NARKOZ commented Nov 2, 2018

Thank you ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants