spring-cloud-contract
spring-cloud-contract copied to clipboard
Enhancement: when doing Git checkout, fallback on master/main if branch not found
I am trying to set up the Consumer Driven Contracts workflow while storing stubs in Git. I think it works best if branch name in the pull request of the contracts repo matches exactly the branch name in the consumer/producer pull request. So, I can just use the current branch name (inside consumer/producer repository) as the branch needed in the contracts repository. That works great, but when consumer/producer wants to develop something not related to API changes, then their CI will fail because of this:
Execution default of goal org.springframework.cloud:spring-cloud-contract-maven-plugin:2.1.2.RELEASE:generateTests failed: org.eclipse.jgit.api.errors.RefNotFoundException: Ref feature/BUG-123_null_pointer cannot be resolved
It would be very nice if in that case Spring Cloud Contract could just print a warning and use "master" instead of failing the build.
Can you describe your producer / consumer / external repo setup cause I don't understand your flow yet.
In contracts Git repo:
- Create a branch
new_endpoint
and pushnew_endpoint.yml
andnew_endpoint_stub.json
(contracts and mappings directories).
In producer Git repo:
- Create a branch
new_endpoint
and run thespring-cloud-contract-maven-plugin:generateTests
maven goal withcontractsProperties.git.branch = new_endpoint
(with maven configuration). The goal will generate the test which I can run. - Create a branch
feature/BUG-123_null_pointer
and run thespring-cloud-contract-maven-plugin:generateTests
maven goal withcontractsProperties.git.branch = feature/BUG-123_null_pointer
(with maven configuration). The goal will fail because such a branch is not found in the contracts repository.
I would like in step 3 to just fallback to master
branch.
P.S. I am using git-commit-id-plugin
to get the git.branch
property, which I can then feed into the contract plugin.
As a workaround, I am now specifying the branch manually. Hopefully, I don't forget to set it back to master when the endpoint is done
I want to try to work on this! gracehopperOSD 👩💻
Hi, I am Shreya, a contributor to OpenForce 2022. I would like to work on this issue. I would be making a PR as soon as I am done with resolving the issue. Thank you
A bit of a drive-by because I'm just randomly ended up here but could this help?
([ -n "$(git rev-parse --verify --quiet main)" ] && echo 'main') || ([ -n "$(git rev-parse --verify --quiet master)" ] && echo 'master')
Will print main
if the main
branch exists, otherwise master
if the master
branch exists.
Apologies if that is not along the lines of what you are looking for.