Spring-cloud-contract: Enhancement: when doing Git checkout, fallback on master if branch not found

Created on 13 Sep 2019  ·  4Comments  ·  Source: spring-cloud/spring-cloud-contract

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.

enhancement gracehopperOSD

Most helpful comment

I want to try to work on this! gracehopperOSD 👩‍💻

All 4 comments

Can you describe your producer / consumer / external repo setup cause I don't understand your flow yet.

In contracts Git repo:

  1. Create a branch new_endpoint and push new_endpoint.yml and new_endpoint_stub.json (contracts and mappings directories).

In producer Git repo:

  1. Create a branch new_endpoint and run the spring-cloud-contract-maven-plugin:generateTests maven goal with contractsProperties.git.branch = new_endpoint (with maven configuration).
    The goal will generate the test which I can run.
  2. Create a branch feature/BUG-123_null_pointer and run the spring-cloud-contract-maven-plugin:generateTests maven goal with contractsProperties.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 👩‍💻

Was this page helpful?
0 / 5 - 0 ratings