codeclimate / test-reporter

Code Climate Test Reporter
MIT License
156 stars 76 forks source link

Drone CI: Wrong branch reported for PRs #457

Open abrain opened 3 years ago

abrain commented 3 years ago

When uploading the coverage report for a Pull Request using Drone CI, the result is attributed to the target branch of the Pull Request.

Situation: I want to merge the branch feature/foo into the branch develop of the same repo and open a PR for it. Whenever the PR gets tested, the results on Code Climate for develop are overwritten with the results from the PR.

On Drone CI, the test-reporter tries to determine the branch from the DRONE_BRANCH environment variable. https://github.com/codeclimate/test-reporter/blob/f002281bc147c6f5d88f65a4f2277c489d75dbde/env/git.go#L159

For push events this is fine, but for Pull Requests it contains the target branch of the PR, not the source branch. As far as I can tell, there is no single environment variable that would fit the purpose. As a workaround, I use a script to set GIT_BRANCH to the correct branch before uploading.