Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This will fail if there is a bad response from the
curl
command.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 tested and never got
null
inside the script, but I will replace the command with: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.
Do you want to use
jq
for the test, like this?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 current code will work for any
curl
response:curl
returns a valid JSON,jq
will try to find and returntag_name
.tag_name
is found in JSON response, an empty string will be returned.curl
responds with anything that is not a valid JSON,jq
command will return an empty string.Command details:
jq -sRr 'fromjson? | .tag_name | values'
-s
will read the entire input file into a large array before apply the filters;-R
will not parse the input as JSON. When combined with-s
, it reads the whole response into a single long string;?
is the error suppression operator and works like a simpletry/catch
.fromjson?
will try to parse the text into JSON format. If not possible will returnnull
..tag_name
will return the value of "tag_name" (ornull
if not found);values
will filter the result and return only "non null values" (returning an empty string in case ofnull
).-r
will output the result as plain text (without the quotes).