fix(coverage): detect branch on Travis CI push builds#2753
fix(coverage): detect branch on Travis CI push builds#2753davehenton wants to merge 1 commit intomainfrom
Conversation
On Travis push builds, `TRAVIS_PULL_REQUEST_BRANCH` is exported as
an empty string rather than being unset. `SystemEnv::var()` wraps
`std::env::var().ok()`, which returns `Some("")` for set-but-empty
vars, so the `or_else` chain in `TravisCI::branch()` never falls
back to `TRAVIS_BRANCH`. Coverage uploads from any push build
(e.g. merge commits on the default branch) then fail validation
with "A branch, tag, or pull request must be specified."
Filter out the empty string before the fallback, matching the
pattern already used by `git_tag()` for `TRAVIS_TAG`. PR builds
are unaffected because they populate `TRAVIS_PULL_REQUEST_BRANCH`
with the source branch.
Adds a regression test for the push-build case with an explicit
empty `TRAVIS_PULL_REQUEST_BRANCH`.
|
Coverage Impact - ubuntu-latest This PR will not change total coverage. Modified Files with Diff Coverage (1)
🛟 Help
|
|
Coverage Impact - macos-15 This PR will not change total coverage. Modified Files with Diff Coverage (1)
🛟 Help
|

Fixes qltysh/cloud#8231.
Summary
Fix
qlty coverage publishfailing on Travis CI push builds (merge commits, direct pushes to a branch) with:PR builds were unaffected — only push builds hit this.
The bug
TravisCI::branch()inqlty-coverage/src/ci/travisci.rsreads:On a Travis push build,
TRAVIS_PULL_REQUEST_BRANCHis exported as an empty string, not unset.SystemEnv::var()isstd::env::var(name).ok(), which returnsSome("")for set-but-empty vars — so theOptionisSome(""),.or_else(...)never fires, theTRAVIS_BRANCHfallback is skipped, andbranch()returns"".With an empty branch, empty
pull_number()(it's"false"on push builds), and emptygit_tag(),reference_typeresolves toUnspecifiedand validation atqlty-cli/src/commands/coverage/utils.rsaborts the upload.PR builds work because
TRAVIS_PULL_REQUEST_BRANCHis populated with the source branch, so theSome("<branch>")path returns a valid value.Reference: Travis default environment variables.
The fix
One-line change: filter out the empty string before falling through to
TRAVIS_BRANCH.fn branch(&self) -> String { self.env .var("TRAVIS_PULL_REQUEST_BRANCH") + .filter(|b| !b.is_empty()) .or_else(|| self.env.var("TRAVIS_BRANCH")) .unwrap_or_default() }This mirrors the pattern the same file already uses in
git_tag()forTRAVIS_TAG. PR builds keep working:TRAVIS_PULL_REQUEST_BRANCHis non-empty, the filter passes it through unchanged.Testing
branch_push_build_with_empty_pr_branch— setsTRAVIS_BRANCH=main,TRAVIS_PULL_REQUEST_BRANCH="",TRAVIS_PULL_REQUEST=false(exactly what Travis exports on a push build) and assertsbranch() == "main".left: "" right: "main"— matching the real-world error.qlty-coveragesuite passes: 255/255 tests, 0 failures.branchandbranch_pull_requesttests continue to pass, confirming no regression in the push-without-PR-var and PR-build codepaths.