| 1 | // SPDX-License-Identifier: Apache-2.0 | |
| 2 | // Copyright 2026 Egothor | |
| 3 | // Copyright 2026 Accenture | |
| 4 | package org.egothor.methodatlas.attest; | |
| 5 | ||
| 6 | import java.util.List; | |
| 7 | ||
| 8 | /** | |
| 9 | * Resolves the current commit SHA from well-known CI environment variables. | |
| 10 | * | |
| 11 | * <p> | |
| 12 | * Variables are tried in order; the first non-blank value wins. When none of | |
| 13 | * the known variables is set (e.g. on a local developer workstation) the | |
| 14 | * sentinel value {@code "unknown"} is returned. | |
| 15 | * </p> | |
| 16 | * | |
| 17 | * <p> | |
| 18 | * Package-private because nothing outside the {@code attest} package needs to | |
| 19 | * resolve the commit SHA independently; {@link AttestCollector} calls this | |
| 20 | * class at report-build time. | |
| 21 | * </p> | |
| 22 | */ | |
| 23 | final class CommitShaResolver { | |
| 24 | ||
| 25 | private static final List<String> ENV_VARS = List.of( | |
| 26 | "GITHUB_SHA", | |
| 27 | "CI_COMMIT_SHA", | |
| 28 | "GIT_COMMIT", | |
| 29 | "BUILD_SOURCEVERSION", | |
| 30 | "BITBUCKET_COMMIT"); | |
| 31 | ||
| 32 | private CommitShaResolver() { | |
| 33 | // Utility class. | |
| 34 | } | |
| 35 | ||
| 36 | /** | |
| 37 | * Returns the commit SHA from the environment, or {@code "unknown"} when | |
| 38 | * no CI environment variable is set. | |
| 39 | * | |
| 40 | * @return non-null, non-empty commit SHA string or {@code "unknown"} | |
| 41 | */ | |
| 42 | /* default */ static String resolve() { | |
| 43 | for (String var : ENV_VARS) { | |
| 44 | String val = System.getenv(var); | |
| 45 |
4
1. resolve : removed conditional - replaced equality check with true → NO_COVERAGE 2. resolve : removed conditional - replaced equality check with false → NO_COVERAGE 3. resolve : removed conditional - replaced equality check with false → NO_COVERAGE 4. resolve : removed conditional - replaced equality check with true → NO_COVERAGE |
if (val != null && !val.isBlank()) { |
| 46 |
1
1. resolve : replaced return value with "" for org/egothor/methodatlas/attest/CommitShaResolver::resolve → NO_COVERAGE |
return val; |
| 47 | } | |
| 48 | } | |
| 49 |
1
1. resolve : replaced return value with "" for org/egothor/methodatlas/attest/CommitShaResolver::resolve → NO_COVERAGE |
return "unknown"; |
| 50 | } | |
| 51 | } | |
Mutations | ||
| 45 |
1.1 2.2 3.3 4.4 |
|
| 46 |
1.1 |
|
| 49 |
1.1 |