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

Skip to content

Conversation

@SimplyAName
Copy link

I have not contributed here before, so please let me know if there's anything I need to do/fix.
I've done my best to match existing styling and have included some unit tests for my change.

TLDR:

  • Improved JSON parsing for GitVersion output
  • Add new unit tests for the above change
  • Added debug messages
  • Updated README with basic instructions on how to get set up

This PR is mainly to fix #1711. I've been running into the same issue on my own pipelines and have tracked down the root cause to output parsing in the tasks.

The error occurs when a '{' character exists anywhere in the GitVersion output object, such as in a branch name. This caused the old parsing function to get an invalid JSON object, as the last '{' didn't belong to the JSON object, just the property string.

To fix this, I've added a function that will start with the old search (last '{' and '}') but then expand to the next '{' character and check if the JSON object is valid again. This continues till a valid object is found or sets the task to failed if it is unable to find one.

I've also included a new section on getting set up with this project in the README. I faced some issues setting it up for the first time, so I included some of the basic things I was missing. If the README changes should be in a separate PR, let me know

@SimplyAName SimplyAName changed the title Fix json parsing in tasks when {} are included in git version output Fix json parsing in tasks when '{' is in the GitVersion output Oct 14, 2025
@SimplyAName SimplyAName changed the title Fix json parsing in tasks when '{' is in the GitVersion output Fix JSON parsing in tasks when '{' is in the GitVersion output Oct 14, 2025
@SimplyAName SimplyAName changed the title Fix JSON parsing in tasks when '{' is in the GitVersion output WIP: Fix JSON parsing in tasks when '{' is in the GitVersion output Oct 14, 2025
@SimplyAName SimplyAName reopened this Oct 14, 2025
@arturcic
Copy link
Member

@SimplyAName thanks for putting that much effort in this, I will hopefully have a look soon on the changes

@SimplyAName
Copy link
Author

SimplyAName commented Oct 15, 2025

Awesome, thanks.

The main code is working, just having some issues with my tests.
I didn't account for a detached state when running them. Working out a fix today

@SimplyAName SimplyAName changed the title WIP: Fix JSON parsing in tasks when '{' is in the GitVersion output Fix JSON parsing in tasks when '{' is in the GitVersion output Oct 15, 2025
@SimplyAName
Copy link
Author

All tests have been fixed now.

Had to modify one of the existing tests that checks the SHA of the commit.

Was failing due to the pipeline merging master in before running. This resulted in a new commit and hash being created, which did not match the branch being checked by GitVersion. Updated to get the latest commit without merge commits

@arturcic
Copy link
Member

@SimplyAName please use rebase onto main instead of merging main into your branch. We prefer clean history with no intermediair merge commits

@SimplyAName SimplyAName force-pushed the feature/fix-json-parsing-azure branch 5 times, most recently from a938242 to 78402aa Compare October 25, 2025 14:32
@SimplyAName
Copy link
Author

@arturcic I've rebased my branch and force-pushed to override the merge commits.
I also updated the README with the info about rebasing.

Lmk if anything needs fixing

@SimplyAName SimplyAName requested a review from arturcic October 25, 2025 14:48
Copy link
Member

@arturcic arturcic left a comment

Choose a reason for hiding this comment

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

LGTM!

@arturcic
Copy link
Member

@SimplyAName please rebase your changes once again and fix the SonarCloud issue:
image

I will accept the change for this release, but I think in the next major release we need to implement it in a more reliable way than parsing the output. There is and -output file -outputFile vars.json https://gitversion.net/docs/usage/cli/arguments which in my opinion is more reliable.

Anyway thanks for the time and effort.

@arturcic arturcic force-pushed the feature/fix-json-parsing-azure branch from 1498904 to 7fe7348 Compare October 28, 2025 07:31
@arturcic
Copy link
Member

@SimplyAName I applied the changes myself and squashed the commits into 2 atomic commits

fixes the gitversion json parsing, including an extractor function to handle branch names with brackets
adds a helper function to find all indexes of a character in a string
adds tests for the json extractor to cover different branch names
@arturcic arturcic force-pushed the feature/fix-json-parsing-azure branch from 7fe7348 to e6808cd Compare October 28, 2025 07:53
@sonarqubecloud
Copy link

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.

[ISSUE]: [error]Expected property name or '}' in JSON at position 1

2 participants