From 6980d02277f854f222426602b4c78c24dab4d66f Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Fri, 16 May 2025 11:34:24 +0200 Subject: [PATCH 01/28] remove backend request for diff --- .../civisibility/config/ChangedFiles.java | 28 -------------- .../civisibility/config/ConfigurationApi.java | 7 ---- .../config/ConfigurationApiImpl.java | 38 ------------------- .../config/ExecutionSettingsFactoryImpl.java | 28 -------------- .../config/ConfigurationApiImplTest.groovy | 25 ------------ .../civisibility/config/diffs-request.ftl | 29 -------------- .../civisibility/config/diffs-response.ftl | 13 ------- .../main/java/datadog/trace/api/Config.java | 7 ---- .../telemetry/CiVisibilityCountMetric.java | 5 --- .../CiVisibilityDistributionMetric.java | 7 ---- 10 files changed, 187 deletions(-) delete mode 100644 dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ChangedFiles.java delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/diffs-request.ftl delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/diffs-response.ftl diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ChangedFiles.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ChangedFiles.java deleted file mode 100644 index 3867c290d99..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ChangedFiles.java +++ /dev/null @@ -1,28 +0,0 @@ -package datadog.trace.civisibility.config; - -import com.squareup.moshi.Json; -import java.util.Collections; -import java.util.Set; - -public class ChangedFiles { - - public static final ChangedFiles EMPTY = new ChangedFiles(null, Collections.emptySet()); - - @Json(name = "base_sha") - private final String baseSha; - - private final Set files; - - ChangedFiles(String baseSha, Set files) { - this.baseSha = baseSha; - this.files = files; - } - - public String getBaseSha() { - return baseSha; - } - - public Set getFiles() { - return files; - } -} diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApi.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApi.java index 807663705f7..e190fedc53d 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApi.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApi.java @@ -38,11 +38,6 @@ public Map>> getTestManagementTests TracerEnvironment tracerEnvironment) { return Collections.emptyMap(); } - - @Override - public ChangedFiles getChangedFiles(TracerEnvironment tracerEnvironment) { - return ChangedFiles.EMPTY; - } }; CiVisibilitySettings getSettings(TracerEnvironment tracerEnvironment) throws IOException; @@ -58,6 +53,4 @@ Map> getKnownTestsByModule(TracerEnvironment tracerE Map>> getTestManagementTestsByModule( TracerEnvironment tracerEnvironment) throws IOException; - - ChangedFiles getChangedFiles(TracerEnvironment tracerEnvironment) throws IOException; } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApiImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApiImpl.java index 2098ce9d87b..ec5966bae4a 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApiImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApiImpl.java @@ -53,7 +53,6 @@ public class ConfigurationApiImpl implements ConfigurationApi { private static final String SETTINGS_URI = "libraries/tests/services/setting"; private static final String SKIPPABLE_TESTS_URI = "ci/tests/skippable"; - private static final String CHANGED_FILES_URI = "ci/tests/diffs"; private static final String FLAKY_TESTS_URI = "ci/libraries/tests/flaky"; private static final String KNOWN_TESTS_URI = "ci/libraries/tests"; private static final String TEST_MANAGEMENT_TESTS_URI = "test/libraries/test-management/tests"; @@ -68,7 +67,6 @@ public class ConfigurationApiImpl implements ConfigurationApi { private final JsonAdapter> testFullNamesResponseAdapter; private final JsonAdapter> testManagementRequestAdapter; private final JsonAdapter> testManagementTestsResponseAdapter; - private final JsonAdapter> changedFilesResponseAdapter; public ConfigurationApiImpl(BackendApi backendApi, CiVisibilityMetricCollector metricCollector) { this(backendApi, metricCollector, () -> RandomUtils.randomUUID().toString()); @@ -119,11 +117,6 @@ public ConfigurationApiImpl(BackendApi backendApi, CiVisibilityMetricCollector m Types.newParameterizedTypeWithOwner( ConfigurationApiImpl.class, EnvelopeDto.class, TestManagementTestsDto.class); testManagementTestsResponseAdapter = moshi.adapter(testManagementTestsResponseType); - - ParameterizedType changedFilesResponseAdapterType = - Types.newParameterizedTypeWithOwner( - ConfigurationApiImpl.class, EnvelopeDto.class, ChangedFiles.class); - changedFilesResponseAdapter = moshi.adapter(changedFilesResponseAdapterType); } @Override @@ -415,37 +408,6 @@ private Map>> parseTestManagementTe return testsByTypeByModule; } - @Override - public ChangedFiles getChangedFiles(TracerEnvironment tracerEnvironment) throws IOException { - OkHttpUtils.CustomListener telemetryListener = - new TelemetryListener.Builder(metricCollector) - .requestCount(CiVisibilityCountMetric.IMPACTED_TESTS_DETECTION_REQUEST) - .requestErrors(CiVisibilityCountMetric.IMPACTED_TESTS_DETECTION_REQUEST_ERRORS) - .requestDuration(CiVisibilityDistributionMetric.IMPACTED_TESTS_DETECTION_REQUEST_MS) - .responseBytes(CiVisibilityDistributionMetric.IMPACTED_TESTS_DETECTION_RESPONSE_BYTES) - .build(); - - String uuid = uuidGenerator.get(); - EnvelopeDto request = - new EnvelopeDto<>(new DataDto<>(uuid, "ci_app_tests_diffs_request", tracerEnvironment)); - String json = requestAdapter.toJson(request); - RequestBody requestBody = RequestBody.create(JSON, json); - ChangedFiles changedFiles = - backendApi.post( - CHANGED_FILES_URI, - requestBody, - is -> - changedFilesResponseAdapter.fromJson(Okio.buffer(Okio.source(is))).data.attributes, - telemetryListener, - false); - - int filesCount = changedFiles.getFiles().size(); - LOGGER.debug("Received {} changed files", filesCount); - metricCollector.add( - CiVisibilityDistributionMetric.IMPACTED_TESTS_DETECTION_RESPONSE_FILES, filesCount); - return changedFiles; - } - private static final class EnvelopeDto { private final DataDto data; diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java index 3e0a62105e5..a22211b379e 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java @@ -8,7 +8,6 @@ import datadog.trace.api.git.GitInfoProvider; import datadog.trace.civisibility.ci.PullRequestInfo; import datadog.trace.civisibility.diff.Diff; -import datadog.trace.civisibility.diff.FileDiff; import datadog.trace.civisibility.diff.LineDiff; import datadog.trace.civisibility.git.tree.GitClient; import datadog.trace.civisibility.git.tree.GitDataUploader; @@ -425,37 +424,10 @@ private Diff getPullRequestDiff( } catch (InterruptedException e) { LOGGER.error("Interrupted while getting git diff for PR: {}", pullRequestInfo, e); Thread.currentThread().interrupt(); - } catch (Exception e) { LOGGER.error("Could not get git diff for PR: {}", pullRequestInfo, e); } - if (config.isCiVisibilityImpactedTestsBackendRequestEnabled()) { - try { - ChangedFiles changedFiles = configurationApi.getChangedFiles(tracerEnvironment); - - // attempting to use base SHA returned by the backend to calculate git diff - if (repositoryRoot != null) { - // ensure repo is not shallow before attempting to get git diff - gitRepoUnshallow.unshallow(); - Diff diff = gitClient.getGitDiff(changedFiles.getBaseSha(), tracerEnvironment.getSha()); - if (diff != null) { - return diff; - } - } - - // falling back to file-level granularity - return new FileDiff(changedFiles.getFiles()); - - } catch (InterruptedException e) { - LOGGER.error("Interrupted while getting git diff for: {}", tracerEnvironment, e); - Thread.currentThread().interrupt(); - - } catch (Exception e) { - LOGGER.error("Could not get git diff for: {}", tracerEnvironment, e); - } - } - return LineDiff.EMPTY; } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy index 6afd6186b4a..dc2d60f440c 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy @@ -218,31 +218,6 @@ class ConfigurationApiImplTest extends Specification { intakeServer.close() } - def "test changed files request"() { - given: - def tracerEnvironment = givenTracerEnvironment() - - def intakeServer = givenBackendEndpoint( - "/api/v2/ci/tests/diffs", - "/datadog/trace/civisibility/config/diffs-request.ftl", - [uid: REQUEST_UID, tracerEnvironment: tracerEnvironment], - "/datadog/trace/civisibility/config/diffs-response.ftl", - [:] - ) - - def configurationApi = givenConfigurationApi(intakeServer) - - when: - def changedFiles = configurationApi.getChangedFiles(tracerEnvironment) - - then: - changedFiles.baseSha == "ef733331f7cee9b1c89d82df87942d8606edf3f7" - changedFiles.files == new HashSet([ - "domains/ci-app/apps/apis/rapid-ci-app/internal/itrapihttp/api.go", - "domains/ci-app/apps/apis/rapid-ci-app/internal/itrapihttp/api_test.go" - ]) - } - private ConfigurationApi givenConfigurationApi(TestHttpServer intakeServer, boolean agentless = true, boolean compression = true) { def api = agentless ? givenIntakeApi(intakeServer.address, compression) diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/diffs-request.ftl b/dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/diffs-request.ftl deleted file mode 100644 index fc4ab315577..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/diffs-request.ftl +++ /dev/null @@ -1,29 +0,0 @@ -{ - "data": { - "type" : "ci_app_tests_diffs_request", - "id" : "${uid}", - "attributes": { - "service" : "${tracerEnvironment.service}", - "env" : "${tracerEnvironment.env}", - "repository_url": "${tracerEnvironment.repositoryUrl}", - "branch" : "${tracerEnvironment.branch}", - "sha" : "${tracerEnvironment.sha}", - "test_level" : "${tracerEnvironment.testLevel}", - "configurations": { - "os.platform" : "${tracerEnvironment.configurations.osPlatform}", - "os.architecture" : "${tracerEnvironment.configurations.osArchitecture}", - "os.arch" : "${tracerEnvironment.configurations.osArchitecture}", - "os.version" : "${tracerEnvironment.configurations.osVersion}", - "runtime.name" : "${tracerEnvironment.configurations.runtimeName}", - "runtime.version" : "${tracerEnvironment.configurations.runtimeVersion}", - "runtime.vendor" : "${tracerEnvironment.configurations.runtimeVendor}", - "runtime.architecture": "${tracerEnvironment.configurations.runtimeArchitecture}", - "custom" : { - <#list tracerEnvironment.configurations.custom as customTag, customValue> - "${customTag}": "${customValue}"<#if customTag?has_next>, - - } - } - } - } -} diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/diffs-response.ftl b/dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/diffs-response.ftl deleted file mode 100644 index fe0986ed261..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/diffs-response.ftl +++ /dev/null @@ -1,13 +0,0 @@ -{ - "data": { - "type": "ci_app_tests_diffs_response", - "id": "1235456", - "attributes": { - "base_sha": "ef733331f7cee9b1c89d82df87942d8606edf3f7", - "files": [ - "domains/ci-app/apps/apis/rapid-ci-app/internal/itrapihttp/api.go", - "domains/ci-app/apps/apis/rapid-ci-app/internal/itrapihttp/api_test.go" - ] - } - } -} diff --git a/internal-api/src/main/java/datadog/trace/api/Config.java b/internal-api/src/main/java/datadog/trace/api/Config.java index 6f3041ca7d8..169e68bc0ec 100644 --- a/internal-api/src/main/java/datadog/trace/api/Config.java +++ b/internal-api/src/main/java/datadog/trace/api/Config.java @@ -366,7 +366,6 @@ public static String getHostName() { private final List ciVisibilityResourceFolderNames; private final boolean ciVisibilityFlakyRetryEnabled; private final boolean ciVisibilityImpactedTestsDetectionEnabled; - private final boolean ciVisibilityImpactedTestsBackendRequestEnabled; private final boolean ciVisibilityKnownTestsRequestEnabled; private final boolean ciVisibilityFlakyRetryOnlyKnownFlakes; private final int ciVisibilityFlakyRetryCount; @@ -1585,8 +1584,6 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment()) configProvider.getBoolean(CIVISIBILITY_FLAKY_RETRY_ENABLED, true); ciVisibilityImpactedTestsDetectionEnabled = configProvider.getBoolean(CIVISIBILITY_IMPACTED_TESTS_DETECTION_ENABLED, true); - ciVisibilityImpactedTestsBackendRequestEnabled = - configProvider.getBoolean(CIVISIBILITY_IMPACTED_TESTS_BACKEND_REQUEST_ENABLED, false); ciVisibilityKnownTestsRequestEnabled = configProvider.getBoolean(CIVISIBILITY_KNOWN_TESTS_REQUEST_ENABLED, true); ciVisibilityFlakyRetryOnlyKnownFlakes = @@ -3096,10 +3093,6 @@ public boolean isCiVisibilityImpactedTestsDetectionEnabled() { return ciVisibilityImpactedTestsDetectionEnabled; } - public boolean isCiVisibilityImpactedTestsBackendRequestEnabled() { - return ciVisibilityImpactedTestsBackendRequestEnabled; - } - public boolean isCiVisibilityKnownTestsRequestEnabled() { return ciVisibilityKnownTestsRequestEnabled; } diff --git a/internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/CiVisibilityCountMetric.java b/internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/CiVisibilityCountMetric.java index 2d8de535abe..868ecde90b8 100644 --- a/internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/CiVisibilityCountMetric.java +++ b/internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/CiVisibilityCountMetric.java @@ -163,11 +163,6 @@ public enum CiVisibilityCountMetric { FLAKY_TESTS_REQUEST("flaky_tests.request", RequestCompressed.class), /** The number of tests requests sent to the flaky tests endpoint that errored */ FLAKY_TESTS_REQUEST_ERRORS("flaky_tests.request_errors", ErrorType.class, StatusCode.class), - /** The number of requests sent to the changed files endpoint */ - IMPACTED_TESTS_DETECTION_REQUEST("impacted_tests_detection.request", RequestCompressed.class), - /** The number of tests requests sent to the changed files endpoint that errored */ - IMPACTED_TESTS_DETECTION_REQUEST_ERRORS( - "impacted_tests_detection.request_errors", ErrorType.class, StatusCode.class), /** The number of requests sent to the test management tests endpoint */ TEST_MANAGEMENT_TESTS_REQUEST("test_management.request", RequestCompressed.class), /** The number of tests requests sent to the test management tests endpoint that errored */ diff --git a/internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/CiVisibilityDistributionMetric.java b/internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/CiVisibilityDistributionMetric.java index a50f2a2d61c..8dcaa6eb385 100644 --- a/internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/CiVisibilityDistributionMetric.java +++ b/internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/CiVisibilityDistributionMetric.java @@ -51,13 +51,6 @@ public enum CiVisibilityDistributionMetric { FLAKY_TESTS_RESPONSE_BYTES("flaky_tests.response_bytes", ResponseCompressed.class), /** The number of tests received by the flaky tests endpoint */ FLAKY_TESTS_RESPONSE_TESTS("flaky_tests.response_tests"), - /** The time it takes to get the response of the changed files endpoint request in ms */ - IMPACTED_TESTS_DETECTION_REQUEST_MS("impacted_tests_detection.request_ms"), - /** The number of bytes received by the changed files endpoint */ - IMPACTED_TESTS_DETECTION_RESPONSE_BYTES( - "impacted_tests_detection.response_bytes", ResponseCompressed.class), - /** The number of files received by the changed files endpoint */ - IMPACTED_TESTS_DETECTION_RESPONSE_FILES("impacted_tests_detection.response_files"), /** The time it takes to get the response of the test management tests endpoint request in ms */ TEST_MANAGEMENT_TESTS_REQUEST_MS("test_management.request_ms"), /** The number of bytes received by the test management tests endpoint */ From a7f738d3d9542bae5b81ab2f4b6f761910bb0456 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Tue, 20 May 2025 16:19:30 +0200 Subject: [PATCH 02/28] update PRInfo building to use partial information from CI vendors --- .../CiVisibilityRepoServices.java | 43 ++++++++++++++----- .../trace/civisibility/ci/AppVeyorInfo.java | 2 +- .../trace/civisibility/ci/BitBucketInfo.java | 3 +- .../trace/civisibility/ci/BuddyInfo.java | 3 +- .../civisibility/ci/PullRequestInfo.java | 26 +++++++++++ .../trace/api/config/CiVisibilityConfig.java | 5 +++ .../main/java/datadog/trace/api/Config.java | 18 ++++++++ 7 files changed, 86 insertions(+), 14 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java index d3c0280a84b..adfa51161f4 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java @@ -65,7 +65,8 @@ public class CiVisibilityRepoServices { ciProvider = ciProviderInfo.getProvider(); CIInfo ciInfo = ciProviderInfo.buildCIInfo(); - PullRequestInfo pullRequestInfo = buildPullRequestInfo(services.environment, ciProviderInfo); + PullRequestInfo pullRequestInfo = + buildPullRequestInfo(services.config, services.environment, ciProviderInfo); if (pullRequestInfo.isNotEmpty()) { LOGGER.info("PR detected: {}", pullRequestInfo); @@ -110,18 +111,38 @@ public class CiVisibilityRepoServices { @Nonnull private static PullRequestInfo buildPullRequestInfo( - CiEnvironment environment, CIProviderInfo ciProviderInfo) { - PullRequestInfo ciProviderPrInfo = ciProviderInfo.buildPullRequestInfo(); - if (ciProviderPrInfo.isNotEmpty()) { - return ciProviderPrInfo; + Config config, CiEnvironment environment, CIProviderInfo ciProviderInfo) { + PullRequestInfo info = buildUserPullRequestInfo(config, environment); + + if (info.isComplete()) { + return info; + } + + // complete with CI vars if user didn't provide all information + return PullRequestInfo.merge(info, ciProviderInfo.buildPullRequestInfo()); + } + + @Nonnull + private static PullRequestInfo buildUserPullRequestInfo( + Config config, CiEnvironment environment) { + PullRequestInfo userInfo = + new PullRequestInfo( + config.getGitPullRequestBaseBranch(), + config.getGitPullRequestBaseBranchSha(), + config.getGitCommitHeadSha()); + + if (userInfo.isComplete()) { + return userInfo; } - // could not get PR info from CI provider, - // check if it was set manually - return new PullRequestInfo( - null, - environment.get(Constants.DDCI_PULL_REQUEST_TARGET_SHA), - environment.get(Constants.DDCI_PULL_REQUEST_SOURCE_SHA)); + // logs-backend specific vars + PullRequestInfo ddCiInfo = + new PullRequestInfo( + null, + environment.get(Constants.DDCI_PULL_REQUEST_TARGET_SHA), + environment.get(Constants.DDCI_PULL_REQUEST_SOURCE_SHA)); + + return PullRequestInfo.merge(userInfo, ddCiInfo); } private static String getRepoRoot(CIInfo ciInfo, GitClient.Factory gitClientFactory) { diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java index 3657766e312..224082cd629 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java @@ -83,7 +83,7 @@ public CIInfo buildCIInfo() { @Nonnull @Override public PullRequestInfo buildPullRequestInfo() { - return PullRequestInfo.EMPTY; + return new PullRequestInfo(environment.get(APPVEYOR_REPO_BRANCH), null, null); } private String buildGitBranch(final String repoProvider) { diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java index bbda148a978..a8ac3e79286 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java @@ -26,6 +26,7 @@ class BitBucketInfo implements CIProviderInfo { public static final String BITBUCKET_GIT_COMMIT = "BITBUCKET_COMMIT"; public static final String BITBUCKET_GIT_BRANCH = "BITBUCKET_BRANCH"; public static final String BITBUCKET_GIT_TAG = "BITBUCKET_TAG"; + public static final String BITBUCKET_PR_DESTINATION_BRANCH = "BITBUCKET_PR_DESTINATION_BRANCH"; private final CiEnvironment environment; @@ -74,7 +75,7 @@ public CIInfo buildCIInfo() { @Nonnull @Override public PullRequestInfo buildPullRequestInfo() { - return PullRequestInfo.EMPTY; + return new PullRequestInfo(environment.get(BITBUCKET_PR_DESTINATION_BRANCH), null, null); } private String buildPipelineUrl(final String repo, final String number) { diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java index 4ae853c55e4..3238313749a 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java @@ -27,6 +27,7 @@ class BuddyInfo implements CIProviderInfo { public static final String BUDDY_GIT_COMMIT_MESSAGE = "BUDDY_EXECUTION_REVISION_MESSAGE"; public static final String BUDDY_GIT_COMMIT_AUTHOR = "BUDDY_EXECUTION_REVISION_COMMITTER_NAME"; public static final String BUDDY_GIT_COMMIT_EMAIL = "BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL"; + public static final String BUDDY_RUN_PR_BASE_BRANCH = "BUDDY_RUN_PR_BASE_BRANCH"; private final CiEnvironment environment; @@ -62,7 +63,7 @@ public CIInfo buildCIInfo() { @Nonnull @Override public PullRequestInfo buildPullRequestInfo() { - return PullRequestInfo.EMPTY; + return new PullRequestInfo(BUDDY_RUN_PR_BASE_BRANCH, null, null); } private String getPipelineId(String pipelineNumber) { diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/PullRequestInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/PullRequestInfo.java index 7365f8f824a..54a4a96c609 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/PullRequestInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/PullRequestInfo.java @@ -36,6 +36,32 @@ public boolean isNotEmpty() { || Strings.isNotBlank(gitCommitHeadSha); } + public boolean isComplete() { + return Strings.isNotBlank(pullRequestBaseBranch) + && Strings.isNotBlank(pullRequestBaseBranchSha) + && Strings.isNotBlank(gitCommitHeadSha); + } + + /** + * Merges info by completing the empty information fields with the fallback's + * + * @param info Base PR info + * @param fallback Fallback PR info + * @return Completed PR info + */ + public static PullRequestInfo merge(PullRequestInfo info, PullRequestInfo fallback) { + return new PullRequestInfo( + Strings.isNotBlank(info.pullRequestBaseBranch) + ? info.pullRequestBaseBranch + : fallback.pullRequestBaseBranch, + Strings.isNotBlank(info.pullRequestBaseBranchSha) + ? info.pullRequestBaseBranchSha + : fallback.pullRequestBaseBranchSha, + Strings.isNotBlank(info.gitCommitHeadSha) + ? info.gitCommitHeadSha + : fallback.gitCommitHeadSha); + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java b/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java index 30bb443de82..d7ab9ad204a 100644 --- a/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java +++ b/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java @@ -85,6 +85,11 @@ public final class CiVisibilityConfig { public static final String TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES = "test.management.attempt.to.fix.retries"; + /* Git PR info */ + public static final String GIT_PULL_REQUEST_BASE_BRANCH = "git.pull.request.base.branch"; + public static final String GIT_PULL_REQUEST_BASE_BRANCH_SHA = "git.pull.request.base.branch.sha"; + public static final String GIT_COMMIT_HEAD_SHA = "git.commit.head.sha"; + /* COVERAGE SETTINGS */ public static final String CIVISIBILITY_CODE_COVERAGE_ENABLED = "civisibility.code.coverage.enabled"; diff --git a/internal-api/src/main/java/datadog/trace/api/Config.java b/internal-api/src/main/java/datadog/trace/api/Config.java index 169e68bc0ec..81f9fd08028 100644 --- a/internal-api/src/main/java/datadog/trace/api/Config.java +++ b/internal-api/src/main/java/datadog/trace/api/Config.java @@ -384,6 +384,9 @@ public static String getHostName() { private final boolean ciVisibilityTestManagementEnabled; private final Integer ciVisibilityTestManagementAttemptToFixRetries; private final boolean ciVisibilityScalatestForkMonitorEnabled; + private final String gitPullRequestBaseBranch; + private final String gitPullRequestBaseBranchSha; + private final String gitCommitHeadSha; private final boolean remoteConfigEnabled; private final boolean remoteConfigIntegrityCheckEnabled; @@ -1613,6 +1616,9 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment()) configProvider.getInteger(TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES); ciVisibilityScalatestForkMonitorEnabled = configProvider.getBoolean(CIVISIBILITY_SCALATEST_FORK_MONITOR_ENABLED, false); + gitPullRequestBaseBranch = configProvider.getString(GIT_PULL_REQUEST_BASE_BRANCH); + gitPullRequestBaseBranchSha = configProvider.getString(GIT_PULL_REQUEST_BASE_BRANCH_SHA); + gitCommitHeadSha = configProvider.getString(GIT_COMMIT_HEAD_SHA); remoteConfigEnabled = configProvider.getBoolean( @@ -3176,6 +3182,18 @@ public Integer getCiVisibilityTestManagementAttemptToFixRetries() { return ciVisibilityTestManagementAttemptToFixRetries; } + public String getGitPullRequestBaseBranch() { + return gitPullRequestBaseBranch; + } + + public String getGitPullRequestBaseBranchSha() { + return gitPullRequestBaseBranchSha; + } + + public String getGitCommitHeadSha() { + return gitCommitHeadSha; + } + public String getAppSecRulesFile() { return appSecRulesFile; } From a1238c034b3b54deec20a700ab5c9f2e785dd6de Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Tue, 20 May 2025 16:23:48 +0200 Subject: [PATCH 03/28] synchronize repo unshallow with future, avoids performing several times --- .../config/ExecutionSettingsFactoryImpl.java | 7 +++---- .../git/tree/GitDataUploaderImpl.java | 5 +++-- .../git/tree/GitRepoUnshallow.java | 21 ++++++++++++++++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java index a22211b379e..523978c92be 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java @@ -213,7 +213,7 @@ private Map doCreate( getTestManagementTestsByModule( tracerEnvironment, testManagementSettings.isEnabled())); Future pullRequestDiffFuture = - executor.submit(() -> getPullRequestDiff(tracerEnvironment, impactedTestsEnabled)); + executor.submit(() -> getPullRequestDiff(impactedTestsEnabled)); SkippableTests skippableTests = skippableTestsFuture.get(); Map> flakyTestsByModule = flakyTestsFuture.get(); @@ -402,8 +402,7 @@ private Map>> getTestManagementTest } @Nonnull - private Diff getPullRequestDiff( - TracerEnvironment tracerEnvironment, boolean impactedTestsDetectionEnabled) { + private Diff getPullRequestDiff(boolean impactedTestsDetectionEnabled) { if (!impactedTestsDetectionEnabled) { return LineDiff.EMPTY; } @@ -411,7 +410,7 @@ private Diff getPullRequestDiff( try { if (repositoryRoot != null) { // ensure repo is not shallow before attempting to get git diff - gitRepoUnshallow.unshallow(); + gitRepoUnshallow.startOrObserveUnshallow().get(); Diff diff = gitClient.getGitDiff( pullRequestInfo.getPullRequestBaseBranchSha(), diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java index 5cbc46a51c9..d84b1849c2c 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java @@ -91,7 +91,7 @@ private void uploadGitData() { LOGGER.debug("Starting git data upload, {}", gitClient); if (!config.isCiVisibilityGitUnshallowDefer()) { - gitRepoUnshallow.unshallow(); + gitRepoUnshallow.startOrObserveUnshallow().get(); } GitInfo gitInfo = gitInfoProvider.getGitInfo(repoRoot); @@ -112,7 +112,8 @@ private void uploadGitData() { return; } - if (config.isCiVisibilityGitUnshallowDefer() && gitRepoUnshallow.unshallow()) { + if (config.isCiVisibilityGitUnshallowDefer() + && gitRepoUnshallow.startOrObserveUnshallow().get()) { latestCommits = gitClient.getLatestCommits(); commitsToSkip = gitDataApi.searchCommits(remoteUrl, latestCommits); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java index bc6acd5c9ec..11fde72a21c 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java @@ -3,6 +3,8 @@ import datadog.trace.api.Config; import datadog.trace.civisibility.utils.ShellCommandExecutor; import java.io.IOException; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; import java.util.concurrent.TimeoutException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,13 +15,30 @@ public class GitRepoUnshallow { private final Config config; private final GitClient gitClient; + private volatile CompletableFuture callback; public GitRepoUnshallow(Config config, GitClient gitClient) { this.config = config; this.gitClient = gitClient; } - public boolean unshallow() throws IOException, InterruptedException, TimeoutException { + public Future startOrObserveUnshallow() { + if (callback == null) { + synchronized (this) { + if (callback == null) { + callback = new CompletableFuture<>(); + try { + callback.complete(unshallow()); + } catch (Exception e) { + callback.completeExceptionally(e); + } + } + } + } + return callback; + } + + private boolean unshallow() throws IOException, InterruptedException, TimeoutException { if (!config.isCiVisibilityGitUnshallowEnabled() || !gitClient.isShallow()) { return false; } From cbe2a959123a3a4483f30681f2db0450e7b21053 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Thu, 22 May 2025 11:22:13 +0200 Subject: [PATCH 04/28] add `default_branch` to settings response --- .../config/CiVisibilitySettings.java | 29 +++++++++++++++---- .../civisibility/config/settings-response.ftl | 3 ++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/CiVisibilitySettings.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/CiVisibilitySettings.java index ceedda5b7e4..bdce3fb02b8 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/CiVisibilitySettings.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/CiVisibilitySettings.java @@ -4,6 +4,7 @@ import java.nio.file.Path; import java.util.Map; import java.util.Objects; +import javax.annotation.Nullable; public class CiVisibilitySettings { @@ -17,7 +18,8 @@ public class CiVisibilitySettings { false, false, EarlyFlakeDetectionSettings.DEFAULT, - TestManagementSettings.DEFAULT); + TestManagementSettings.DEFAULT, + null); private final boolean itrEnabled; private final boolean codeCoverage; @@ -28,6 +30,7 @@ public class CiVisibilitySettings { private final boolean knownTestsEnabled; private final EarlyFlakeDetectionSettings earlyFlakeDetectionSettings; private final TestManagementSettings testManagementSettings; + @Nullable private final String defaultBranch; CiVisibilitySettings( boolean itrEnabled, @@ -38,7 +41,8 @@ public class CiVisibilitySettings { boolean impactedTestsDetectionEnabled, boolean knownTestsEnabled, EarlyFlakeDetectionSettings earlyFlakeDetectionSettings, - TestManagementSettings testManagementSettings) { + TestManagementSettings testManagementSettings, + @Nullable String defaultBranch) { this.itrEnabled = itrEnabled; this.codeCoverage = codeCoverage; this.testsSkipping = testsSkipping; @@ -48,6 +52,7 @@ public class CiVisibilitySettings { this.knownTestsEnabled = knownTestsEnabled; this.earlyFlakeDetectionSettings = earlyFlakeDetectionSettings; this.testManagementSettings = testManagementSettings; + this.defaultBranch = defaultBranch; } public boolean isItrEnabled() { @@ -86,6 +91,11 @@ public TestManagementSettings getTestManagementSettings() { return testManagementSettings; } + @Nullable + public String getDefaultBranch() { + return defaultBranch; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -103,7 +113,8 @@ public boolean equals(Object o) { && impactedTestsDetectionEnabled == that.impactedTestsDetectionEnabled && knownTestsEnabled == that.knownTestsEnabled && Objects.equals(earlyFlakeDetectionSettings, that.earlyFlakeDetectionSettings) - && Objects.equals(testManagementSettings, that.testManagementSettings); + && Objects.equals(testManagementSettings, that.testManagementSettings) + && Objects.equals(defaultBranch, that.defaultBranch); } @Override @@ -117,7 +128,8 @@ public int hashCode() { impactedTestsDetectionEnabled, knownTestsEnabled, earlyFlakeDetectionSettings, - testManagementSettings); + testManagementSettings, + defaultBranch); } public interface Factory { @@ -145,7 +157,8 @@ public CiVisibilitySettings fromJson(Map json) { EarlyFlakeDetectionSettings.JsonAdapter.INSTANCE.fromJson( (Map) json.get("early_flake_detection")), TestManagementSettings.JsonAdapter.INSTANCE.fromJson( - (Map) json.get("test_management"))); + (Map) json.get("test_management")), + getString(json, "default_branch", null)); } private static boolean getBoolean( @@ -153,5 +166,11 @@ private static boolean getBoolean( Object value = json.get(fieldName); return value instanceof Boolean ? (Boolean) value : defaultValue; } + + private static String getString( + Map json, String fieldName, String defaultValue) { + Object value = json.get(fieldName); + return value instanceof String ? (String) value : defaultValue; + } } } diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/settings-response.ftl b/dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/settings-response.ftl index 5f5c61db670..f21b821434e 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/settings-response.ftl +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/settings-response.ftl @@ -10,6 +10,9 @@ "flaky_test_retries_enabled": ${settings.flakyTestRetriesEnabled?c}, "impacted_tests_enabled": ${settings.impactedTestsDetectionEnabled?c}, "known_tests_enabled": ${settings.knownTestsEnabled?c}, + <#if settings.defaultBranch??> + "default_branch": "${settings.defaultBranch}", + "early_flake_detection": { "enabled": ${settings.earlyFlakeDetectionSettings.enabled?c}, "slow_test_retries": { From b861e7fbb94b4949972b528ff7315c329e36092c Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Thu, 22 May 2025 11:24:28 +0200 Subject: [PATCH 05/28] update settings api test --- .../civisibility/config/ConfigurationApiImplTest.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy index dc2d60f440c..4cb3ee89c5a 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy @@ -55,10 +55,10 @@ class ConfigurationApiImplTest extends Specification { where: agentless | compression | expectedSettings - false | false | new CiVisibilitySettings(false, false, false, false, false, false, false, EarlyFlakeDetectionSettings.DEFAULT, TestManagementSettings.DEFAULT) - false | true | new CiVisibilitySettings(true, true, true, true, true, true, true, EarlyFlakeDetectionSettings.DEFAULT, TestManagementSettings.DEFAULT) - true | false | new CiVisibilitySettings(false, true, false, true, false, true, false, new EarlyFlakeDetectionSettings(true, [new ExecutionsByDuration(1000, 3)], 10), new TestManagementSettings(true, 10)) - true | true | new CiVisibilitySettings(false, false, true, true, false, false, true, new EarlyFlakeDetectionSettings(true, [new ExecutionsByDuration(5000, 3), new ExecutionsByDuration(120000, 2)], 10), new TestManagementSettings(true, 20)) + false | false | new CiVisibilitySettings(false, false, false, false, false, false, false, EarlyFlakeDetectionSettings.DEFAULT, TestManagementSettings.DEFAULT, null) + false | true | new CiVisibilitySettings(true, true, true, true, true, true, true, EarlyFlakeDetectionSettings.DEFAULT, TestManagementSettings.DEFAULT, "main") + true | false | new CiVisibilitySettings(false, true, false, true, false, true, false, new EarlyFlakeDetectionSettings(true, [new ExecutionsByDuration(1000, 3)], 10), new TestManagementSettings(true, 10), "master") + true | true | new CiVisibilitySettings(false, false, true, true, false, false, true, new EarlyFlakeDetectionSettings(true, [new ExecutionsByDuration(5000, 3), new ExecutionsByDuration(120000, 2)], 10), new TestManagementSettings(true, 20), "prod") } def "test skippable tests request"() { From cab317e178b740e6cb651dd7486bd925338b2843 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Thu, 22 May 2025 11:25:04 +0200 Subject: [PATCH 06/28] change repo unshallow synchronization from future-based to synchronized --- .../config/ExecutionSettingsFactoryImpl.java | 2 +- .../git/tree/GitDataUploaderImpl.java | 4 ++-- .../git/tree/GitRepoUnshallow.java | 20 ++----------------- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java index 523978c92be..ac96c18fc99 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java @@ -410,7 +410,7 @@ private Diff getPullRequestDiff(boolean impactedTestsDetectionEnabled) { try { if (repositoryRoot != null) { // ensure repo is not shallow before attempting to get git diff - gitRepoUnshallow.startOrObserveUnshallow().get(); + gitRepoUnshallow.unshallow(); Diff diff = gitClient.getGitDiff( pullRequestInfo.getPullRequestBaseBranchSha(), diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java index d84b1849c2c..458b6cb7c66 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java @@ -91,7 +91,7 @@ private void uploadGitData() { LOGGER.debug("Starting git data upload, {}", gitClient); if (!config.isCiVisibilityGitUnshallowDefer()) { - gitRepoUnshallow.startOrObserveUnshallow().get(); + gitRepoUnshallow.unshallow(); } GitInfo gitInfo = gitInfoProvider.getGitInfo(repoRoot); @@ -113,7 +113,7 @@ private void uploadGitData() { } if (config.isCiVisibilityGitUnshallowDefer() - && gitRepoUnshallow.startOrObserveUnshallow().get()) { + && gitRepoUnshallow.unshallow()) { latestCommits = gitClient.getLatestCommits(); commitsToSkip = gitDataApi.searchCommits(remoteUrl, latestCommits); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java index 11fde72a21c..5638ce6691c 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java @@ -15,30 +15,14 @@ public class GitRepoUnshallow { private final Config config; private final GitClient gitClient; - private volatile CompletableFuture callback; public GitRepoUnshallow(Config config, GitClient gitClient) { this.config = config; this.gitClient = gitClient; } - public Future startOrObserveUnshallow() { - if (callback == null) { - synchronized (this) { - if (callback == null) { - callback = new CompletableFuture<>(); - try { - callback.complete(unshallow()); - } catch (Exception e) { - callback.completeExceptionally(e); - } - } - } - } - return callback; - } - - private boolean unshallow() throws IOException, InterruptedException, TimeoutException { + public synchronized boolean unshallow() + throws IOException, InterruptedException, TimeoutException { if (!config.isCiVisibilityGitUnshallowEnabled() || !gitClient.isShallow()) { return false; } From e40154996d83ab7c7d49961fe8f83afd0e1af64e Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Fri, 23 May 2025 14:14:10 +0200 Subject: [PATCH 07/28] include pr info checks to CITagsProviderTest --- .../civisibility/ci/AppVeyorInfoTest.groovy | 14 +++++++++++++ .../civisibility/ci/BitBucketInfoTest.groovy | 14 +++++++++++++ .../civisibility/ci/BuddyInfoTest.groovy | 14 +++++++++++++ .../civisibility/ci/CITagsProviderTest.groovy | 20 +++++++++++++++++++ .../civisibility/ci/GitLabInfoTest.groovy | 16 +++++++++++++++ .../ci/GithubActionsInfoTest.groovy | 19 +++++++++--------- 6 files changed, 87 insertions(+), 10 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/AppVeyorInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/AppVeyorInfoTest.groovy index 60ec9df0e8f..e86cead5130 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/AppVeyorInfoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/AppVeyorInfoTest.groovy @@ -24,4 +24,18 @@ class AppVeyorInfoTest extends CITagsProviderTest { map.put(AppVeyorInfo.APPVEYOR_REPO_COMMIT, "0000000000000000000000000000000000000000") return map } + + @Override + void setupPullRequestInfoBuild() { + environmentVariables.set(AppVeyorInfo.APPVEYOR_REPO_BRANCH, "base-branch") + } + + @Override + PullRequestInfo expectedPullRequestInfo() { + return new PullRequestInfo( + "base-branch", + null, + null, + ) + } } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BitBucketInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BitBucketInfoTest.groovy index 5b21890c8b2..5d61e6b2463 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BitBucketInfoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BitBucketInfoTest.groovy @@ -23,4 +23,18 @@ class BitBucketInfoTest extends CITagsProviderTest { map.put(BitBucketInfo.BITBUCKET_GIT_COMMIT, "0000000000000000000000000000000000000000") return map } + + @Override + void setupPullRequestInfoBuild() { + environmentVariables.set(BitBucketInfo.BITBUCKET_PR_DESTINATION_BRANCH, "base-branch") + } + + @Override + PullRequestInfo expectedPullRequestInfo() { + return new PullRequestInfo( + "base-branch", + null, + null, + ) + } } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BuddyInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BuddyInfoTest.groovy index ae95013edd7..8198f4b0ae0 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BuddyInfoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BuddyInfoTest.groovy @@ -22,6 +22,20 @@ class BuddyInfoTest extends CITagsProviderTest { return map } + @Override + void setupPullRequestInfoBuild() { + environmentVariables.set(BuddyInfo.BUDDY_RUN_PR_BASE_BRANCH, "base-branch") + } + + @Override + PullRequestInfo expectedPullRequestInfo() { + return new PullRequestInfo( + "base-branch", + null, + null + ) + } + boolean isWorkspaceAwareCi() { false } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy index d22f7542803..11f86b2f129 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy @@ -158,8 +158,28 @@ abstract class CITagsProviderTest extends Specification { } } + def "test pull request info building"() { + setup: + setupPullRequestInfoBuild() + + expect: + if (isCi()) { + CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS, new CiEnvironmentImpl(System.getenv())) + def ciProviderInfo = ciProviderInfoFactory.createCIProviderInfo(getWorkspacePath()) + def actualPullRequestInfo = ciProviderInfo.buildPullRequestInfo() + + actualPullRequestInfo == expectedPullRequestInfo() + } + } + abstract String getProviderName() + void setupPullRequestInfoBuild() {} + + PullRequestInfo expectedPullRequestInfo() { + return PullRequestInfo.EMPTY + } + Map buildRemoteGitInfoEmpty() { return new HashMap() } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GitLabInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GitLabInfoTest.groovy index b4a504c3092..758fa21fde5 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GitLabInfoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GitLabInfoTest.groovy @@ -23,4 +23,20 @@ class GitLabInfoTest extends CITagsProviderTest { map.put(GitLabInfo.GITLAB_GIT_COMMIT, "0000000000000000000000000000000000000000") return map } + + @Override + void setupPullRequestInfoBuild() { + environmentVariables.set(GitLabInfo.GITLAB_PULL_REQUEST_BASE_BRANCH, "base-branch") + environmentVariables.set(GitLabInfo.GITLAB_PULL_REQUEST_BASE_BRANCH_SHA, "cab317e178b740e6cb651dd7486bd925338b2843") + environmentVariables.set(GitLabInfo.GITLAB_PULL_REQUEST_COMMIT_HEAD_SHA, "b861e7fbb94b4949972b528ff7315c329e36092c") + } + + @Override + PullRequestInfo expectedPullRequestInfo() { + return new PullRequestInfo( + "base-branch", + "cab317e178b740e6cb651dd7486bd925338b2843", + "b861e7fbb94b4949972b528ff7315c329e36092c" + ) + } } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy index ca5e905e0a7..7c9422e26cc 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy @@ -1,6 +1,5 @@ package datadog.trace.civisibility.ci -import datadog.trace.civisibility.ci.env.CiEnvironmentImpl import java.nio.file.Paths @@ -28,20 +27,20 @@ class GithubActionsInfoTest extends CITagsProviderTest { return map } - def "test pull request info parsing"() { - setup: + @Override + void setupPullRequestInfoBuild() { def githubEvent = GithubActionsInfoTest.getResource("/ci/github-event.json") def githubEventPath = Paths.get(githubEvent.toURI()) environmentVariables.set(GithubActionsInfo.GITHUB_BASE_REF, "base-ref") environmentVariables.set(GithubActionsInfo.GITHUB_EVENT_PATH, githubEventPath.toString()) + } - when: - def pullRequestInfo = new GithubActionsInfo(new CiEnvironmentImpl(System.getenv())).buildPullRequestInfo() - - then: - pullRequestInfo.pullRequestBaseBranch == "base-ref" - pullRequestInfo.pullRequestBaseBranchSha == "52e0974c74d41160a03d59ddc73bb9f5adab054b" - pullRequestInfo.gitCommitHeadSha == "df289512a51123083a8e6931dd6f57bb3883d4c4" + @Override + PullRequestInfo expectedPullRequestInfo() { + return new PullRequestInfo( + "base-ref", + "52e0974c74d41160a03d59ddc73bb9f5adab054b", + "df289512a51123083a8e6931dd6f57bb3883d4c4") } } From 63e72366048332846824c8db4ca06085bfb1b2a8 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Fri, 23 May 2025 14:43:29 +0200 Subject: [PATCH 08/28] add tests for prinfo merging --- .../git/tree/GitDataUploaderImpl.java | 3 +-- .../civisibility/git/tree/GitRepoUnshallow.java | 2 -- .../civisibility/ci/PullRequestInfoTest.groovy | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/PullRequestInfoTest.groovy diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java index 458b6cb7c66..5cbc46a51c9 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java @@ -112,8 +112,7 @@ private void uploadGitData() { return; } - if (config.isCiVisibilityGitUnshallowDefer() - && gitRepoUnshallow.unshallow()) { + if (config.isCiVisibilityGitUnshallowDefer() && gitRepoUnshallow.unshallow()) { latestCommits = gitClient.getLatestCommits(); commitsToSkip = gitDataApi.searchCommits(remoteUrl, latestCommits); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java index 5638ce6691c..489e2a4d377 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java @@ -3,8 +3,6 @@ import datadog.trace.api.Config; import datadog.trace.civisibility.utils.ShellCommandExecutor; import java.io.IOException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; import java.util.concurrent.TimeoutException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/PullRequestInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/PullRequestInfoTest.groovy new file mode 100644 index 00000000000..347b1ad6d86 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/PullRequestInfoTest.groovy @@ -0,0 +1,16 @@ +package datadog.trace.civisibility.ci + +import spock.lang.Specification + +class PullRequestInfoTest extends Specification { + def "test merging of informations"() { + PullRequestInfo.merge(infoA, infoB) == result + + where: + infoA | infoB | result + new PullRequestInfo("branchA", "a", "a") | new PullRequestInfo("branchB", "b", "b") | new PullRequestInfo("branchA", "a", "a") + new PullRequestInfo(null, null, null) | new PullRequestInfo("branchB", "b", "b") | new PullRequestInfo("branchB", "b", "b") + new PullRequestInfo("branchA", null, null) | new PullRequestInfo("branchB", "b", "b") | new PullRequestInfo("branchA", "b", "b") + new PullRequestInfo("branchA", null, null) | new PullRequestInfo(null, null, null) | new PullRequestInfo("branchA", null, null) + } +} From a109cfd3256bbbf8f47d1856e2c538e3fcadaa31 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Mon, 2 Jun 2025 11:26:15 +0200 Subject: [PATCH 09/28] Revert "update PRInfo building to use partial information from CI vendors" This reverts commit a7f738d3d9542bae5b81ab2f4b6f761910bb0456. --- .../CiVisibilityRepoServices.java | 43 +++++-------------- .../trace/civisibility/ci/AppVeyorInfo.java | 2 +- .../trace/civisibility/ci/BitBucketInfo.java | 3 +- .../trace/civisibility/ci/BuddyInfo.java | 3 +- .../civisibility/ci/PullRequestInfo.java | 26 ----------- .../trace/api/config/CiVisibilityConfig.java | 5 --- .../main/java/datadog/trace/api/Config.java | 18 -------- 7 files changed, 14 insertions(+), 86 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java index adfa51161f4..d3c0280a84b 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java @@ -65,8 +65,7 @@ public class CiVisibilityRepoServices { ciProvider = ciProviderInfo.getProvider(); CIInfo ciInfo = ciProviderInfo.buildCIInfo(); - PullRequestInfo pullRequestInfo = - buildPullRequestInfo(services.config, services.environment, ciProviderInfo); + PullRequestInfo pullRequestInfo = buildPullRequestInfo(services.environment, ciProviderInfo); if (pullRequestInfo.isNotEmpty()) { LOGGER.info("PR detected: {}", pullRequestInfo); @@ -111,38 +110,18 @@ public class CiVisibilityRepoServices { @Nonnull private static PullRequestInfo buildPullRequestInfo( - Config config, CiEnvironment environment, CIProviderInfo ciProviderInfo) { - PullRequestInfo info = buildUserPullRequestInfo(config, environment); - - if (info.isComplete()) { - return info; - } - - // complete with CI vars if user didn't provide all information - return PullRequestInfo.merge(info, ciProviderInfo.buildPullRequestInfo()); - } - - @Nonnull - private static PullRequestInfo buildUserPullRequestInfo( - Config config, CiEnvironment environment) { - PullRequestInfo userInfo = - new PullRequestInfo( - config.getGitPullRequestBaseBranch(), - config.getGitPullRequestBaseBranchSha(), - config.getGitCommitHeadSha()); - - if (userInfo.isComplete()) { - return userInfo; + CiEnvironment environment, CIProviderInfo ciProviderInfo) { + PullRequestInfo ciProviderPrInfo = ciProviderInfo.buildPullRequestInfo(); + if (ciProviderPrInfo.isNotEmpty()) { + return ciProviderPrInfo; } - // logs-backend specific vars - PullRequestInfo ddCiInfo = - new PullRequestInfo( - null, - environment.get(Constants.DDCI_PULL_REQUEST_TARGET_SHA), - environment.get(Constants.DDCI_PULL_REQUEST_SOURCE_SHA)); - - return PullRequestInfo.merge(userInfo, ddCiInfo); + // could not get PR info from CI provider, + // check if it was set manually + return new PullRequestInfo( + null, + environment.get(Constants.DDCI_PULL_REQUEST_TARGET_SHA), + environment.get(Constants.DDCI_PULL_REQUEST_SOURCE_SHA)); } private static String getRepoRoot(CIInfo ciInfo, GitClient.Factory gitClientFactory) { diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java index 224082cd629..3657766e312 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java @@ -83,7 +83,7 @@ public CIInfo buildCIInfo() { @Nonnull @Override public PullRequestInfo buildPullRequestInfo() { - return new PullRequestInfo(environment.get(APPVEYOR_REPO_BRANCH), null, null); + return PullRequestInfo.EMPTY; } private String buildGitBranch(final String repoProvider) { diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java index a8ac3e79286..bbda148a978 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java @@ -26,7 +26,6 @@ class BitBucketInfo implements CIProviderInfo { public static final String BITBUCKET_GIT_COMMIT = "BITBUCKET_COMMIT"; public static final String BITBUCKET_GIT_BRANCH = "BITBUCKET_BRANCH"; public static final String BITBUCKET_GIT_TAG = "BITBUCKET_TAG"; - public static final String BITBUCKET_PR_DESTINATION_BRANCH = "BITBUCKET_PR_DESTINATION_BRANCH"; private final CiEnvironment environment; @@ -75,7 +74,7 @@ public CIInfo buildCIInfo() { @Nonnull @Override public PullRequestInfo buildPullRequestInfo() { - return new PullRequestInfo(environment.get(BITBUCKET_PR_DESTINATION_BRANCH), null, null); + return PullRequestInfo.EMPTY; } private String buildPipelineUrl(final String repo, final String number) { diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java index 3238313749a..4ae853c55e4 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java @@ -27,7 +27,6 @@ class BuddyInfo implements CIProviderInfo { public static final String BUDDY_GIT_COMMIT_MESSAGE = "BUDDY_EXECUTION_REVISION_MESSAGE"; public static final String BUDDY_GIT_COMMIT_AUTHOR = "BUDDY_EXECUTION_REVISION_COMMITTER_NAME"; public static final String BUDDY_GIT_COMMIT_EMAIL = "BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL"; - public static final String BUDDY_RUN_PR_BASE_BRANCH = "BUDDY_RUN_PR_BASE_BRANCH"; private final CiEnvironment environment; @@ -63,7 +62,7 @@ public CIInfo buildCIInfo() { @Nonnull @Override public PullRequestInfo buildPullRequestInfo() { - return new PullRequestInfo(BUDDY_RUN_PR_BASE_BRANCH, null, null); + return PullRequestInfo.EMPTY; } private String getPipelineId(String pipelineNumber) { diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/PullRequestInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/PullRequestInfo.java index 54a4a96c609..7365f8f824a 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/PullRequestInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/PullRequestInfo.java @@ -36,32 +36,6 @@ public boolean isNotEmpty() { || Strings.isNotBlank(gitCommitHeadSha); } - public boolean isComplete() { - return Strings.isNotBlank(pullRequestBaseBranch) - && Strings.isNotBlank(pullRequestBaseBranchSha) - && Strings.isNotBlank(gitCommitHeadSha); - } - - /** - * Merges info by completing the empty information fields with the fallback's - * - * @param info Base PR info - * @param fallback Fallback PR info - * @return Completed PR info - */ - public static PullRequestInfo merge(PullRequestInfo info, PullRequestInfo fallback) { - return new PullRequestInfo( - Strings.isNotBlank(info.pullRequestBaseBranch) - ? info.pullRequestBaseBranch - : fallback.pullRequestBaseBranch, - Strings.isNotBlank(info.pullRequestBaseBranchSha) - ? info.pullRequestBaseBranchSha - : fallback.pullRequestBaseBranchSha, - Strings.isNotBlank(info.gitCommitHeadSha) - ? info.gitCommitHeadSha - : fallback.gitCommitHeadSha); - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java b/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java index d7ab9ad204a..30bb443de82 100644 --- a/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java +++ b/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java @@ -85,11 +85,6 @@ public final class CiVisibilityConfig { public static final String TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES = "test.management.attempt.to.fix.retries"; - /* Git PR info */ - public static final String GIT_PULL_REQUEST_BASE_BRANCH = "git.pull.request.base.branch"; - public static final String GIT_PULL_REQUEST_BASE_BRANCH_SHA = "git.pull.request.base.branch.sha"; - public static final String GIT_COMMIT_HEAD_SHA = "git.commit.head.sha"; - /* COVERAGE SETTINGS */ public static final String CIVISIBILITY_CODE_COVERAGE_ENABLED = "civisibility.code.coverage.enabled"; diff --git a/internal-api/src/main/java/datadog/trace/api/Config.java b/internal-api/src/main/java/datadog/trace/api/Config.java index 81f9fd08028..169e68bc0ec 100644 --- a/internal-api/src/main/java/datadog/trace/api/Config.java +++ b/internal-api/src/main/java/datadog/trace/api/Config.java @@ -384,9 +384,6 @@ public static String getHostName() { private final boolean ciVisibilityTestManagementEnabled; private final Integer ciVisibilityTestManagementAttemptToFixRetries; private final boolean ciVisibilityScalatestForkMonitorEnabled; - private final String gitPullRequestBaseBranch; - private final String gitPullRequestBaseBranchSha; - private final String gitCommitHeadSha; private final boolean remoteConfigEnabled; private final boolean remoteConfigIntegrityCheckEnabled; @@ -1616,9 +1613,6 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment()) configProvider.getInteger(TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES); ciVisibilityScalatestForkMonitorEnabled = configProvider.getBoolean(CIVISIBILITY_SCALATEST_FORK_MONITOR_ENABLED, false); - gitPullRequestBaseBranch = configProvider.getString(GIT_PULL_REQUEST_BASE_BRANCH); - gitPullRequestBaseBranchSha = configProvider.getString(GIT_PULL_REQUEST_BASE_BRANCH_SHA); - gitCommitHeadSha = configProvider.getString(GIT_COMMIT_HEAD_SHA); remoteConfigEnabled = configProvider.getBoolean( @@ -3182,18 +3176,6 @@ public Integer getCiVisibilityTestManagementAttemptToFixRetries() { return ciVisibilityTestManagementAttemptToFixRetries; } - public String getGitPullRequestBaseBranch() { - return gitPullRequestBaseBranch; - } - - public String getGitPullRequestBaseBranchSha() { - return gitPullRequestBaseBranchSha; - } - - public String getGitCommitHeadSha() { - return gitCommitHeadSha; - } - public String getAppSecRulesFile() { return appSecRulesFile; } From 4d1888763327e3f0674095727917bd4116c761d3 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Mon, 2 Jun 2025 11:26:25 +0200 Subject: [PATCH 10/28] Revert "include pr info checks to CITagsProviderTest" This reverts commit e40154996d83ab7c7d49961fe8f83afd0e1af64e. --- .../civisibility/ci/AppVeyorInfoTest.groovy | 14 ------------- .../civisibility/ci/BitBucketInfoTest.groovy | 14 ------------- .../civisibility/ci/BuddyInfoTest.groovy | 14 ------------- .../civisibility/ci/CITagsProviderTest.groovy | 20 ------------------- .../civisibility/ci/GitLabInfoTest.groovy | 16 --------------- .../ci/GithubActionsInfoTest.groovy | 19 +++++++++--------- 6 files changed, 10 insertions(+), 87 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/AppVeyorInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/AppVeyorInfoTest.groovy index e86cead5130..60ec9df0e8f 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/AppVeyorInfoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/AppVeyorInfoTest.groovy @@ -24,18 +24,4 @@ class AppVeyorInfoTest extends CITagsProviderTest { map.put(AppVeyorInfo.APPVEYOR_REPO_COMMIT, "0000000000000000000000000000000000000000") return map } - - @Override - void setupPullRequestInfoBuild() { - environmentVariables.set(AppVeyorInfo.APPVEYOR_REPO_BRANCH, "base-branch") - } - - @Override - PullRequestInfo expectedPullRequestInfo() { - return new PullRequestInfo( - "base-branch", - null, - null, - ) - } } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BitBucketInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BitBucketInfoTest.groovy index 5d61e6b2463..5b21890c8b2 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BitBucketInfoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BitBucketInfoTest.groovy @@ -23,18 +23,4 @@ class BitBucketInfoTest extends CITagsProviderTest { map.put(BitBucketInfo.BITBUCKET_GIT_COMMIT, "0000000000000000000000000000000000000000") return map } - - @Override - void setupPullRequestInfoBuild() { - environmentVariables.set(BitBucketInfo.BITBUCKET_PR_DESTINATION_BRANCH, "base-branch") - } - - @Override - PullRequestInfo expectedPullRequestInfo() { - return new PullRequestInfo( - "base-branch", - null, - null, - ) - } } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BuddyInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BuddyInfoTest.groovy index 8198f4b0ae0..ae95013edd7 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BuddyInfoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/BuddyInfoTest.groovy @@ -22,20 +22,6 @@ class BuddyInfoTest extends CITagsProviderTest { return map } - @Override - void setupPullRequestInfoBuild() { - environmentVariables.set(BuddyInfo.BUDDY_RUN_PR_BASE_BRANCH, "base-branch") - } - - @Override - PullRequestInfo expectedPullRequestInfo() { - return new PullRequestInfo( - "base-branch", - null, - null - ) - } - boolean isWorkspaceAwareCi() { false } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy index 11f86b2f129..d22f7542803 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/CITagsProviderTest.groovy @@ -158,28 +158,8 @@ abstract class CITagsProviderTest extends Specification { } } - def "test pull request info building"() { - setup: - setupPullRequestInfoBuild() - - expect: - if (isCi()) { - CIProviderInfoFactory ciProviderInfoFactory = new CIProviderInfoFactory(Config.get(), GIT_FOLDER_FOR_TESTS, new CiEnvironmentImpl(System.getenv())) - def ciProviderInfo = ciProviderInfoFactory.createCIProviderInfo(getWorkspacePath()) - def actualPullRequestInfo = ciProviderInfo.buildPullRequestInfo() - - actualPullRequestInfo == expectedPullRequestInfo() - } - } - abstract String getProviderName() - void setupPullRequestInfoBuild() {} - - PullRequestInfo expectedPullRequestInfo() { - return PullRequestInfo.EMPTY - } - Map buildRemoteGitInfoEmpty() { return new HashMap() } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GitLabInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GitLabInfoTest.groovy index 758fa21fde5..b4a504c3092 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GitLabInfoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GitLabInfoTest.groovy @@ -23,20 +23,4 @@ class GitLabInfoTest extends CITagsProviderTest { map.put(GitLabInfo.GITLAB_GIT_COMMIT, "0000000000000000000000000000000000000000") return map } - - @Override - void setupPullRequestInfoBuild() { - environmentVariables.set(GitLabInfo.GITLAB_PULL_REQUEST_BASE_BRANCH, "base-branch") - environmentVariables.set(GitLabInfo.GITLAB_PULL_REQUEST_BASE_BRANCH_SHA, "cab317e178b740e6cb651dd7486bd925338b2843") - environmentVariables.set(GitLabInfo.GITLAB_PULL_REQUEST_COMMIT_HEAD_SHA, "b861e7fbb94b4949972b528ff7315c329e36092c") - } - - @Override - PullRequestInfo expectedPullRequestInfo() { - return new PullRequestInfo( - "base-branch", - "cab317e178b740e6cb651dd7486bd925338b2843", - "b861e7fbb94b4949972b528ff7315c329e36092c" - ) - } } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy index 7c9422e26cc..ca5e905e0a7 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/GithubActionsInfoTest.groovy @@ -1,5 +1,6 @@ package datadog.trace.civisibility.ci +import datadog.trace.civisibility.ci.env.CiEnvironmentImpl import java.nio.file.Paths @@ -27,20 +28,20 @@ class GithubActionsInfoTest extends CITagsProviderTest { return map } - @Override - void setupPullRequestInfoBuild() { + def "test pull request info parsing"() { + setup: def githubEvent = GithubActionsInfoTest.getResource("/ci/github-event.json") def githubEventPath = Paths.get(githubEvent.toURI()) environmentVariables.set(GithubActionsInfo.GITHUB_BASE_REF, "base-ref") environmentVariables.set(GithubActionsInfo.GITHUB_EVENT_PATH, githubEventPath.toString()) - } - @Override - PullRequestInfo expectedPullRequestInfo() { - return new PullRequestInfo( - "base-ref", - "52e0974c74d41160a03d59ddc73bb9f5adab054b", - "df289512a51123083a8e6931dd6f57bb3883d4c4") + when: + def pullRequestInfo = new GithubActionsInfo(new CiEnvironmentImpl(System.getenv())).buildPullRequestInfo() + + then: + pullRequestInfo.pullRequestBaseBranch == "base-ref" + pullRequestInfo.pullRequestBaseBranchSha == "52e0974c74d41160a03d59ddc73bb9f5adab054b" + pullRequestInfo.gitCommitHeadSha == "df289512a51123083a8e6931dd6f57bb3883d4c4" } } From 84e1c0f5e4db8b9c2db671ca6c0a42461fadfd0c Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Mon, 2 Jun 2025 11:26:28 +0200 Subject: [PATCH 11/28] Revert "add tests for prinfo merging" This reverts commit 63e72366048332846824c8db4ca06085bfb1b2a8. --- .../git/tree/GitDataUploaderImpl.java | 3 ++- .../civisibility/git/tree/GitRepoUnshallow.java | 2 ++ .../civisibility/ci/PullRequestInfoTest.groovy | 16 ---------------- 3 files changed, 4 insertions(+), 17 deletions(-) delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/PullRequestInfoTest.groovy diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java index 5cbc46a51c9..458b6cb7c66 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java @@ -112,7 +112,8 @@ private void uploadGitData() { return; } - if (config.isCiVisibilityGitUnshallowDefer() && gitRepoUnshallow.unshallow()) { + if (config.isCiVisibilityGitUnshallowDefer() + && gitRepoUnshallow.unshallow()) { latestCommits = gitClient.getLatestCommits(); commitsToSkip = gitDataApi.searchCommits(remoteUrl, latestCommits); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java index 489e2a4d377..5638ce6691c 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java @@ -3,6 +3,8 @@ import datadog.trace.api.Config; import datadog.trace.civisibility.utils.ShellCommandExecutor; import java.io.IOException; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; import java.util.concurrent.TimeoutException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/PullRequestInfoTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/PullRequestInfoTest.groovy deleted file mode 100644 index 347b1ad6d86..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ci/PullRequestInfoTest.groovy +++ /dev/null @@ -1,16 +0,0 @@ -package datadog.trace.civisibility.ci - -import spock.lang.Specification - -class PullRequestInfoTest extends Specification { - def "test merging of informations"() { - PullRequestInfo.merge(infoA, infoB) == result - - where: - infoA | infoB | result - new PullRequestInfo("branchA", "a", "a") | new PullRequestInfo("branchB", "b", "b") | new PullRequestInfo("branchA", "a", "a") - new PullRequestInfo(null, null, null) | new PullRequestInfo("branchB", "b", "b") | new PullRequestInfo("branchB", "b", "b") - new PullRequestInfo("branchA", null, null) | new PullRequestInfo("branchB", "b", "b") | new PullRequestInfo("branchA", "b", "b") - new PullRequestInfo("branchA", null, null) | new PullRequestInfo(null, null, null) | new PullRequestInfo("branchA", null, null) - } -} From ec152b6fccb4bf941eb8a11327b25ab811bbc6fa Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Mon, 2 Jun 2025 16:32:21 +0200 Subject: [PATCH 12/28] base commit sha algorithm implementation --- .../civisibility/git/tree/GitClient.java | 4 + .../git/tree/GitDataUploaderImpl.java | 3 +- .../git/tree/GitRepoUnshallow.java | 2 - .../civisibility/git/tree/NoOpGitClient.java | 6 + .../civisibility/git/tree/ShellGitClient.java | 351 +++++++++++++++++- .../git/tree/GitClientTest.groovy | 145 +++++++- .../civisibility/telemetry/tag/Command.java | 1 + 7 files changed, 495 insertions(+), 17 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitClient.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitClient.java index 41e9cc9ee10..2143fe35b4b 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitClient.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitClient.java @@ -72,6 +72,10 @@ List getObjects(Collection commitsToSkip, Collection com Path createPackFiles(List objectHashes) throws IOException, TimeoutException, InterruptedException; + @Nullable + String getBaseCommitSha(@Nullable String baseBranch, @Nullable String defaultBranch) + throws IOException, TimeoutException, InterruptedException; + @Nullable LineDiff getGitDiff(String baseCommit, String targetCommit) throws IOException, TimeoutException, InterruptedException; diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java index 458b6cb7c66..5cbc46a51c9 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitDataUploaderImpl.java @@ -112,8 +112,7 @@ private void uploadGitData() { return; } - if (config.isCiVisibilityGitUnshallowDefer() - && gitRepoUnshallow.unshallow()) { + if (config.isCiVisibilityGitUnshallowDefer() && gitRepoUnshallow.unshallow()) { latestCommits = gitClient.getLatestCommits(); commitsToSkip = gitDataApi.searchCommits(remoteUrl, latestCommits); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java index 5638ce6691c..489e2a4d377 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/GitRepoUnshallow.java @@ -3,8 +3,6 @@ import datadog.trace.api.Config; import datadog.trace.civisibility.utils.ShellCommandExecutor; import java.io.IOException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; import java.util.concurrent.TimeoutException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/NoOpGitClient.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/NoOpGitClient.java index c030fc7442f..1ec0f2ecf8a 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/NoOpGitClient.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/NoOpGitClient.java @@ -126,6 +126,12 @@ public Path createPackFiles(List objectHashes) { return null; } + @Nullable + @Override + public String getBaseCommitSha(@Nullable String baseBranch, @Nullable String defaultBranch) { + return null; + } + @Nullable @Override public LineDiff getGitDiff(String baseCommit, String targetCommit) { diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java index 4d78112a646..db82e1763d4 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java @@ -16,11 +16,17 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.concurrent.TimeoutException; +import java.util.regex.Pattern; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.slf4j.Logger; @@ -31,6 +37,11 @@ public class ShellGitClient implements GitClient { private static final Logger LOGGER = LoggerFactory.getLogger(ShellGitClient.class); private static final String DD_TEMP_DIRECTORY_PREFIX = "dd-ci-vis-"; + private static final List POSSIBLE_BASE_BRANCHES = + Arrays.asList("main", "master", "preprod", "prod", "dev", "development", "trunk"); + private static final Pattern BASE_BRANCH_PATTERN = + Pattern.compile("^(" + String.join("|", POSSIBLE_BASE_BRANCHES) + "|release/.*|hotfix/.*)$"); + private static final String ORIGIN = "origin"; private final CiVisibilityMetricCollector metricCollector; private final String repoRoot; @@ -573,6 +584,328 @@ private Path createTempDirectory() throws IOException { } } + /** + * Returns best effort base commit SHA for the most likely base branch in a PR. + * + * @param baseBranch Base branch name (if available will skip all logic that evaluates branch + * candidates) + * @param settingsDefaultBranch Default branch name obtained from the settings endpoint + * @return Base branch SHA if found or {@code null} otherwise + * @throws IOException If an error was encountered while writing command input or reading output + * @throws TimeoutException If timeout was reached while waiting for Git command to finish + * @throws InterruptedException If current thread was interrupted while waiting for Git command to + * finish + */ + @Nullable + @Override + public String getBaseCommitSha( + @Nullable String baseBranch, @Nullable String settingsDefaultBranch) + throws IOException, TimeoutException, InterruptedException { + return executeCommand( + Command.BASE_COMMIT_SHA, + () -> { + String remoteName = getRemoteName(); + LOGGER.debug("Remote name: {}", remoteName); + + String sourceBranch = getSourceBranch(); + if (sourceBranch == null) { + return null; + } + LOGGER.debug("Source branch: {}", sourceBranch); + + String defaultBranch = + Strings.isNotBlank(settingsDefaultBranch) + ? settingsDefaultBranch + : detectDefaultBranch(remoteName); + + List possibleBaseBranches = + baseBranch == null ? POSSIBLE_BASE_BRANCHES : Collections.singletonList(baseBranch); + checkAndFetchBaseBranches(possibleBaseBranches, remoteName); + + List candidates = getBaseBranchCandidates(baseBranch, sourceBranch, remoteName); + if (candidates.isEmpty()) { + LOGGER.debug("No base branch candidates found"); + return null; + } + + String baseSha; + if (candidates.size() == 1) { + baseSha = getCommonAncestor(candidates.get(0), sourceBranch); + } else { + // select best candidate based on "ahead" metrics + Map metrics = computeBranchMetrics(candidates, sourceBranch); + baseSha = findBestBranchSha(metrics, defaultBranch, remoteName); + } + + return baseSha; + }); + } + + public String getRemoteName() throws IOException, InterruptedException, TimeoutException { + try { + String remote = + commandExecutor + .executeCommand( + IOUtils::readFully, + "git", + "rev-parse", + "--abbrev-ref", + "--symbolic-full-name", + "@{upstream}") + .trim(); + + return remote.split("/")[0]; + } catch (ShellCommandExecutor.ShellCommandFailedException e) { + LOGGER.debug("Error getting remote from upstream", e); + } + + // fallback to first remote if no upstream + try { + List remotes = commandExecutor.executeCommand(IOUtils::readLines, "git", "remote"); + return remotes.get(0); + } catch (ShellCommandExecutor.ShellCommandFailedException e) { + LOGGER.debug("Error getting remotes", e); + } + return ORIGIN; + } + + @Nullable + public String getSourceBranch() throws IOException, InterruptedException, TimeoutException { + try { + return commandExecutor + .executeCommand(IOUtils::readFully, "git", "rev-parse", "--abbrev-ref", "HEAD") + .trim(); + } catch (ShellCommandExecutor.ShellCommandFailedException e) { + LOGGER.debug("Error getting source branch", e); + return null; + } + } + + public String removeRemotePrefix(String branch, String remoteName) { + return branch.replaceFirst("^" + remoteName + "/", ""); + } + + public boolean isBaseLikeBranch(String branch, String remoteName) { + // remove remote prefix + String shortBranchName = removeRemotePrefix(branch, remoteName); + + return BASE_BRANCH_PATTERN.matcher(shortBranchName).matches(); + } + + @Nullable + public String detectDefaultBranch(String remoteName) + throws IOException, InterruptedException, TimeoutException { + try { + String defaultRef = + commandExecutor + .executeCommand( + IOUtils::readFully, + "git", + "symbolic-ref", + "--quiet", + "--short", + "refs/remotes/" + remoteName + "/HEAD") + .trim(); + if (Strings.isNotBlank(defaultRef)) { + return removeRemotePrefix(defaultRef, remoteName); + } + } catch (ShellCommandExecutor.ShellCommandFailedException ignored) { + } + + LOGGER.debug("Could not get symbolic-ref, trying to find fallback"); + return findFallbackDefaultBranch(remoteName); + } + + @Nullable + public String findFallbackDefaultBranch(String remoteName) + throws IOException, InterruptedException, TimeoutException { + List fallbackBranches = Arrays.asList("main", "master"); + + for (String branch : fallbackBranches) { + try { + commandExecutor.executeCommand( + ShellCommandExecutor.OutputParser.IGNORE, + "git", + "show-ref", + "--verify", + "--quiet", + "refs/remotes/" + remoteName + "/" + branch); + LOGGER.debug("Found fallback default branch: {}", branch); + return branch; + } catch (ShellCommandExecutor.ShellCommandFailedException ignored) { + } + } + + return null; + } + + public void checkAndFetchBranch(String branch, String remoteName) + throws IOException, InterruptedException, TimeoutException { + try { + // check if branch exists locally + commandExecutor.executeCommand( + ShellCommandExecutor.OutputParser.IGNORE, + "git", + "show-ref", + "--verify", + "--quiet", + "refs/remotes/" + remoteName + "/" + branch); + LOGGER.debug("Branch {} exists locally, skipping fetch", branch); + return; + } catch (ShellCommandExecutor.ShellCommandFailedException e) { + LOGGER.debug("Branch {} does not exist locally, checking remote", branch, e); + } + + // check if branch exists in remote + String remoteHeads = + commandExecutor + .executeCommand(IOUtils::readFully, "git", "ls-remote", "--heads", remoteName, branch) + .trim(); + + if (remoteHeads.isEmpty()) { + LOGGER.debug("Branch {} does not exist in remote", branch); + return; + } + + // fetch latest commit for branch from remote + LOGGER.debug("Branch {} exists in remote, fetching", branch); + commandExecutor.executeCommand( + ShellCommandExecutor.OutputParser.IGNORE, + "git", + "fetch", + "--depth", + "1", + remoteName, + branch); + } + + public void checkAndFetchBaseBranches(List branches, String remoteName) + throws IOException, InterruptedException, TimeoutException { + for (String branch : branches) { + checkAndFetchBranch(branch, remoteName); + } + } + + public List getBaseBranchCandidates( + String baseBranch, String sourceBranch, String remoteName) + throws IOException, InterruptedException, TimeoutException { + if (baseBranch != null) { + return Collections.singletonList(baseBranch); + } + + List candidates = new ArrayList<>(); + try { + List branches = + commandExecutor.executeCommand( + IOUtils::readLines, + "git", + "for-each-ref", + "--format='%(refname:short)'", + "refs/remotes/" + remoteName); + for (String branch : branches) { + if (!branch.equals(sourceBranch) && isBaseLikeBranch(branch, remoteName)) { + candidates.add(branch); + } + } + } catch (ShellCommandExecutor.ShellCommandFailedException e) { + LOGGER.debug("Error building candidate branches", e); + } + + return candidates; + } + + public String getCommonAncestor(String candidateBranch, String sourceBranch) + throws IOException, InterruptedException, TimeoutException { + try { + return commandExecutor + .executeCommand(IOUtils::readFully, "git", "merge-base", candidateBranch, sourceBranch) + .trim(); + } catch (ShellCommandExecutor.ShellCommandFailedException e) { + LOGGER.debug( + "Error calculating common ancestor for {} and {}", candidateBranch, sourceBranch, e); + } + return null; + } + + public static class BaseBranchMetric { + private final int behind; + private final int ahead; + private final String baseSha; + + public BaseBranchMetric(int behind, int ahead, String baseSha) { + this.behind = behind; + this.ahead = ahead; + this.baseSha = baseSha; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof BaseBranchMetric)) return false; + BaseBranchMetric that = (BaseBranchMetric) o; + return behind == that.behind && ahead == that.ahead && Objects.equals(baseSha, that.baseSha); + } + + @Override + public int hashCode() { + return Objects.hash(behind, ahead, baseSha); + } + } + + public Map computeBranchMetrics( + List candidates, String sourceBranch) + throws IOException, InterruptedException, TimeoutException { + Map branchMetrics = new HashMap<>(); + + for (String candidate : candidates) { + String baseSha = getCommonAncestor(candidate, sourceBranch); + if (baseSha == null || baseSha.isEmpty()) { + continue; + } + + String countsResult = + commandExecutor + .executeCommand( + IOUtils::readFully, + "git", + "rev-list", + "--left-right", + "--count", + candidate + "..." + sourceBranch) + .trim(); + + String[] counts = countsResult.split("\\s+"); + int behind = Integer.parseInt(counts[0]); + int ahead = Integer.parseInt(counts[1]); + + branchMetrics.put(candidate, new BaseBranchMetric(behind, ahead, baseSha)); + } + + return branchMetrics; + } + + public boolean isDefaultBranch(String branch, @Nullable String defaultBranch, String remoteName) { + return defaultBranch != null + && (branch.equals(defaultBranch) || branch.equals(remoteName + "/" + defaultBranch)); + } + + public String findBestBranchSha( + Map metrics, String defaultBranch, String remoteName) { + if (metrics.isEmpty()) { + return null; + } + + // Find branch with smallest "ahead" value, prioritizing default branch on tie + Comparator> comparator = + Comparator.comparingInt((Map.Entry e) -> e.getValue().ahead) + .thenComparing( // negated to prioritize default branch on min search + e -> !isDefaultBranch(e.getKey(), defaultBranch, remoteName)); + + Map.Entry bestMetric = + metrics.entrySet().stream().min(comparator).orElse(null); + + return bestMetric != null ? bestMetric.getValue().baseSha : null; + } + /** * Returns Git diff between two commits. * @@ -588,7 +921,13 @@ private Path createTempDirectory() throws IOException { @Override public LineDiff getGitDiff(String baseCommit, String targetCommit) throws IOException, TimeoutException, InterruptedException { - if (Strings.isNotBlank(baseCommit) && Strings.isNotBlank(targetCommit)) { + if (!Strings.isNotBlank(baseCommit)) { + LOGGER.debug( + "Base commit and/or target commit info is not available, returning empty git diff: {}/{}", + baseCommit, + targetCommit); + return null; + } else if (Strings.isNotBlank(targetCommit)) { return executeCommand( Command.DIFF, () -> @@ -601,11 +940,11 @@ public LineDiff getGitDiff(String baseCommit, String targetCommit) baseCommit, targetCommit)); } else { - LOGGER.debug( - "Base commit and/or target commit info is not available, returning empty git diff: {}/{}", - baseCommit, - targetCommit); - return null; + return executeCommand( + Command.DIFF, + () -> + commandExecutor.executeCommand( + GitDiffParser::parse, "git", "diff", "-U0", "--word-diff=porcelain", baseCommit)); } } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy index 6dbb26c2565..bc1b200f2a9 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy @@ -1,17 +1,16 @@ package datadog.trace.civisibility.git.tree -import datadog.trace.civisibility.telemetry.CiVisibilityMetricCollectorImpl +import static datadog.trace.civisibility.TestUtils.lines + +import datadog.communication.util.IOUtils import datadog.trace.civisibility.git.GitObject import datadog.trace.civisibility.git.pack.V2PackGitInfoExtractor -import datadog.communication.util.IOUtils -import spock.lang.Specification -import spock.lang.TempDir - +import datadog.trace.civisibility.telemetry.CiVisibilityMetricCollectorImpl import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths - -import static datadog.trace.civisibility.TestUtils.lines +import spock.lang.Specification +import spock.lang.TempDir class GitClientTest extends Specification { @@ -329,6 +328,138 @@ class GitClientTest extends Specification { ] } + def "test remove remote prefix"() { + def gitClient = givenGitClient() + gitClient.removeRemotePrefix(branchName, remoteName) == expected + + where: + branchName | remoteName | expected + "origin/main" | "origin" | "main" + "upstream/master" | "upstream" | "master" + "origin/feature/test" | "origin" | "feature/test" + "main" | "origin" | "main" + "upstream/main" | "origin" | "upstream/main" + "" | "origin" | "" + } + + def "test base like branch match"() { + def gitClient = givenGitClient() + gitClient.isBaseLikeBranch(branchName, remoteName) == expected + + where: + branchName | remoteName | expected + "main" | "origin" | true + "master" | "origin" | true + "preprod" | "origin" | true + "prod" | "origin" | true + "dev" | "origin" | true + "development" | "origin" | true + "trunk" | "origin" | true + "release/v1.0" | "origin" | true + "release/2023.1" | "origin" | true + "hotfix/critical" | "origin" | true + "hotfix/bug-123" | "origin" | true + "origin/main" | "origin" | true + "origin/master" | "origin" | true + "upstream/main" | "upstream" | true + "feature/test" | "origin" | false + "bugfix/issue-123" | "origin" | false + "update/dependencies" | "origin" | false + "my-feature-branch" | "origin" | false + "" | "origin" | false + "main-backup" | "origin" | false + "maintenance" | "origin" | false + } + + def "test is default branch"() { + def gitClient = givenGitClient() + gitClient.isDefaultBranch(branch, defaultBranch, remoteName) == expected + + where: + branch | defaultBranch | remoteName | expected + "main" | "main" | "origin" | true + "master" | "master" | "origin" | true + "origin/main" | "main" | "origin" | true + "upstream/master" | "master" | "upstream" | true + "feature/test" | "main" | "origin" | false + "origin/feature" | "main" | "origin" | false + "main" | "master" | "origin" | false + "main" | null | "origin" | false + } + + def "test get remote name"() { + givenGitRepo(repoPath) + def gitClient = givenGitClient() + gitClient.getRemoteName() == remoteName + + where: + repoPath | remoteName + "ci/git/impacted/git" | "origin" + "ci/git/with_pack/git" | "origin" // fallback on ambiguous upstream + } + + def "test get source branch"() { + given: + givenGitRepo("ci/git/impacted/git") + def gitClient = givenGitClient() + + when: + def branch = gitClient.getSourceBranch() + + then: + branch == "feature/source" + } + + def "test detect default branch"() { + givenGitRepo() + def gitClient = givenGitClient() + gitClient.detectDefaultBranch("origin") == "master" + } + + def "test compute branch metrics"() { + given: + givenGitRepo("ci/git/impacted/git") + def gitClient = givenGitClient() + + when: + def metrics = gitClient.computeBranchMetrics(["master", "origin/master"], "feature/source") + + then: + metrics == [ + "master" : new ShellGitClient.BaseBranchMetric(1, 1, "2ae4709da8155737b36d480722c57bab906a4f00"), + "origin/master": new ShellGitClient.BaseBranchMetric(1, 1, "2ae4709da8155737b36d480722c57bab906a4f00")] + } + + def "test find best branch sha"() { + def gitClient = givenGitClient() + gitClient.findBestBranchSha(metrics, "main", "origin") == expected + + where: + metrics | expected + [ + "main" : new ShellGitClient.BaseBranchMetric(10, 2, "sha1"), + "master" : new ShellGitClient.BaseBranchMetric(15, 1, "sha2"), + "origin/main": new ShellGitClient.BaseBranchMetric(5, 2, "sha3")] | "sha2" + [ + "main" : new ShellGitClient.BaseBranchMetric(10, 2, "sha1"), + "master" : new ShellGitClient.BaseBranchMetric(15, 2, "sha2"), + "origin/main": new ShellGitClient.BaseBranchMetric(5, 2, "sha3")] | "sha3" + [:] | null + } + + def "test get base branch sha"() { + givenGitRepo("ci/git/impacted/git") + def gitClient = givenGitClient() + + gitClient.getBaseCommitSha(baseBranch, defaultBranch) == expected + + where: + baseBranch | defaultBranch | expected + "master" | "master" | "2ae4709da8155737b36d480722c57bab906a4f00" + "master" | null | "2ae4709da8155737b36d480722c57bab906a4f00" + null | null | "2ae4709da8155737b36d480722c57bab906a4f00" + } + private void givenGitRepo() { givenGitRepo("ci/git/with_pack/git") } diff --git a/internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/tag/Command.java b/internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/tag/Command.java index 7b0fa25efd3..0413066d100 100644 --- a/internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/tag/Command.java +++ b/internal-api/src/main/java/datadog/trace/api/civisibility/telemetry/tag/Command.java @@ -12,6 +12,7 @@ public enum Command implements TagValue { GET_OBJECTS, PACK_OBJECTS, DIFF, + BASE_COMMIT_SHA, OTHER; private final String s; From 1e843af251760dbe16e2120091c9f5e860a03578 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Mon, 2 Jun 2025 16:33:01 +0200 Subject: [PATCH 13/28] example git repo for base commit sha testing --- .../test/resources/ci/git/impacted/README.md | 2 ++ .../src/test/resources/ci/git/impacted/git/HEAD | 1 + .../test/resources/ci/git/impacted/git/config | 16 ++++++++++++++++ .../0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 | Bin 0 -> 43 bytes .../17/6f8635f95d63e924c30e5e9b7abeeeedf54d8a | Bin 0 -> 31 bytes .../2a/e4709da8155737b36d480722c57bab906a4f00 | 2 ++ .../5f/cf9693c480d770583779a67bae94ca379a0cfa | Bin 0 -> 54 bytes .../6c/75724a3f6ac016736dfae8c684c269a57d201e | Bin 0 -> 415 bytes .../7e/7fbbe44883d25f3f5207819b9f44a5093248c9 | Bin 0 -> 54 bytes .../c4/795aab1c04211706f11edac18e059905a80790 | 2 ++ .../f1/3dd20ed84d937f11a6dec2a95be2dfbe7a407f | Bin 0 -> 49 bytes .../f3/b7c4615f1990980108cec313d98dfd3250f323 | Bin 0 -> 53 bytes .../git/impacted/git/refs/heads/feature/source | 1 + .../ci/git/impacted/git/refs/heads/master | 1 + .../git/impacted/git/refs/remotes/origin/HEAD | 1 + .../git/refs/remotes/origin/feature/source | 1 + .../git/impacted/git/refs/remotes/origin/master | 1 + 17 files changed, 28 insertions(+) create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/README.md create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/HEAD create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/config create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/17/6f8635f95d63e924c30e5e9b7abeeeedf54d8a create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/2a/e4709da8155737b36d480722c57bab906a4f00 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/5f/cf9693c480d770583779a67bae94ca379a0cfa create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/6c/75724a3f6ac016736dfae8c684c269a57d201e create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/7e/7fbbe44883d25f3f5207819b9f44a5093248c9 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/c4/795aab1c04211706f11edac18e059905a80790 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/f1/3dd20ed84d937f11a6dec2a95be2dfbe7a407f create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/f3/b7c4615f1990980108cec313d98dfd3250f323 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/refs/heads/feature/source create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/refs/heads/master create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/refs/remotes/origin/HEAD create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/refs/remotes/origin/feature/source create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/refs/remotes/origin/master diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/README.md b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/README.md new file mode 100644 index 00000000000..0a3fe8f1bf6 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/README.md @@ -0,0 +1,2 @@ +# Example repo +Some change diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/HEAD new file mode 100644 index 00000000000..910cf56841e --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/feature/source diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/config b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/config new file mode 100644 index 00000000000..8ac856be458 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/config @@ -0,0 +1,16 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true + precomposeunicode = true +[remote "origin"] + url = /Users/daniel.mohedano/dd/git-playground/origin.git + fetch = +refs/heads/*:refs/remotes/origin/* +[branch "master"] + remote = origin + merge = refs/heads/master +[branch "feature/source"] + remote = origin + merge = refs/heads/feature/source diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 new file mode 100644 index 0000000000000000000000000000000000000000..d5dc253bc5193a097af0d31686bf7531ce9bf082 GIT binary patch literal 43 zcmb9XD~D{Ff%bx2y%6F@paY9O<@qvZ!`TFoBUGcFkjs4s(tU? Me)a7F05tp%=Pg4RPyhe` literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/6c/75724a3f6ac016736dfae8c684c269a57d201e b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/6c/75724a3f6ac016736dfae8c684c269a57d201e new file mode 100644 index 0000000000000000000000000000000000000000..24d9b50841bee37e52c9c91e92aa34973e94b560 GIT binary patch literal 415 zcmV;Q0bu@k0j-cvbDJ;_#e3#c=$>gJAwbY+JH_UYaSW~lI4(CK32+Sp6FGJK=?iI( zJ$7ey=k0H1-@IAYcim9|)5agvCsTA; zD5L^96$XJ0r#3Q8f=P)jZrG6MIx|U0O9xuis36qnMK%2hJSvZ(1##a9PGt{1PjdqI z-CyvHQ$=}SH|KlScV7V_hHarKh6(PVKKV>^3arF`u&RgpAm%AIRBwHME7!*J4Xp7*EtXO80RG_yJlP11%mbh@xgqq49qw&Fp) zJ{>f$*vNG|>Ov+ohIm#8hg2ql?sYG9_j zb+RYP!T&Cu_Vu~;f?{|W!ylJpHFRowH>mn7)!XAswot4JHrIXm`WRhzuKslG>~tGP zdkxfAXSHR&-bi8OhlilKol`gdqWyV?pLqXzhE@rxJ^{)(U=5YE0KEh=yNm*qBbBVt Jegmnhvn?`N#^eA1 literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/7e/7fbbe44883d25f3f5207819b9f44a5093248c9 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/7e/7fbbe44883d25f3f5207819b9f44a5093248c9 new file mode 100644 index 0000000000000000000000000000000000000000..167bcebfc4319fe406108de7152b6009d3833160 GIT binary patch literal 54 zcmbdyCV@1Im1O#RNcwx_P7K7OjR KErZ(v!F~WdoEHoL literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/c4/795aab1c04211706f11edac18e059905a80790 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/c4/795aab1c04211706f11edac18e059905a80790 new file mode 100644 index 00000000000..4bbcdf05bf0 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/c4/795aab1c04211706f11edac18e059905a80790 @@ -0,0 +1,2 @@ +xM0{W^;6U[5bȂhRn aL`m=vHj4m[MPn*E*3rFAtH2SXh:f Ra +\2D5hjs T&\K\@ɧ_-J5 *]>u_%|3@5bQL'ʡ-u'@ Dwk F‹an8i3CG<(ꅕ!'ᒛ-/B/M:s]Oݾ/.v7obi6&3yF qjC"rz K6:#;4tEbWsKo=SDM <_ǧ}+p(\ Q+9#C+fr_٘ \ No newline at end of file diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/f1/3dd20ed84d937f11a6dec2a95be2dfbe7a407f b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/f1/3dd20ed84d937f11a6dec2a95be2dfbe7a407f new file mode 100644 index 0000000000000000000000000000000000000000..d7bd64bd0410caacc826e6d14cee3f16355327cd GIT binary patch literal 49 zcmV-10M7q-0ZYosPf{>8W>8jetw_u*$VpWwN-fCe^2jgIP0OrM$j?*AO)M@+E#d+I H4&n`G9dZ?7 literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/f3/b7c4615f1990980108cec313d98dfd3250f323 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/f3/b7c4615f1990980108cec313d98dfd3250f323 new file mode 100644 index 0000000000000000000000000000000000000000..08808775b173d1961aff80df42a948ad6bf78f98 GIT binary patch literal 53 zcmb Date: Mon, 2 Jun 2025 17:06:17 +0200 Subject: [PATCH 14/28] simplify algo implementation for easier read --- .../civisibility/git/tree/ShellGitClient.java | 54 ++++++------------- 1 file changed, 15 insertions(+), 39 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java index db82e1763d4..4f3f8e739e1 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java @@ -613,31 +613,28 @@ public String getBaseCommitSha( } LOGGER.debug("Source branch: {}", sourceBranch); + if (baseBranch != null) { + return getCommonAncestor(baseBranch, sourceBranch); + } + String defaultBranch = Strings.isNotBlank(settingsDefaultBranch) ? settingsDefaultBranch : detectDefaultBranch(remoteName); - List possibleBaseBranches = - baseBranch == null ? POSSIBLE_BASE_BRANCHES : Collections.singletonList(baseBranch); - checkAndFetchBaseBranches(possibleBaseBranches, remoteName); + for (String branch : POSSIBLE_BASE_BRANCHES) { + checkAndFetchBranch(branch, remoteName); + } - List candidates = getBaseBranchCandidates(baseBranch, sourceBranch, remoteName); + List candidates = getBaseBranchCandidates(sourceBranch, remoteName); if (candidates.isEmpty()) { LOGGER.debug("No base branch candidates found"); return null; } - String baseSha; - if (candidates.size() == 1) { - baseSha = getCommonAncestor(candidates.get(0), sourceBranch); - } else { - // select best candidate based on "ahead" metrics - Map metrics = computeBranchMetrics(candidates, sourceBranch); - baseSha = findBestBranchSha(metrics, defaultBranch, remoteName); - } - - return baseSha; + // select best candidate based on "ahead" metrics + Map metrics = computeBranchMetrics(candidates, sourceBranch); + return findBestBranchSha(metrics, defaultBranch, remoteName); }); } @@ -713,14 +710,7 @@ public String detectDefaultBranch(String remoteName) } LOGGER.debug("Could not get symbolic-ref, trying to find fallback"); - return findFallbackDefaultBranch(remoteName); - } - - @Nullable - public String findFallbackDefaultBranch(String remoteName) - throws IOException, InterruptedException, TimeoutException { List fallbackBranches = Arrays.asList("main", "master"); - for (String branch : fallbackBranches) { try { commandExecutor.executeCommand( @@ -742,7 +732,7 @@ public String findFallbackDefaultBranch(String remoteName) public void checkAndFetchBranch(String branch, String remoteName) throws IOException, InterruptedException, TimeoutException { try { - // check if branch exists locally + // check if branch exists locally as a remote ref commandExecutor.executeCommand( ShellCommandExecutor.OutputParser.IGNORE, "git", @@ -779,22 +769,11 @@ public void checkAndFetchBranch(String branch, String remoteName) branch); } - public void checkAndFetchBaseBranches(List branches, String remoteName) + public List getBaseBranchCandidates(String sourceBranch, String remoteName) throws IOException, InterruptedException, TimeoutException { - for (String branch : branches) { - checkAndFetchBranch(branch, remoteName); - } - } - - public List getBaseBranchCandidates( - String baseBranch, String sourceBranch, String remoteName) - throws IOException, InterruptedException, TimeoutException { - if (baseBranch != null) { - return Collections.singletonList(baseBranch); - } - List candidates = new ArrayList<>(); try { + // only consider remote branches List branches = commandExecutor.executeCommand( IOUtils::readLines, @@ -922,10 +901,7 @@ public String findBestBranchSha( public LineDiff getGitDiff(String baseCommit, String targetCommit) throws IOException, TimeoutException, InterruptedException { if (!Strings.isNotBlank(baseCommit)) { - LOGGER.debug( - "Base commit and/or target commit info is not available, returning empty git diff: {}/{}", - baseCommit, - targetCommit); + LOGGER.debug("Base commit info is not available, returning empty git diff"); return null; } else if (Strings.isNotBlank(targetCommit)) { return executeCommand( From 67339e9045d5e2e40f517c92a1c2f5a2ee348e4c Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Mon, 2 Jun 2025 17:06:32 +0200 Subject: [PATCH 15/28] implement git diff based on best candidate for base commit sha --- .../config/ExecutionSettingsFactoryImpl.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java index ac96c18fc99..04ffda7c2e2 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ExecutionSettingsFactoryImpl.java @@ -213,7 +213,8 @@ private Map doCreate( getTestManagementTestsByModule( tracerEnvironment, testManagementSettings.isEnabled())); Future pullRequestDiffFuture = - executor.submit(() -> getPullRequestDiff(impactedTestsEnabled)); + executor.submit( + () -> getPullRequestDiff(impactedTestsEnabled, settings.getDefaultBranch())); SkippableTests skippableTests = skippableTestsFuture.get(); Map> flakyTestsByModule = flakyTestsFuture.get(); @@ -402,7 +403,7 @@ private Map>> getTestManagementTest } @Nonnull - private Diff getPullRequestDiff(boolean impactedTestsDetectionEnabled) { + private Diff getPullRequestDiff(boolean impactedTestsDetectionEnabled, String defaultBranch) { if (!impactedTestsDetectionEnabled) { return LineDiff.EMPTY; } @@ -411,15 +412,18 @@ private Diff getPullRequestDiff(boolean impactedTestsDetectionEnabled) { if (repositoryRoot != null) { // ensure repo is not shallow before attempting to get git diff gitRepoUnshallow.unshallow(); - Diff diff = - gitClient.getGitDiff( - pullRequestInfo.getPullRequestBaseBranchSha(), - pullRequestInfo.getGitCommitHeadSha()); + + String baseCommitSha = pullRequestInfo.getPullRequestBaseBranchSha(); + if (baseCommitSha == null) { + baseCommitSha = + gitClient.getBaseCommitSha(pullRequestInfo.getPullRequestBaseBranch(), defaultBranch); + } + + Diff diff = gitClient.getGitDiff(baseCommitSha, pullRequestInfo.getGitCommitHeadSha()); if (diff != null) { return diff; } } - } catch (InterruptedException e) { LOGGER.error("Interrupted while getting git diff for PR: {}", pullRequestInfo, e); Thread.currentThread().interrupt(); From bfd3ad495f803a6f1bc4f1d19722b0b3eada29f4 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Tue, 3 Jun 2025 18:41:24 +0200 Subject: [PATCH 16/28] add github actions cloning test --- .../test/resources/ci/git/github-clone/README.md | 2 ++ .../resources/ci/git/github-clone/git/FETCH_HEAD | 1 + .../test/resources/ci/git/github-clone/git/HEAD | 1 + .../test/resources/ci/git/github-clone/git/config | 13 +++++++++++++ .../0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 | Bin 0 -> 43 bytes .../17/6f8635f95d63e924c30e5e9b7abeeeedf54d8a | Bin 0 -> 31 bytes .../2a/e4709da8155737b36d480722c57bab906a4f00 | 2 ++ .../5f/cf9693c480d770583779a67bae94ca379a0cfa | Bin 0 -> 54 bytes .../6c/75724a3f6ac016736dfae8c684c269a57d201e | Bin 0 -> 415 bytes .../f3/b7c4615f1990980108cec313d98dfd3250f323 | Bin 0 -> 53 bytes .../github-clone/git/refs/heads/feature/source | 1 + .../git/refs/remotes/origin/feature/source | 1 + 12 files changed, 21 insertions(+) create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/README.md create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/FETCH_HEAD create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/HEAD create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/config create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/17/6f8635f95d63e924c30e5e9b7abeeeedf54d8a create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/2a/e4709da8155737b36d480722c57bab906a4f00 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/5f/cf9693c480d770583779a67bae94ca379a0cfa create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/6c/75724a3f6ac016736dfae8c684c269a57d201e create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/f3/b7c4615f1990980108cec313d98dfd3250f323 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/refs/heads/feature/source create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/refs/remotes/origin/feature/source diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/README.md b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/README.md new file mode 100644 index 00000000000..0a3fe8f1bf6 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/README.md @@ -0,0 +1,2 @@ +# Example repo +Some change diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/FETCH_HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/FETCH_HEAD new file mode 100644 index 00000000000..ec1516d27a9 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/FETCH_HEAD @@ -0,0 +1 @@ +6c75724a3f6ac016736dfae8c684c269a57d201e branch 'feature/source' of ../origin diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/HEAD new file mode 100644 index 00000000000..910cf56841e --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/feature/source diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/config b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/config new file mode 100644 index 00000000000..5ee77423067 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/config @@ -0,0 +1,13 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true + precomposeunicode = true +[remote "origin"] + url = ../origin.git + fetch = +refs/heads/*:refs/remotes/origin/* +[branch "feature/source"] + remote = origin + merge = refs/heads/feature/source diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 new file mode 100644 index 0000000000000000000000000000000000000000..d5dc253bc5193a097af0d31686bf7531ce9bf082 GIT binary patch literal 43 zcmb9XD~D{Ff%bx2y%6F@paY9O<@qvZ!`TFoBUGcFkjs4s(tU? Me)a7F05tp%=Pg4RPyhe` literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/6c/75724a3f6ac016736dfae8c684c269a57d201e b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/6c/75724a3f6ac016736dfae8c684c269a57d201e new file mode 100644 index 0000000000000000000000000000000000000000..24d9b50841bee37e52c9c91e92aa34973e94b560 GIT binary patch literal 415 zcmV;Q0bu@k0j-cvbDJ;_#e3#c=$>gJAwbY+JH_UYaSW~lI4(CK32+Sp6FGJK=?iI( zJ$7ey=k0H1-@IAYcim9|)5agvCsTA; zD5L^96$XJ0r#3Q8f=P)jZrG6MIx|U0O9xuis36qnMK%2hJSvZ(1##a9PGt{1PjdqI z-CyvHQ$=}SH|KlScV7V_hHarKh6(PVKKV>^3arF`u&RgpAm%AIRBwHME7!*J4Xp7*EtXO80RG_yJlP11%mbh@xgqq49qw&Fp) zJ{>f$*vNG|>Ov+ohIm#8hg2ql?sYG9_j zb+RYP!T&Cu_Vu~;f?{|W!ylJpHFRowH>mn7)!XAswot4JHrIXm`WRhzuKslG>~tGP zdkxfAXSHR&-bi8OhlilKol`gdqWyV?pLqXzhE@rxJ^{)(U=5YE0KEh=yNm*qBbBVt Jegmnhvn?`N#^eA1 literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/f3/b7c4615f1990980108cec313d98dfd3250f323 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/f3/b7c4615f1990980108cec313d98dfd3250f323 new file mode 100644 index 0000000000000000000000000000000000000000..08808775b173d1961aff80df42a948ad6bf78f98 GIT binary patch literal 53 zcmb Date: Wed, 4 Jun 2025 12:01:01 +0200 Subject: [PATCH 17/28] add several testing cases and cleaned up debug messages --- .../civisibility/git/tree/ShellGitClient.java | 21 ++- .../git/tree/GitClientTest.groovy | 46 +++-- .../resources/ci/git/github-clone/README.md | 2 - .../ci/git/github-clone/git/FETCH_HEAD | 1 - .../resources/ci/git/github-clone/git/HEAD | 1 - .../0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 | Bin 43 -> 0 bytes .../17/6f8635f95d63e924c30e5e9b7abeeeedf54d8a | Bin 31 -> 0 bytes .../2a/e4709da8155737b36d480722c57bab906a4f00 | 2 - .../5f/cf9693c480d770583779a67bae94ca379a0cfa | Bin 54 -> 0 bytes .../6c/75724a3f6ac016736dfae8c684c269a57d201e | Bin 415 -> 0 bytes .../f3/b7c4615f1990980108cec313d98dfd3250f323 | Bin 53 -> 0 bytes .../git/refs/heads/feature/source | 1 - .../git/refs/remotes/origin/feature/source | 1 - .../test/resources/ci/git/impacted/README.md | 2 - .../ci/git/impacted/build_script.txt | 55 ++++++ .../git/impacted/ghub_actions_clone/README.md | 3 + .../ghub_actions_clone/git/FETCH_HEAD | 1 + .../git/impacted/ghub_actions_clone/git/HEAD | 1 + .../ghub_actions_clone}/git/config | 6 +- .../02/fcc183ad25f086aaec562224abc1b323ebaaa9 | Bin 0 -> 400 bytes .../07/30f8c84174f476a9493f9d779640d7c971a2ef | Bin 0 -> 363 bytes .../1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 | Bin 0 -> 399 bytes .../3b/bf06262d9604dc0667c1e96b13fbf88f25a43f | Bin 0 -> 54 bytes .../82/ac08af7cb3071716559cc26257ee21dfc8e4d3 | Bin 0 -> 54 bytes .../95/e75d98dbaf42c1efc9be0405e079f97aa24888 | Bin 0 -> 32 bytes .../af/5626b4a114abcb82d63db7c8082c3c4756e51b | Bin 0 -> 30 bytes .../e0/dea118958b3ce7d0b353aaf37177a4eac87d59 | Bin 0 -> 54 bytes .../eb/fd7499dae526dcbaf30e1250b1f875946729f8 | Bin 0 -> 54 bytes .../ghub_actions_clone/git/refs/heads/feature | 1 + .../git/refs/remotes/origin/feature | 1 + .../test/resources/ci/git/impacted/git/HEAD | 1 - .../0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 | Bin 43 -> 0 bytes .../17/6f8635f95d63e924c30e5e9b7abeeeedf54d8a | Bin 31 -> 0 bytes .../2a/e4709da8155737b36d480722c57bab906a4f00 | 2 - .../5f/cf9693c480d770583779a67bae94ca379a0cfa | Bin 54 -> 0 bytes .../6c/75724a3f6ac016736dfae8c684c269a57d201e | Bin 415 -> 0 bytes .../7e/7fbbe44883d25f3f5207819b9f44a5093248c9 | Bin 54 -> 0 bytes .../c4/795aab1c04211706f11edac18e059905a80790 | 2 - .../f1/3dd20ed84d937f11a6dec2a95be2dfbe7a407f | Bin 49 -> 0 bytes .../f3/b7c4615f1990980108cec313d98dfd3250f323 | Bin 53 -> 0 bytes .../impacted/git/refs/heads/feature/source | 1 - .../ci/git/impacted/git/refs/heads/master | 1 - .../git/impacted/git/refs/remotes/origin/HEAD | 1 - .../git/refs/remotes/origin/feature/source | 1 - .../impacted/git/refs/remotes/origin/master | 1 - .../ci/git/impacted/new_clone/README.md | 3 + .../ci/git/impacted/new_clone/git/FETCH_HEAD | 1 + .../ci/git/impacted/new_clone/git/HEAD | 1 + .../git/impacted/{ => new_clone}/git/config | 8 +- .../02/fcc183ad25f086aaec562224abc1b323ebaaa9 | Bin 0 -> 400 bytes .../07/30f8c84174f476a9493f9d779640d7c971a2ef | Bin 0 -> 363 bytes .../1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 | Bin 0 -> 399 bytes .../3b/bf06262d9604dc0667c1e96b13fbf88f25a43f | Bin 0 -> 54 bytes .../82/ac08af7cb3071716559cc26257ee21dfc8e4d3 | Bin 0 -> 54 bytes .../95/e75d98dbaf42c1efc9be0405e079f97aa24888 | Bin 0 -> 32 bytes .../af/5626b4a114abcb82d63db7c8082c3c4756e51b | Bin 0 -> 30 bytes .../e0/dea118958b3ce7d0b353aaf37177a4eac87d59 | Bin 0 -> 54 bytes .../eb/fd7499dae526dcbaf30e1250b1f875946729f8 | Bin 0 -> 54 bytes .../impacted/new_clone/git/refs/heads/master | 1 + .../new_clone/git/refs/remotes/origin/feature | 1 + .../ci/git/impacted/no_remote/README.md | 1 + .../ci/git/impacted/no_remote/git/HEAD | 1 + .../ci/git/impacted/no_remote/git/config | 10 + .../a9/d9bdb3b83442c8e55b6dfd61b0790847720ee8 | Bin 0 -> 54 bytes .../ad/686ebdcb37b8660171e8df4b922e018f92f508 | Bin 0 -> 33 bytes .../d8/a57e1a0937c50c15cc7b9a3e39dc73a1249eaa | Bin 0 -> 364 bytes .../impacted/no_remote/git/refs/heads/master | 1 + .../ci/git/impacted/repo_origin/HEAD | 1 + .../ci/git/impacted/repo_origin/config | 6 + .../ci/git/impacted/repo_origin/description | 1 + .../repo_origin/hooks/applypatch-msg.sample | 15 ++ .../repo_origin/hooks/commit-msg.sample | 24 +++ .../hooks/fsmonitor-watchman.sample | 174 ++++++++++++++++++ .../repo_origin/hooks/post-update.sample | 8 + .../repo_origin/hooks/pre-applypatch.sample | 14 ++ .../repo_origin/hooks/pre-commit.sample | 49 +++++ .../repo_origin/hooks/pre-merge-commit.sample | 13 ++ .../repo_origin/hooks/pre-push.sample | 53 ++++++ .../repo_origin/hooks/pre-rebase.sample | 169 +++++++++++++++++ .../repo_origin/hooks/pre-receive.sample | 24 +++ .../hooks/prepare-commit-msg.sample | 42 +++++ .../repo_origin/hooks/push-to-checkout.sample | 78 ++++++++ .../hooks/sendemail-validate.sample | 77 ++++++++ .../impacted/repo_origin/hooks/update.sample | 128 +++++++++++++ .../ci/git/impacted/repo_origin/info/exclude | 6 + .../02/fcc183ad25f086aaec562224abc1b323ebaaa9 | Bin 0 -> 400 bytes .../07/30f8c84174f476a9493f9d779640d7c971a2ef | Bin 0 -> 363 bytes .../1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 | Bin 0 -> 399 bytes .../3b/bf06262d9604dc0667c1e96b13fbf88f25a43f | Bin 0 -> 54 bytes .../82/ac08af7cb3071716559cc26257ee21dfc8e4d3 | Bin 0 -> 54 bytes .../95/e75d98dbaf42c1efc9be0405e079f97aa24888 | Bin 0 -> 32 bytes .../af/5626b4a114abcb82d63db7c8082c3c4756e51b | Bin 0 -> 30 bytes .../e0/dea118958b3ce7d0b353aaf37177a4eac87d59 | Bin 0 -> 54 bytes .../eb/fd7499dae526dcbaf30e1250b1f875946729f8 | Bin 0 -> 54 bytes .../impacted/repo_origin/refs/heads/feature | 1 + .../impacted/repo_origin/refs/heads/master | 1 + .../ci/git/impacted/source_repo/README.md | 3 + .../ci/git/impacted/source_repo/git/HEAD | 1 + .../ci/git/impacted/source_repo/git/config | 10 + .../02/fcc183ad25f086aaec562224abc1b323ebaaa9 | Bin 0 -> 400 bytes .../07/30f8c84174f476a9493f9d779640d7c971a2ef | Bin 0 -> 363 bytes .../1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 | Bin 0 -> 399 bytes .../3b/bf06262d9604dc0667c1e96b13fbf88f25a43f | Bin 0 -> 54 bytes .../82/ac08af7cb3071716559cc26257ee21dfc8e4d3 | Bin 0 -> 54 bytes .../95/e75d98dbaf42c1efc9be0405e079f97aa24888 | Bin 0 -> 32 bytes .../af/5626b4a114abcb82d63db7c8082c3c4756e51b | Bin 0 -> 30 bytes .../e0/dea118958b3ce7d0b353aaf37177a4eac87d59 | Bin 0 -> 54 bytes .../eb/fd7499dae526dcbaf30e1250b1f875946729f8 | Bin 0 -> 54 bytes .../source_repo/git/refs/heads/feature | 1 + .../source_repo/git/refs/heads/master | 1 + .../git/refs/remotes/origin/feature | 1 + .../git/refs/remotes/origin/master | 1 + 112 files changed, 1028 insertions(+), 57 deletions(-) delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/README.md delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/FETCH_HEAD delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/HEAD delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/17/6f8635f95d63e924c30e5e9b7abeeeedf54d8a delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/2a/e4709da8155737b36d480722c57bab906a4f00 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/5f/cf9693c480d770583779a67bae94ca379a0cfa delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/6c/75724a3f6ac016736dfae8c684c269a57d201e delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/f3/b7c4615f1990980108cec313d98dfd3250f323 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/refs/heads/feature/source delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/refs/remotes/origin/feature/source delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/README.md create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/build_script.txt create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/README.md create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/FETCH_HEAD create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/HEAD rename dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/{github-clone => impacted/ghub_actions_clone}/git/config (72%) create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/07/30f8c84174f476a9493f9d779640d7c971a2ef create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/95/e75d98dbaf42c1efc9be0405e079f97aa24888 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/e0/dea118958b3ce7d0b353aaf37177a4eac87d59 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/heads/feature create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/remotes/origin/feature delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/HEAD delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/17/6f8635f95d63e924c30e5e9b7abeeeedf54d8a delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/2a/e4709da8155737b36d480722c57bab906a4f00 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/5f/cf9693c480d770583779a67bae94ca379a0cfa delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/6c/75724a3f6ac016736dfae8c684c269a57d201e delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/7e/7fbbe44883d25f3f5207819b9f44a5093248c9 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/c4/795aab1c04211706f11edac18e059905a80790 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/f1/3dd20ed84d937f11a6dec2a95be2dfbe7a407f delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/f3/b7c4615f1990980108cec313d98dfd3250f323 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/refs/heads/feature/source delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/refs/heads/master delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/refs/remotes/origin/HEAD delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/refs/remotes/origin/feature/source delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/refs/remotes/origin/master create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/README.md create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/FETCH_HEAD create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/HEAD rename dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/{ => new_clone}/git/config (50%) create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/07/30f8c84174f476a9493f9d779640d7c971a2ef create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/95/e75d98dbaf42c1efc9be0405e079f97aa24888 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/e0/dea118958b3ce7d0b353aaf37177a4eac87d59 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/heads/master create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/remotes/origin/feature create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/README.md create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/HEAD create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/config create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/a9/d9bdb3b83442c8e55b6dfd61b0790847720ee8 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/ad/686ebdcb37b8660171e8df4b922e018f92f508 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/d8/a57e1a0937c50c15cc7b9a3e39dc73a1249eaa create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/refs/heads/master create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/HEAD create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/config create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/description create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/applypatch-msg.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/commit-msg.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/fsmonitor-watchman.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/post-update.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-applypatch.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-commit.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-merge-commit.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-push.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-rebase.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-receive.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/prepare-commit-msg.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/push-to-checkout.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/sendemail-validate.sample create mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/update.sample create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/info/exclude create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/07/30f8c84174f476a9493f9d779640d7c971a2ef create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/95/e75d98dbaf42c1efc9be0405e079f97aa24888 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/e0/dea118958b3ce7d0b353aaf37177a4eac87d59 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/README.md create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/HEAD create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/config create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/07/30f8c84174f476a9493f9d779640d7c971a2ef create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/95/e75d98dbaf42c1efc9be0405e079f97aa24888 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/e0/dea118958b3ce7d0b353aaf37177a4eac87d59 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/feature create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/master create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/feature create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/master diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java index 4f3f8e739e1..d8a1cc2068d 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java @@ -653,7 +653,7 @@ public String getRemoteName() throws IOException, InterruptedException, TimeoutE return remote.split("/")[0]; } catch (ShellCommandExecutor.ShellCommandFailedException e) { - LOGGER.debug("Error getting remote from upstream", e); + LOGGER.debug("Error getting remote from upstream, falling back to first remote", e); } // fallback to first remote if no upstream @@ -709,7 +709,7 @@ public String detectDefaultBranch(String remoteName) } catch (ShellCommandExecutor.ShellCommandFailedException ignored) { } - LOGGER.debug("Could not get symbolic-ref, trying to find fallback"); + LOGGER.debug("Could not get symbolic-ref for default branch, trying fallback"); List fallbackBranches = Arrays.asList("main", "master"); for (String branch : fallbackBranches) { try { @@ -726,6 +726,7 @@ public String detectDefaultBranch(String remoteName) } } + LOGGER.debug("No fallback default branch found"); return null; } @@ -743,16 +744,20 @@ public void checkAndFetchBranch(String branch, String remoteName) LOGGER.debug("Branch {} exists locally, skipping fetch", branch); return; } catch (ShellCommandExecutor.ShellCommandFailedException e) { - LOGGER.debug("Branch {} does not exist locally, checking remote", branch, e); + LOGGER.debug("Branch {} does not exist locally, checking remote", branch); } // check if branch exists in remote - String remoteHeads = - commandExecutor - .executeCommand(IOUtils::readFully, "git", "ls-remote", "--heads", remoteName, branch) - .trim(); + String remoteHeads = null; + try { + remoteHeads = + commandExecutor + .executeCommand(IOUtils::readFully, "git", "ls-remote", "--heads", remoteName, branch) + .trim(); + } catch (ShellCommandExecutor.ShellCommandFailedException ignored) { + } - if (remoteHeads.isEmpty()) { + if (!Strings.isNotBlank(remoteHeads)) { LOGGER.debug("Branch {} does not exist in remote", branch); return; } diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy index bc1b200f2a9..0a79902f957 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy @@ -393,41 +393,47 @@ class GitClientTest extends Specification { gitClient.getRemoteName() == remoteName where: - repoPath | remoteName - "ci/git/impacted/git" | "origin" - "ci/git/with_pack/git" | "origin" // fallback on ambiguous upstream + repoPath | remoteName + "ci/git/impacted/ghub_actions_clone/git" | "origin" // get remote from upstream + "ci/git/impacted/source_repo/git" | "origin" // no upstream configured for branch + "ci/git/with_pack/git" | "origin" // ambiguous '@{upstream}' argument } def "test get source branch"() { given: - givenGitRepo("ci/git/impacted/git") + givenGitRepo("ci/git/impacted/source_repo/git") def gitClient = givenGitClient() when: def branch = gitClient.getSourceBranch() then: - branch == "feature/source" + branch == "feature" } def "test detect default branch"() { - givenGitRepo() + given: + givenGitRepo("ci/git/impacted/source_repo/git") def gitClient = givenGitClient() - gitClient.detectDefaultBranch("origin") == "master" + + when: + def defaultBranch = gitClient.detectDefaultBranch("origin") + + then: + defaultBranch == "master" } def "test compute branch metrics"() { given: - givenGitRepo("ci/git/impacted/git") + givenGitRepo("ci/git/impacted/source_repo/git") def gitClient = givenGitClient() when: - def metrics = gitClient.computeBranchMetrics(["master", "origin/master"], "feature/source") + def metrics = gitClient.computeBranchMetrics(["origin/master"], "feature") then: - metrics == [ - "master" : new ShellGitClient.BaseBranchMetric(1, 1, "2ae4709da8155737b36d480722c57bab906a4f00"), - "origin/master": new ShellGitClient.BaseBranchMetric(1, 1, "2ae4709da8155737b36d480722c57bab906a4f00")] + metrics.size() == 1 + metrics["origin/master"] == new ShellGitClient.BaseBranchMetric(0, 1, "02fcc183ad25f086aaec562224abc1b323ebaaa9") } def "test find best branch sha"() { @@ -447,17 +453,19 @@ class GitClientTest extends Specification { [:] | null } - def "test get base branch sha"() { - givenGitRepo("ci/git/impacted/git") + def "test get base branch sha: #testcaseName"() { + givenGitRepo(repo) def gitClient = givenGitClient() - gitClient.getBaseCommitSha(baseBranch, defaultBranch) == expected + gitClient.getBaseCommitSha(baseBranch, null) == expected where: - baseBranch | defaultBranch | expected - "master" | "master" | "2ae4709da8155737b36d480722c57bab906a4f00" - "master" | null | "2ae4709da8155737b36d480722c57bab906a4f00" - null | null | "2ae4709da8155737b36d480722c57bab906a4f00" + testcaseName | repo | baseBranch | expected + "base branch provided" | "ci/git/impacted/source_repo/git" | "master" | "02fcc183ad25f086aaec562224abc1b323ebaaa9" + "base branch not provided" | "ci/git/impacted/source_repo/git" | null | "02fcc183ad25f086aaec562224abc1b323ebaaa9" + "fresh clone" | "ci/git/impacted/new_clone/git" | null | "02fcc183ad25f086aaec562224abc1b323ebaaa9" + "no remote clone" | "ci/git/impacted/no_remote/git" | null | null + "Github Actions style clone" | "ci/git/impacted/ghub_actions_clone/git" | null | "02fcc183ad25f086aaec562224abc1b323ebaaa9" } private void givenGitRepo() { diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/README.md b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/README.md deleted file mode 100644 index 0a3fe8f1bf6..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Example repo -Some change diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/FETCH_HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/FETCH_HEAD deleted file mode 100644 index ec1516d27a9..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/FETCH_HEAD +++ /dev/null @@ -1 +0,0 @@ -6c75724a3f6ac016736dfae8c684c269a57d201e branch 'feature/source' of ../origin diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/HEAD deleted file mode 100644 index 910cf56841e..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/feature/source diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 deleted file mode 100644 index d5dc253bc5193a097af0d31686bf7531ce9bf082..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 43 zcmb9XD~D{Ff%bx2y%6F@paY9O<@qvZ!`TFoBUGcFkjs4s(tU? Me)a7F05tp%=Pg4RPyhe` diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/6c/75724a3f6ac016736dfae8c684c269a57d201e b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/6c/75724a3f6ac016736dfae8c684c269a57d201e deleted file mode 100644 index 24d9b50841bee37e52c9c91e92aa34973e94b560..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 415 zcmV;Q0bu@k0j-cvbDJ;_#e3#c=$>gJAwbY+JH_UYaSW~lI4(CK32+Sp6FGJK=?iI( zJ$7ey=k0H1-@IAYcim9|)5agvCsTA; zD5L^96$XJ0r#3Q8f=P)jZrG6MIx|U0O9xuis36qnMK%2hJSvZ(1##a9PGt{1PjdqI z-CyvHQ$=}SH|KlScV7V_hHarKh6(PVKKV>^3arF`u&RgpAm%AIRBwHME7!*J4Xp7*EtXO80RG_yJlP11%mbh@xgqq49qw&Fp) zJ{>f$*vNG|>Ov+ohIm#8hg2ql?sYG9_j zb+RYP!T&Cu_Vu~;f?{|W!ylJpHFRowH>mn7)!XAswot4JHrIXm`WRhzuKslG>~tGP zdkxfAXSHR&-bi8OhlilKol`gdqWyV?pLqXzhE@rxJ^{)(U=5YE0KEh=yNm*qBbBVt Jegmnhvn?`N#^eA1 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/f3/b7c4615f1990980108cec313d98dfd3250f323 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/objects/f3/b7c4615f1990980108cec313d98dfd3250f323 deleted file mode 100644 index 08808775b173d1961aff80df42a948ad6bf78f98..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53 zcmb>README.md && git add README.md && git commit -m "Initial commit") +(cd $source_path && echo "Hello, world!" >>README.md && git add README.md && git commit -m "Update README") +(cd $source_path && git push origin master) + +base_branch="master" +feature_branch="feature" +base_commit=$(cd $source_path && git rev-parse HEAD) + +# create feature branch +(cd $source_path && git checkout -b $feature_branch) +(cd $source_path && echo "Feature branch change" >>README.md && git add README.md && git commit -m "Updated README") +(cd $source_path && git push origin $feature_branch) + +# create new clone +mkdir -p $new_clone_path +(cd $new_clone_path && git init) +(cd $new_clone_path && git remote add origin $origin_path) +(cd $new_clone_path && git fetch origin $feature_branch) +(cd $new_clone_path && git reset --hard "origin/$feature_branch") + +# remote pointing to non existing repo +mkdir -p $no_remote_path +(cd $no_remote_path && git init) +(cd $no_remote_path && echo "base branch file" >>README.md && git add README.md && git commit -m "first commit") +(cd $no_remote_path && git remote add origin "git@git.com:datadog/non_existing_repo.git") + +# github actions style clone +mkdir -p $ghub_actions_path +(cd $ghub_actions_path && git init) +(cd $ghub_actions_path && git remote add origin $origin_path) +(cd $ghub_actions_path && git fetch --no-tags --prune --no-recurse-submodules origin $feature_branch) +(cd $ghub_actions_path && git checkout --progress --force -B $feature_branch "refs/remotes/origin/$feature_branch") + +echo "BASE COMMIT: $base_commit" + +# cleanup +(cd $source_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index && mv .git git) +(cd $new_clone_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index && mv .git git) +(cd $no_remote_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index && mv .git git) +(cd $ghub_actions_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index && mv .git git) diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/README.md b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/README.md new file mode 100644 index 00000000000..82ac08af7cb --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/README.md @@ -0,0 +1,3 @@ +Hello, world! +Hello, world! +Feature branch change diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/FETCH_HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/FETCH_HEAD new file mode 100644 index 00000000000..189fccde139 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/FETCH_HEAD @@ -0,0 +1 @@ +1ef73e8a15f4920afa1bd5d0fa1464e745f7e4d6 branch 'feature' of /tmp/impacted/repo_origin diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/HEAD new file mode 100644 index 00000000000..7a3c5afe3e1 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/feature diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/config b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/config similarity index 72% rename from dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/config rename to dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/config index 5ee77423067..60dbbbd3c84 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/github-clone/git/config +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/config @@ -6,8 +6,8 @@ ignorecase = true precomposeunicode = true [remote "origin"] - url = ../origin.git + url = /tmp/impacted/repo_origin fetch = +refs/heads/*:refs/remotes/origin/* -[branch "feature/source"] +[branch "feature"] remote = origin - merge = refs/heads/feature/source + merge = refs/heads/feature diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 new file mode 100644 index 0000000000000000000000000000000000000000..33aaacf527e71e09210c0479e92efd9e1dc54ea5 GIT binary patch literal 400 zcmV;B0dM|z0j-fwZ=)~}#rMpo@O`zdjR9k6ceMlvAq`FmkWy|A81e^jN=Xy-)30fJ z+~bZk)|;O+Pow8jcHLnFrlo%y2O)rfmEZ{3)U+i zUH1k4RD9%>Z1yjArR;tKWlNz>)D7S})FIRqRR@paKUg*A=Jn8kA5+czAY>p(79a@& z=A_xi|KJ+P5DPQdE}W@i)m}8IRf(BgJ#A0XF+)*$npl$rCTRm6&@QNxa97w?xv1vZ z@|0^}w(6Jdpo^ZlcJ`9a;k4ludix=!!EuUr9{9>FRC<<9#Kr8LyQnR^5V6!ZH89b5 zeX-6DN4G3kdfYs_Z)+othFL4Od4BH$NTJ0;rD5kZ2|;on-+rOI3n&S&}F3=`z{yN@DrlyL#$cnf3B#41Ve=^Fzmua7D&^!@jM8Ao-S*@~H$>`+9 zC+#OQSzF>&uCdMnjzvOk0B0KAy<8p_A$yR8e;;SpJ8I?Is660)yiin;%U`{V^*Idj zvDoz2Qs81rM`;ixZI6B-M(956i;Qbs_1Ros(@U9sesp0z< Jz&|MVpSURSxc~qF literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 new file mode 100644 index 0000000000000000000000000000000000000000..5713a364c0f53d5fc5f4804fea9526f68485eb45 GIT binary patch literal 399 zcmV;A0dW3!0j-fuZ<|06hI`&$vG*$Je!v1!8x@exkijIQaB75g+z>55-W%0nCe{HwkD=9s0M>L zt8RpdXeqHxML|rBY$k+~CL@FxB9}O)gsNN!;Q;YER{a@zqN`N{`9Ka0oC__!?&ha#*7td-VDepJCpU3!+;W$0ctV{yaY61~BZJ?7V-`h-v#bdTQ zJ_ESebgSk}RL7Tgc1j=7JmKw0^DgGbb@w+B_|vv%(u;H^OUiFziJQF_VV?RXfHQrH zjcc$NejI|;Eh4uaTW4tZ#w}57FISn=asTCaZ4Czpk8joXLWbd`U1P%wUwAy0jnilV tBV=E_Q|R*MsKaHucB@}y^bP#A!{^@r%mCRi{YMpW>rXcL;12|MtZg1{#Q*>R literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f new file mode 100644 index 0000000000000000000000000000000000000000..57eb72be65a28d5f689a43f00374ea6addbeb584 GIT binary patch literal 54 zcmbH&;f?#!jCb#dcrnM>^Wl4u_wy@? KBpGyb1tI_?PZjn6 literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 new file mode 100644 index 0000000000000000000000000000000000000000..be32d0e3b5368ab64f56d0d5e1458235f46fcaeb GIT binary patch literal 54 zcmV-60LlM&0ZYosPf{>7VDL!I$;sDID99XD~D{Ff%bx2y%6F@paY9O<|b&Ja)$I^-c%hpWMg7`k?Y> M)gq4$08!%+@=25!`2YX_ literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 new file mode 100644 index 0000000000000000000000000000000000000000..5d38589c034979d3a28af66bfc520c73cea959a3 GIT binary patch literal 54 zcmV-60LlM&0V^p=O;s>9XD~D{Ff%bx2y%6F@paY9O<`CcrnY6F$m-Kg*KD_+;Lx#g M4|^&N05>xaVkvSJ$p8QV literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/heads/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/heads/feature new file mode 100644 index 00000000000..c030c81b14e --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/heads/feature @@ -0,0 +1 @@ +1ef73e8a15f4920afa1bd5d0fa1464e745f7e4d6 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/remotes/origin/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/remotes/origin/feature new file mode 100644 index 00000000000..c030c81b14e --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/remotes/origin/feature @@ -0,0 +1 @@ +1ef73e8a15f4920afa1bd5d0fa1464e745f7e4d6 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/HEAD deleted file mode 100644 index 910cf56841e..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/feature/source diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/0a/3fe8f1bf6c828f645c7cb8a94d166c6d63ca86 deleted file mode 100644 index d5dc253bc5193a097af0d31686bf7531ce9bf082..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 43 zcmb9XD~D{Ff%bx2y%6F@paY9O<@qvZ!`TFoBUGcFkjs4s(tU? Me)a7F05tp%=Pg4RPyhe` diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/6c/75724a3f6ac016736dfae8c684c269a57d201e b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/6c/75724a3f6ac016736dfae8c684c269a57d201e deleted file mode 100644 index 24d9b50841bee37e52c9c91e92aa34973e94b560..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 415 zcmV;Q0bu@k0j-cvbDJ;_#e3#c=$>gJAwbY+JH_UYaSW~lI4(CK32+Sp6FGJK=?iI( zJ$7ey=k0H1-@IAYcim9|)5agvCsTA; zD5L^96$XJ0r#3Q8f=P)jZrG6MIx|U0O9xuis36qnMK%2hJSvZ(1##a9PGt{1PjdqI z-CyvHQ$=}SH|KlScV7V_hHarKh6(PVKKV>^3arF`u&RgpAm%AIRBwHME7!*J4Xp7*EtXO80RG_yJlP11%mbh@xgqq49qw&Fp) zJ{>f$*vNG|>Ov+ohIm#8hg2ql?sYG9_j zb+RYP!T&Cu_Vu~;f?{|W!ylJpHFRowH>mn7)!XAswot4JHrIXm`WRhzuKslG>~tGP zdkxfAXSHR&-bi8OhlilKol`gdqWyV?pLqXzhE@rxJ^{)(U=5YE0KEh=yNm*qBbBVt Jegmnhvn?`N#^eA1 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/7e/7fbbe44883d25f3f5207819b9f44a5093248c9 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/7e/7fbbe44883d25f3f5207819b9f44a5093248c9 deleted file mode 100644 index 167bcebfc4319fe406108de7152b6009d3833160..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmbdyCV@1Im1O#RNcwx_P7K7OjR KErZ(v!F~WdoEHoL diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/c4/795aab1c04211706f11edac18e059905a80790 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/c4/795aab1c04211706f11edac18e059905a80790 deleted file mode 100644 index 4bbcdf05bf0..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/c4/795aab1c04211706f11edac18e059905a80790 +++ /dev/null @@ -1,2 +0,0 @@ -xM0{W^;6U[5bȂhRn aL`m=vHj4m[MPn*E*3rFAtH2SXh:f Ra -\2D5hjs T&\K\@ɧ_-J5 *]>u_%|3@5bQL'ʡ-u'@ Dwk F‹an8i3CG<(ꅕ!'ᒛ-/B/M:s]Oݾ/.v7obi6&3yF qjC"rz K6:#;4tEbWsKo=SDM <_ǧ}+p(\ Q+9#C+fr_٘ \ No newline at end of file diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/f1/3dd20ed84d937f11a6dec2a95be2dfbe7a407f b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/f1/3dd20ed84d937f11a6dec2a95be2dfbe7a407f deleted file mode 100644 index d7bd64bd0410caacc826e6d14cee3f16355327cd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 49 zcmV-10M7q-0ZYosPf{>8W>8jetw_u*$VpWwN-fCe^2jgIP0OrM$j?*AO)M@+E#d+I H4&n`G9dZ?7 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/f3/b7c4615f1990980108cec313d98dfd3250f323 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/git/objects/f3/b7c4615f1990980108cec313d98dfd3250f323 deleted file mode 100644 index 08808775b173d1961aff80df42a948ad6bf78f98..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53 zcmb+i zUH1k4RD9%>Z1yjArR;tKWlNz>)D7S})FIRqRR@paKUg*A=Jn8kA5+czAY>p(79a@& z=A_xi|KJ+P5DPQdE}W@i)m}8IRf(BgJ#A0XF+)*$npl$rCTRm6&@QNxa97w?xv1vZ z@|0^}w(6Jdpo^ZlcJ`9a;k4ludix=!!EuUr9{9>FRC<<9#Kr8LyQnR^5V6!ZH89b5 zeX-6DN4G3kdfYs_Z)+othFL4Od4BH$NTJ0;rD5kZ2|;on-+rOI3n&S&}F3=`z{yN@DrlyL#$cnf3B#41Ve=^Fzmua7D&^!@jM8Ao-S*@~H$>`+9 zC+#OQSzF>&uCdMnjzvOk0B0KAy<8p_A$yR8e;;SpJ8I?Is660)yiin;%U`{V^*Idj zvDoz2Qs81rM`;ixZI6B-M(956i;Qbs_1Ros(@U9sesp0z< Jz&|MVpSURSxc~qF literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 new file mode 100644 index 0000000000000000000000000000000000000000..5713a364c0f53d5fc5f4804fea9526f68485eb45 GIT binary patch literal 399 zcmV;A0dW3!0j-fuZ<|06hI`&$vG*$Je!v1!8x@exkijIQaB75g+z>55-W%0nCe{HwkD=9s0M>L zt8RpdXeqHxML|rBY$k+~CL@FxB9}O)gsNN!;Q;YER{a@zqN`N{`9Ka0oC__!?&ha#*7td-VDepJCpU3!+;W$0ctV{yaY61~BZJ?7V-`h-v#bdTQ zJ_ESebgSk}RL7Tgc1j=7JmKw0^DgGbb@w+B_|vv%(u;H^OUiFziJQF_VV?RXfHQrH zjcc$NejI|;Eh4uaTW4tZ#w}57FISn=asTCaZ4Czpk8joXLWbd`U1P%wUwAy0jnilV tBV=E_Q|R*MsKaHucB@}y^bP#A!{^@r%mCRi{YMpW>rXcL;12|MtZg1{#Q*>R literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f new file mode 100644 index 0000000000000000000000000000000000000000..57eb72be65a28d5f689a43f00374ea6addbeb584 GIT binary patch literal 54 zcmbH&;f?#!jCb#dcrnM>^Wl4u_wy@? KBpGyb1tI_?PZjn6 literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 new file mode 100644 index 0000000000000000000000000000000000000000..be32d0e3b5368ab64f56d0d5e1458235f46fcaeb GIT binary patch literal 54 zcmV-60LlM&0ZYosPf{>7VDL!I$;sDID99XD~D{Ff%bx2y%6F@paY9O<|b&Ja)$I^-c%hpWMg7`k?Y> M)gq4$08!%+@=25!`2YX_ literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 new file mode 100644 index 0000000000000000000000000000000000000000..5d38589c034979d3a28af66bfc520c73cea959a3 GIT binary patch literal 54 zcmV-60LlM&0V^p=O;s>9XD~D{Ff%bx2y%6F@paY9O<`CcrnY6F$m-Kg*KD_+;Lx#g M4|^&N05>xaVkvSJ$p8QV literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/heads/master b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/heads/master new file mode 100644 index 00000000000..c030c81b14e --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/heads/master @@ -0,0 +1 @@ +1ef73e8a15f4920afa1bd5d0fa1464e745f7e4d6 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/remotes/origin/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/remotes/origin/feature new file mode 100644 index 00000000000..c030c81b14e --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/remotes/origin/feature @@ -0,0 +1 @@ +1ef73e8a15f4920afa1bd5d0fa1464e745f7e4d6 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/README.md b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/README.md new file mode 100644 index 00000000000..ad686ebdcb3 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/README.md @@ -0,0 +1 @@ +base branch file diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/HEAD new file mode 100644 index 00000000000..cb089cd89a7 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/config b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/config new file mode 100644 index 00000000000..155f4087068 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/config @@ -0,0 +1,10 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true + precomposeunicode = true +[remote "origin"] + url = git@git.com:datadog/non_existing_repo.git + fetch = +refs/heads/*:refs/remotes/origin/* diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/a9/d9bdb3b83442c8e55b6dfd61b0790847720ee8 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/a9/d9bdb3b83442c8e55b6dfd61b0790847720ee8 new file mode 100644 index 0000000000000000000000000000000000000000..8ff8c7eebcbbd2d5f4808427d63a29b924ae4301 GIT binary patch literal 54 zcmV-60LlM&0V^p=O;s>9XD~D{Ff%bx2y%6F@paY9O<`D@k+=7>`HnQk!WZ|wC+RWv MPx{IM06e1)`aaVbJ^%m! literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/ad/686ebdcb37b8660171e8df4b922e018f92f508 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/ad/686ebdcb37b8660171e8df4b922e018f92f508 new file mode 100644 index 0000000000000000000000000000000000000000..82909bfce18537109a4c006dbfee7eff4f9650b8 GIT binary patch literal 33 pcmbx}og0FTpWJfAW#WbEUR1_08C3~m4b literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/d8/a57e1a0937c50c15cc7b9a3e39dc73a1249eaa b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/d8/a57e1a0937c50c15cc7b9a3e39dc73a1249eaa new file mode 100644 index 0000000000000000000000000000000000000000..d1304fc58e55e69be44389a3a3eca5505d498e3a GIT binary patch literal 364 zcmV-y0h9iC0j-hSZlf>|hWFY};rnP?b1(*}t(Jt7(?FE~X_q^L&7lFD5UOnR^b1Wd z_i{&?(LbLwzeY2K?7C)zSkZorgAkBe+{$^b<))_VYGDeDbAy-MP;x{pWa@;dNC*?K zkFk~mbXebr7KXAGob?huOmzZx-8cBf*~qx8>eF2zyCPsS+lK znN_imN$WG;>ijaMd1e|#z`b;Rcmr^`>DTR`iauJI=_&EhJmF+&`z7YawzDhq-N}tk zdYQ~*rA1e^QrgU+N|d-5z?p7?G2Y8pu^}3b@3GCh;nTaI!|wSiKdR$!5ubQl1_m|m zdqTUH#ha^}i?;Y(l_snI\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/fsmonitor-watchman.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/fsmonitor-watchman.sample new file mode 100755 index 00000000000..23e856f5dee --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/fsmonitor-watchman.sample @@ -0,0 +1,174 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use IPC::Open2; + +# An example hook script to integrate Watchman +# (https://facebook.github.io/watchman/) with git to speed up detecting +# new and modified files. +# +# The hook is passed a version (currently 2) and last update token +# formatted as a string and outputs to stdout a new update token and +# all files that have been modified since the update token. Paths must +# be relative to the root of the working tree and separated by a single NUL. +# +# To enable this hook, rename this file to "query-watchman" and set +# 'git config core.fsmonitor .git/hooks/query-watchman' +# +my ($version, $last_update_token) = @ARGV; + +# Uncomment for debugging +# print STDERR "$0 $version $last_update_token\n"; + +# Check the hook interface version +if ($version ne 2) { + die "Unsupported query-fsmonitor hook version '$version'.\n" . + "Falling back to scanning...\n"; +} + +my $git_work_tree = get_working_dir(); + +my $retry = 1; + +my $json_pkg; +eval { + require JSON::XS; + $json_pkg = "JSON::XS"; + 1; +} or do { + require JSON::PP; + $json_pkg = "JSON::PP"; +}; + +launch_watchman(); + +sub launch_watchman { + my $o = watchman_query(); + if (is_work_tree_watched($o)) { + output_result($o->{clock}, @{$o->{files}}); + } +} + +sub output_result { + my ($clockid, @files) = @_; + + # Uncomment for debugging watchman output + # open (my $fh, ">", ".git/watchman-output.out"); + # binmode $fh, ":utf8"; + # print $fh "$clockid\n@files\n"; + # close $fh; + + binmode STDOUT, ":utf8"; + print $clockid; + print "\0"; + local $, = "\0"; + print @files; +} + +sub watchman_clock { + my $response = qx/watchman clock "$git_work_tree"/; + die "Failed to get clock id on '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + + return $json_pkg->new->utf8->decode($response); +} + +sub watchman_query { + my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') + or die "open2() failed: $!\n" . + "Falling back to scanning...\n"; + + # In the query expression below we're asking for names of files that + # changed since $last_update_token but not from the .git folder. + # + # To accomplish this, we're using the "since" generator to use the + # recency index to select candidate nodes and "fields" to limit the + # output to file names only. Then we're using the "expression" term to + # further constrain the results. + my $last_update_line = ""; + if (substr($last_update_token, 0, 1) eq "c") { + $last_update_token = "\"$last_update_token\""; + $last_update_line = qq[\n"since": $last_update_token,]; + } + my $query = <<" END"; + ["query", "$git_work_tree", {$last_update_line + "fields": ["name"], + "expression": ["not", ["dirname", ".git"]] + }] + END + + # Uncomment for debugging the watchman query + # open (my $fh, ">", ".git/watchman-query.json"); + # print $fh $query; + # close $fh; + + print CHLD_IN $query; + close CHLD_IN; + my $response = do {local $/; }; + + # Uncomment for debugging the watch response + # open ($fh, ">", ".git/watchman-response.json"); + # print $fh $response; + # close $fh; + + die "Watchman: command returned no output.\n" . + "Falling back to scanning...\n" if $response eq ""; + die "Watchman: command returned invalid output: $response\n" . + "Falling back to scanning...\n" unless $response =~ /^\{/; + + return $json_pkg->new->utf8->decode($response); +} + +sub is_work_tree_watched { + my ($output) = @_; + my $error = $output->{error}; + if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) { + $retry--; + my $response = qx/watchman watch "$git_work_tree"/; + die "Failed to make watchman watch '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + $output = $json_pkg->new->utf8->decode($response); + $error = $output->{error}; + die "Watchman: $error.\n" . + "Falling back to scanning...\n" if $error; + + # Uncomment for debugging watchman output + # open (my $fh, ">", ".git/watchman-output.out"); + # close $fh; + + # Watchman will always return all files on the first query so + # return the fast "everything is dirty" flag to git and do the + # Watchman query just to get it over with now so we won't pay + # the cost in git to look up each individual file. + my $o = watchman_clock(); + $error = $output->{error}; + + die "Watchman: $error.\n" . + "Falling back to scanning...\n" if $error; + + output_result($o->{clock}, ("/")); + $last_update_token = $o->{clock}; + + eval { launch_watchman() }; + return 0; + } + + die "Watchman: $error.\n" . + "Falling back to scanning...\n" if $error; + + return 1; +} + +sub get_working_dir { + my $working_dir; + if ($^O =~ 'msys' || $^O =~ 'cygwin') { + $working_dir = Win32::GetCwd(); + $working_dir =~ tr/\\/\//; + } else { + require Cwd; + $working_dir = Cwd::cwd(); + } + + return $working_dir; +} diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/post-update.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/post-update.sample new file mode 100755 index 00000000000..ec17ec1939b --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/post-update.sample @@ -0,0 +1,8 @@ +#!/bin/sh +# +# An example hook script to prepare a packed repository for use over +# dumb transports. +# +# To enable this hook, rename this file to "post-update". + +exec git update-server-info diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-applypatch.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-applypatch.sample new file mode 100755 index 00000000000..4142082bcb9 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-applypatch.sample @@ -0,0 +1,14 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed +# by applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-applypatch". + +. git-sh-setup +precommit="$(git rev-parse --git-path hooks/pre-commit)" +test -x "$precommit" && exec "$precommit" ${1+"$@"} +: diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-commit.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-commit.sample new file mode 100755 index 00000000000..29ed5ee486a --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-commit.sample @@ -0,0 +1,49 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=$(git hash-object -t tree /dev/null) +fi + +# If you want to allow non-ASCII filenames set this variable to true. +allownonascii=$(git config --type=bool hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ASCII filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff-index --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + exit 1 +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached $against -- diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-merge-commit.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-merge-commit.sample new file mode 100755 index 00000000000..399eab1924e --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-merge-commit.sample @@ -0,0 +1,13 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git merge" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message to +# stderr if it wants to stop the merge commit. +# +# To enable this hook, rename this file to "pre-merge-commit". + +. git-sh-setup +test -x "$GIT_DIR/hooks/pre-commit" && + exec "$GIT_DIR/hooks/pre-commit" +: diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-push.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-push.sample new file mode 100755 index 00000000000..4ce688d32b7 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-push.sample @@ -0,0 +1,53 @@ +#!/bin/sh + +# An example hook script to verify what is about to be pushed. Called by "git +# push" after it has checked the remote status, but before anything has been +# pushed. If this script exits with a non-zero status nothing will be pushed. +# +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# +# +# This sample shows how to prevent push of commits where the log message starts +# with "WIP" (work in progress). + +remote="$1" +url="$2" + +zero=$(git hash-object --stdin &2 "Found WIP commit in $local_ref, not pushing" + exit 1 + fi + fi +done + +exit 0 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-rebase.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-rebase.sample new file mode 100755 index 00000000000..6cbef5c370d --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-rebase.sample @@ -0,0 +1,169 @@ +#!/bin/sh +# +# Copyright (c) 2006, 2008 Junio C Hamano +# +# The "pre-rebase" hook is run just before "git rebase" starts doing +# its job, and can prevent the command from running by exiting with +# non-zero status. +# +# The hook is called with the following parameters: +# +# $1 -- the upstream the series was forked from. +# $2 -- the branch being rebased (or empty when rebasing the current branch). +# +# This sample shows how to prevent topic branches that are already +# merged to 'next' branch from getting rebased, because allowing it +# would result in rebasing already published history. + +publish=next +basebranch="$1" +if test "$#" = 2 +then + topic="refs/heads/$2" +else + topic=`git symbolic-ref HEAD` || + exit 0 ;# we do not interrupt rebasing detached HEAD +fi + +case "$topic" in +refs/heads/??/*) + ;; +*) + exit 0 ;# we do not interrupt others. + ;; +esac + +# Now we are dealing with a topic branch being rebased +# on top of master. Is it OK to rebase it? + +# Does the topic really exist? +git show-ref -q "$topic" || { + echo >&2 "No such branch $topic" + exit 1 +} + +# Is topic fully merged to master? +not_in_master=`git rev-list --pretty=oneline ^master "$topic"` +if test -z "$not_in_master" +then + echo >&2 "$topic is fully merged to master; better remove it." + exit 1 ;# we could allow it, but there is no point. +fi + +# Is topic ever merged to next? If so you should not be rebasing it. +only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` +only_next_2=`git rev-list ^master ${publish} | sort` +if test "$only_next_1" = "$only_next_2" +then + not_in_topic=`git rev-list "^$topic" master` + if test -z "$not_in_topic" + then + echo >&2 "$topic is already up to date with master" + exit 1 ;# we could allow it, but there is no point. + else + exit 0 + fi +else + not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` + /usr/bin/perl -e ' + my $topic = $ARGV[0]; + my $msg = "* $topic has commits already merged to public branch:\n"; + my (%not_in_next) = map { + /^([0-9a-f]+) /; + ($1 => 1); + } split(/\n/, $ARGV[1]); + for my $elem (map { + /^([0-9a-f]+) (.*)$/; + [$1 => $2]; + } split(/\n/, $ARGV[2])) { + if (!exists $not_in_next{$elem->[0]}) { + if ($msg) { + print STDERR $msg; + undef $msg; + } + print STDERR " $elem->[1]\n"; + } + } + ' "$topic" "$not_in_next" "$not_in_master" + exit 1 +fi + +<<\DOC_END + +This sample hook safeguards topic branches that have been +published from being rewound. + +The workflow assumed here is: + + * Once a topic branch forks from "master", "master" is never + merged into it again (either directly or indirectly). + + * Once a topic branch is fully cooked and merged into "master", + it is deleted. If you need to build on top of it to correct + earlier mistakes, a new topic branch is created by forking at + the tip of the "master". This is not strictly necessary, but + it makes it easier to keep your history simple. + + * Whenever you need to test or publish your changes to topic + branches, merge them into "next" branch. + +The script, being an example, hardcodes the publish branch name +to be "next", but it is trivial to make it configurable via +$GIT_DIR/config mechanism. + +With this workflow, you would want to know: + +(1) ... if a topic branch has ever been merged to "next". Young + topic branches can have stupid mistakes you would rather + clean up before publishing, and things that have not been + merged into other branches can be easily rebased without + affecting other people. But once it is published, you would + not want to rewind it. + +(2) ... if a topic branch has been fully merged to "master". + Then you can delete it. More importantly, you should not + build on top of it -- other people may already want to + change things related to the topic as patches against your + "master", so if you need further changes, it is better to + fork the topic (perhaps with the same name) afresh from the + tip of "master". + +Let's look at this example: + + o---o---o---o---o---o---o---o---o---o "next" + / / / / + / a---a---b A / / + / / / / + / / c---c---c---c B / + / / / \ / + / / / b---b C \ / + / / / / \ / + ---o---o---o---o---o---o---o---o---o---o---o "master" + + +A, B and C are topic branches. + + * A has one fix since it was merged up to "next". + + * B has finished. It has been fully merged up to "master" and "next", + and is ready to be deleted. + + * C has not merged to "next" at all. + +We would want to allow C to be rebased, refuse A, and encourage +B to be deleted. + +To compute (1): + + git rev-list ^master ^topic next + git rev-list ^master next + + if these match, topic has not merged in next at all. + +To compute (2): + + git rev-list master..topic + + if this is empty, it is fully merged to "master". + +DOC_END diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-receive.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-receive.sample new file mode 100755 index 00000000000..a1fd29ec148 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-receive.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to make use of push options. +# The example simply echoes all push options that start with 'echoback=' +# and rejects all pushes when the "reject" push option is used. +# +# To enable this hook, rename this file to "pre-receive". + +if test -n "$GIT_PUSH_OPTION_COUNT" +then + i=0 + while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" + do + eval "value=\$GIT_PUSH_OPTION_$i" + case "$value" in + echoback=*) + echo "echo from the pre-receive-hook: ${value#*=}" >&2 + ;; + reject) + exit 1 + esac + i=$((i + 1)) + done +fi diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/prepare-commit-msg.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/prepare-commit-msg.sample new file mode 100755 index 00000000000..10fa14c5ab0 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/prepare-commit-msg.sample @@ -0,0 +1,42 @@ +#!/bin/sh +# +# An example hook script to prepare the commit log message. +# Called by "git commit" with the name of the file that has the +# commit message, followed by the description of the commit +# message's source. The hook's purpose is to edit the commit +# message file. If the hook fails with a non-zero status, +# the commit is aborted. +# +# To enable this hook, rename this file to "prepare-commit-msg". + +# This hook includes three examples. The first one removes the +# "# Please enter the commit message..." help message. +# +# The second includes the output of "git diff --name-status -r" +# into the message, just before the "git status" output. It is +# commented because it doesn't cope with --amend or with squashed +# commits. +# +# The third example adds a Signed-off-by line to the message, that can +# still be edited. This is rarely a good idea. + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" + +# case "$COMMIT_SOURCE,$SHA1" in +# ,|template,) +# /usr/bin/perl -i.bak -pe ' +# print "\n" . `git diff --cached --name-status -r` +# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +# *) ;; +# esac + +# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +# fi diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/push-to-checkout.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/push-to-checkout.sample new file mode 100755 index 00000000000..af5a0c0018b --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/push-to-checkout.sample @@ -0,0 +1,78 @@ +#!/bin/sh + +# An example hook script to update a checked-out tree on a git push. +# +# This hook is invoked by git-receive-pack(1) when it reacts to git +# push and updates reference(s) in its repository, and when the push +# tries to update the branch that is currently checked out and the +# receive.denyCurrentBranch configuration variable is set to +# updateInstead. +# +# By default, such a push is refused if the working tree and the index +# of the remote repository has any difference from the currently +# checked out commit; when both the working tree and the index match +# the current commit, they are updated to match the newly pushed tip +# of the branch. This hook is to be used to override the default +# behaviour; however the code below reimplements the default behaviour +# as a starting point for convenient modification. +# +# The hook receives the commit with which the tip of the current +# branch is going to be updated: +commit=$1 + +# It can exit with a non-zero status to refuse the push (when it does +# so, it must not modify the index or the working tree). +die () { + echo >&2 "$*" + exit 1 +} + +# Or it can make any necessary changes to the working tree and to the +# index to bring them to the desired state when the tip of the current +# branch is updated to the new commit, and exit with a zero status. +# +# For example, the hook can simply run git read-tree -u -m HEAD "$1" +# in order to emulate git fetch that is run in the reverse direction +# with git push, as the two-tree form of git read-tree -u -m is +# essentially the same as git switch or git checkout that switches +# branches while keeping the local changes in the working tree that do +# not interfere with the difference between the branches. + +# The below is a more-or-less exact translation to shell of the C code +# for the default behaviour for git's push-to-checkout hook defined in +# the push_to_deploy() function in builtin/receive-pack.c. +# +# Note that the hook will be executed from the repository directory, +# not from the working tree, so if you want to perform operations on +# the working tree, you will have to adapt your code accordingly, e.g. +# by adding "cd .." or using relative paths. + +if ! git update-index -q --ignore-submodules --refresh +then + die "Up-to-date check failed" +fi + +if ! git diff-files --quiet --ignore-submodules -- +then + die "Working directory has unstaged changes" +fi + +# This is a rough translation of: +# +# head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX +if git cat-file -e HEAD 2>/dev/null +then + head=HEAD +else + head=$(git hash-object -t tree --stdin &2 + exit 1 +} + +unset GIT_DIR GIT_WORK_TREE +cd "$worktree" && + +if grep -q "^diff --git " "$1" +then + validate_patch "$1" +else + validate_cover_letter "$1" +fi && + +if test "$GIT_SENDEMAIL_FILE_COUNTER" = "$GIT_SENDEMAIL_FILE_TOTAL" +then + git config --unset-all sendemail.validateWorktree && + trap 'git worktree remove -ff "$worktree"' EXIT && + validate_series +fi diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/update.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/update.sample new file mode 100755 index 00000000000..c4d426bc6ee --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/update.sample @@ -0,0 +1,128 @@ +#!/bin/sh +# +# An example hook script to block unannotated tags from entering. +# Called by "git receive-pack" with arguments: refname sha1-old sha1-new +# +# To enable this hook, rename this file to "update". +# +# Config +# ------ +# hooks.allowunannotated +# This boolean sets whether unannotated tags will be allowed into the +# repository. By default they won't be. +# hooks.allowdeletetag +# This boolean sets whether deleting tags will be allowed in the +# repository. By default they won't be. +# hooks.allowmodifytag +# This boolean sets whether a tag may be modified after creation. By default +# it won't be. +# hooks.allowdeletebranch +# This boolean sets whether deleting branches will be allowed in the +# repository. By default they won't be. +# hooks.denycreatebranch +# This boolean sets whether remotely creating branches will be denied +# in the repository. By default this is allowed. +# + +# --- Command line +refname="$1" +oldrev="$2" +newrev="$3" + +# --- Safety check +if [ -z "$GIT_DIR" ]; then + echo "Don't run this script from the command line." >&2 + echo " (if you want, you could supply GIT_DIR then run" >&2 + echo " $0 )" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "usage: $0 " >&2 + exit 1 +fi + +# --- Config +allowunannotated=$(git config --type=bool hooks.allowunannotated) +allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch) +denycreatebranch=$(git config --type=bool hooks.denycreatebranch) +allowdeletetag=$(git config --type=bool hooks.allowdeletetag) +allowmodifytag=$(git config --type=bool hooks.allowmodifytag) + +# check for no description +projectdesc=$(sed -e '1q' "$GIT_DIR/description") +case "$projectdesc" in +"Unnamed repository"* | "") + echo "*** Project description file hasn't been set" >&2 + exit 1 + ;; +esac + +# --- Check types +# if $newrev is 0000...0000, it's a commit to delete a ref. +zero=$(git hash-object --stdin &2 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 + exit 1 + fi + ;; + refs/tags/*,delete) + # delete tag + if [ "$allowdeletetag" != "true" ]; then + echo "*** Deleting a tag is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/tags/*,tag) + # annotated tag + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 + then + echo "*** Tag '$refname' already exists." >&2 + echo "*** Modifying a tag is not allowed in this repository." >&2 + exit 1 + fi + ;; + refs/heads/*,commit) + # branch + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then + echo "*** Creating a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/heads/*,delete) + # delete branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/remotes/*,commit) + # tracking branch + ;; + refs/remotes/*,delete) + # delete tracking branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + *) + # Anything else (is there anything else?) + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 + exit 1 + ;; +esac + +# --- Finished +exit 0 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/info/exclude b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/info/exclude new file mode 100644 index 00000000000..a5196d1be8f --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/info/exclude @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 new file mode 100644 index 0000000000000000000000000000000000000000..33aaacf527e71e09210c0479e92efd9e1dc54ea5 GIT binary patch literal 400 zcmV;B0dM|z0j-fwZ=)~}#rMpo@O`zdjR9k6ceMlvAq`FmkWy|A81e^jN=Xy-)30fJ z+~bZk)|;O+Pow8jcHLnFrlo%y2O)rfmEZ{3)U+i zUH1k4RD9%>Z1yjArR;tKWlNz>)D7S})FIRqRR@paKUg*A=Jn8kA5+czAY>p(79a@& z=A_xi|KJ+P5DPQdE}W@i)m}8IRf(BgJ#A0XF+)*$npl$rCTRm6&@QNxa97w?xv1vZ z@|0^}w(6Jdpo^ZlcJ`9a;k4ludix=!!EuUr9{9>FRC<<9#Kr8LyQnR^5V6!ZH89b5 zeX-6DN4G3kdfYs_Z)+othFL4Od4BH$NTJ0;rD5kZ2|;on-+rOI3n&S&}F3=`z{yN@DrlyL#$cnf3B#41Ve=^Fzmua7D&^!@jM8Ao-S*@~H$>`+9 zC+#OQSzF>&uCdMnjzvOk0B0KAy<8p_A$yR8e;;SpJ8I?Is660)yiin;%U`{V^*Idj zvDoz2Qs81rM`;ixZI6B-M(956i;Qbs_1Ros(@U9sesp0z< Jz&|MVpSURSxc~qF literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 new file mode 100644 index 0000000000000000000000000000000000000000..5713a364c0f53d5fc5f4804fea9526f68485eb45 GIT binary patch literal 399 zcmV;A0dW3!0j-fuZ<|06hI`&$vG*$Je!v1!8x@exkijIQaB75g+z>55-W%0nCe{HwkD=9s0M>L zt8RpdXeqHxML|rBY$k+~CL@FxB9}O)gsNN!;Q;YER{a@zqN`N{`9Ka0oC__!?&ha#*7td-VDepJCpU3!+;W$0ctV{yaY61~BZJ?7V-`h-v#bdTQ zJ_ESebgSk}RL7Tgc1j=7JmKw0^DgGbb@w+B_|vv%(u;H^OUiFziJQF_VV?RXfHQrH zjcc$NejI|;Eh4uaTW4tZ#w}57FISn=asTCaZ4Czpk8joXLWbd`U1P%wUwAy0jnilV tBV=E_Q|R*MsKaHucB@}y^bP#A!{^@r%mCRi{YMpW>rXcL;12|MtZg1{#Q*>R literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f new file mode 100644 index 0000000000000000000000000000000000000000..57eb72be65a28d5f689a43f00374ea6addbeb584 GIT binary patch literal 54 zcmbH&;f?#!jCb#dcrnM>^Wl4u_wy@? KBpGyb1tI_?PZjn6 literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 new file mode 100644 index 0000000000000000000000000000000000000000..be32d0e3b5368ab64f56d0d5e1458235f46fcaeb GIT binary patch literal 54 zcmV-60LlM&0ZYosPf{>7VDL!I$;sDID99XD~D{Ff%bx2y%6F@paY9O<|b&Ja)$I^-c%hpWMg7`k?Y> M)gq4$08!%+@=25!`2YX_ literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 new file mode 100644 index 0000000000000000000000000000000000000000..5d38589c034979d3a28af66bfc520c73cea959a3 GIT binary patch literal 54 zcmV-60LlM&0V^p=O;s>9XD~D{Ff%bx2y%6F@paY9O<`CcrnY6F$m-Kg*KD_+;Lx#g M4|^&N05>xaVkvSJ$p8QV literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature new file mode 100644 index 00000000000..c030c81b14e --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature @@ -0,0 +1 @@ +1ef73e8a15f4920afa1bd5d0fa1464e745f7e4d6 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master new file mode 100644 index 00000000000..ddb3fb20bd3 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master @@ -0,0 +1 @@ +02fcc183ad25f086aaec562224abc1b323ebaaa9 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/README.md b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/README.md new file mode 100644 index 00000000000..82ac08af7cb --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/README.md @@ -0,0 +1,3 @@ +Hello, world! +Hello, world! +Feature branch change diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/HEAD new file mode 100644 index 00000000000..7a3c5afe3e1 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/feature diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/config b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/config new file mode 100644 index 00000000000..b83d6f41726 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/config @@ -0,0 +1,10 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true + precomposeunicode = true +[remote "origin"] + url = /tmp/impacted/repo_origin + fetch = +refs/heads/*:refs/remotes/origin/* diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 new file mode 100644 index 0000000000000000000000000000000000000000..33aaacf527e71e09210c0479e92efd9e1dc54ea5 GIT binary patch literal 400 zcmV;B0dM|z0j-fwZ=)~}#rMpo@O`zdjR9k6ceMlvAq`FmkWy|A81e^jN=Xy-)30fJ z+~bZk)|;O+Pow8jcHLnFrlo%y2O)rfmEZ{3)U+i zUH1k4RD9%>Z1yjArR;tKWlNz>)D7S})FIRqRR@paKUg*A=Jn8kA5+czAY>p(79a@& z=A_xi|KJ+P5DPQdE}W@i)m}8IRf(BgJ#A0XF+)*$npl$rCTRm6&@QNxa97w?xv1vZ z@|0^}w(6Jdpo^ZlcJ`9a;k4ludix=!!EuUr9{9>FRC<<9#Kr8LyQnR^5V6!ZH89b5 zeX-6DN4G3kdfYs_Z)+othFL4Od4BH$NTJ0;rD5kZ2|;on-+rOI3n&S&}F3=`z{yN@DrlyL#$cnf3B#41Ve=^Fzmua7D&^!@jM8Ao-S*@~H$>`+9 zC+#OQSzF>&uCdMnjzvOk0B0KAy<8p_A$yR8e;;SpJ8I?Is660)yiin;%U`{V^*Idj zvDoz2Qs81rM`;ixZI6B-M(956i;Qbs_1Ros(@U9sesp0z< Jz&|MVpSURSxc~qF literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 new file mode 100644 index 0000000000000000000000000000000000000000..5713a364c0f53d5fc5f4804fea9526f68485eb45 GIT binary patch literal 399 zcmV;A0dW3!0j-fuZ<|06hI`&$vG*$Je!v1!8x@exkijIQaB75g+z>55-W%0nCe{HwkD=9s0M>L zt8RpdXeqHxML|rBY$k+~CL@FxB9}O)gsNN!;Q;YER{a@zqN`N{`9Ka0oC__!?&ha#*7td-VDepJCpU3!+;W$0ctV{yaY61~BZJ?7V-`h-v#bdTQ zJ_ESebgSk}RL7Tgc1j=7JmKw0^DgGbb@w+B_|vv%(u;H^OUiFziJQF_VV?RXfHQrH zjcc$NejI|;Eh4uaTW4tZ#w}57FISn=asTCaZ4Czpk8joXLWbd`U1P%wUwAy0jnilV tBV=E_Q|R*MsKaHucB@}y^bP#A!{^@r%mCRi{YMpW>rXcL;12|MtZg1{#Q*>R literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f new file mode 100644 index 0000000000000000000000000000000000000000..57eb72be65a28d5f689a43f00374ea6addbeb584 GIT binary patch literal 54 zcmbH&;f?#!jCb#dcrnM>^Wl4u_wy@? KBpGyb1tI_?PZjn6 literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 new file mode 100644 index 0000000000000000000000000000000000000000..be32d0e3b5368ab64f56d0d5e1458235f46fcaeb GIT binary patch literal 54 zcmV-60LlM&0ZYosPf{>7VDL!I$;sDID99XD~D{Ff%bx2y%6F@paY9O<|b&Ja)$I^-c%hpWMg7`k?Y> M)gq4$08!%+@=25!`2YX_ literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 new file mode 100644 index 0000000000000000000000000000000000000000..5d38589c034979d3a28af66bfc520c73cea959a3 GIT binary patch literal 54 zcmV-60LlM&0V^p=O;s>9XD~D{Ff%bx2y%6F@paY9O<`CcrnY6F$m-Kg*KD_+;Lx#g M4|^&N05>xaVkvSJ$p8QV literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/feature new file mode 100644 index 00000000000..c030c81b14e --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/feature @@ -0,0 +1 @@ +1ef73e8a15f4920afa1bd5d0fa1464e745f7e4d6 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/master b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/master new file mode 100644 index 00000000000..ddb3fb20bd3 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/master @@ -0,0 +1 @@ +02fcc183ad25f086aaec562224abc1b323ebaaa9 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/feature new file mode 100644 index 00000000000..c030c81b14e --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/feature @@ -0,0 +1 @@ +1ef73e8a15f4920afa1bd5d0fa1464e745f7e4d6 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/master b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/master new file mode 100644 index 00000000000..ddb3fb20bd3 --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/master @@ -0,0 +1 @@ +02fcc183ad25f086aaec562224abc1b323ebaaa9 From c558a8652751917d10c38b66314d67aba1a235e6 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Wed, 4 Jun 2025 14:28:32 +0200 Subject: [PATCH 18/28] remove repo_origin folder --- .../ci/git/impacted/repo_origin/HEAD | 1 - .../ci/git/impacted/repo_origin/config | 6 - .../ci/git/impacted/repo_origin/description | 1 - .../repo_origin/hooks/applypatch-msg.sample | 15 -- .../repo_origin/hooks/commit-msg.sample | 24 --- .../hooks/fsmonitor-watchman.sample | 174 ------------------ .../repo_origin/hooks/post-update.sample | 8 - .../repo_origin/hooks/pre-applypatch.sample | 14 -- .../repo_origin/hooks/pre-commit.sample | 49 ----- .../repo_origin/hooks/pre-merge-commit.sample | 13 -- .../repo_origin/hooks/pre-push.sample | 53 ------ .../repo_origin/hooks/pre-rebase.sample | 169 ----------------- .../repo_origin/hooks/pre-receive.sample | 24 --- .../hooks/prepare-commit-msg.sample | 42 ----- .../repo_origin/hooks/push-to-checkout.sample | 78 -------- .../hooks/sendemail-validate.sample | 77 -------- .../impacted/repo_origin/hooks/update.sample | 128 ------------- .../ci/git/impacted/repo_origin/info/exclude | 6 - .../02/fcc183ad25f086aaec562224abc1b323ebaaa9 | Bin 400 -> 0 bytes .../07/30f8c84174f476a9493f9d779640d7c971a2ef | Bin 363 -> 0 bytes .../1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 | Bin 399 -> 0 bytes .../3b/bf06262d9604dc0667c1e96b13fbf88f25a43f | Bin 54 -> 0 bytes .../82/ac08af7cb3071716559cc26257ee21dfc8e4d3 | Bin 54 -> 0 bytes .../95/e75d98dbaf42c1efc9be0405e079f97aa24888 | Bin 32 -> 0 bytes .../af/5626b4a114abcb82d63db7c8082c3c4756e51b | Bin 30 -> 0 bytes .../e0/dea118958b3ce7d0b353aaf37177a4eac87d59 | Bin 54 -> 0 bytes .../eb/fd7499dae526dcbaf30e1250b1f875946729f8 | Bin 54 -> 0 bytes .../impacted/repo_origin/refs/heads/feature | 1 - .../impacted/repo_origin/refs/heads/master | 1 - 29 files changed, 884 deletions(-) delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/HEAD delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/config delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/description delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/applypatch-msg.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/commit-msg.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/fsmonitor-watchman.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/post-update.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-applypatch.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-commit.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-merge-commit.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-push.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-rebase.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-receive.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/prepare-commit-msg.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/push-to-checkout.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/sendemail-validate.sample delete mode 100755 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/update.sample delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/info/exclude delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/07/30f8c84174f476a9493f9d779640d7c971a2ef delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/95/e75d98dbaf42c1efc9be0405e079f97aa24888 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/e0/dea118958b3ce7d0b353aaf37177a4eac87d59 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/HEAD deleted file mode 100644 index cb089cd89a7..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/master diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/config b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/config deleted file mode 100644 index e6da231579b..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/config +++ /dev/null @@ -1,6 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = true - bare = true - ignorecase = true - precomposeunicode = true diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/description b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/description deleted file mode 100644 index 498b267a8c7..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/applypatch-msg.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/applypatch-msg.sample deleted file mode 100755 index a5d7b84a673..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/applypatch-msg.sample +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# -# An example hook script to check the commit log message taken by -# applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. The hook is -# allowed to edit the commit message file. -# -# To enable this hook, rename this file to "applypatch-msg". - -. git-sh-setup -commitmsg="$(git rev-parse --git-path hooks/commit-msg)" -test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} -: diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/commit-msg.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/commit-msg.sample deleted file mode 100755 index b58d1184a9d..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/commit-msg.sample +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# -# An example hook script to check the commit log message. -# Called by "git commit" with one argument, the name of the file -# that has the commit message. The hook should exit with non-zero -# status after issuing an appropriate message if it wants to stop the -# commit. The hook is allowed to edit the commit message file. -# -# To enable this hook, rename this file to "commit-msg". - -# Uncomment the below to add a Signed-off-by line to the message. -# Doing this in a hook is a bad idea in general, but the prepare-commit-msg -# hook is more suited to it. -# -# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" - -# This example catches duplicate Signed-off-by lines. - -test "" = "$(grep '^Signed-off-by: ' "$1" | - sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { - echo >&2 Duplicate Signed-off-by lines. - exit 1 -} diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/fsmonitor-watchman.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/fsmonitor-watchman.sample deleted file mode 100755 index 23e856f5dee..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/fsmonitor-watchman.sample +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use IPC::Open2; - -# An example hook script to integrate Watchman -# (https://facebook.github.io/watchman/) with git to speed up detecting -# new and modified files. -# -# The hook is passed a version (currently 2) and last update token -# formatted as a string and outputs to stdout a new update token and -# all files that have been modified since the update token. Paths must -# be relative to the root of the working tree and separated by a single NUL. -# -# To enable this hook, rename this file to "query-watchman" and set -# 'git config core.fsmonitor .git/hooks/query-watchman' -# -my ($version, $last_update_token) = @ARGV; - -# Uncomment for debugging -# print STDERR "$0 $version $last_update_token\n"; - -# Check the hook interface version -if ($version ne 2) { - die "Unsupported query-fsmonitor hook version '$version'.\n" . - "Falling back to scanning...\n"; -} - -my $git_work_tree = get_working_dir(); - -my $retry = 1; - -my $json_pkg; -eval { - require JSON::XS; - $json_pkg = "JSON::XS"; - 1; -} or do { - require JSON::PP; - $json_pkg = "JSON::PP"; -}; - -launch_watchman(); - -sub launch_watchman { - my $o = watchman_query(); - if (is_work_tree_watched($o)) { - output_result($o->{clock}, @{$o->{files}}); - } -} - -sub output_result { - my ($clockid, @files) = @_; - - # Uncomment for debugging watchman output - # open (my $fh, ">", ".git/watchman-output.out"); - # binmode $fh, ":utf8"; - # print $fh "$clockid\n@files\n"; - # close $fh; - - binmode STDOUT, ":utf8"; - print $clockid; - print "\0"; - local $, = "\0"; - print @files; -} - -sub watchman_clock { - my $response = qx/watchman clock "$git_work_tree"/; - die "Failed to get clock id on '$git_work_tree'.\n" . - "Falling back to scanning...\n" if $? != 0; - - return $json_pkg->new->utf8->decode($response); -} - -sub watchman_query { - my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') - or die "open2() failed: $!\n" . - "Falling back to scanning...\n"; - - # In the query expression below we're asking for names of files that - # changed since $last_update_token but not from the .git folder. - # - # To accomplish this, we're using the "since" generator to use the - # recency index to select candidate nodes and "fields" to limit the - # output to file names only. Then we're using the "expression" term to - # further constrain the results. - my $last_update_line = ""; - if (substr($last_update_token, 0, 1) eq "c") { - $last_update_token = "\"$last_update_token\""; - $last_update_line = qq[\n"since": $last_update_token,]; - } - my $query = <<" END"; - ["query", "$git_work_tree", {$last_update_line - "fields": ["name"], - "expression": ["not", ["dirname", ".git"]] - }] - END - - # Uncomment for debugging the watchman query - # open (my $fh, ">", ".git/watchman-query.json"); - # print $fh $query; - # close $fh; - - print CHLD_IN $query; - close CHLD_IN; - my $response = do {local $/; }; - - # Uncomment for debugging the watch response - # open ($fh, ">", ".git/watchman-response.json"); - # print $fh $response; - # close $fh; - - die "Watchman: command returned no output.\n" . - "Falling back to scanning...\n" if $response eq ""; - die "Watchman: command returned invalid output: $response\n" . - "Falling back to scanning...\n" unless $response =~ /^\{/; - - return $json_pkg->new->utf8->decode($response); -} - -sub is_work_tree_watched { - my ($output) = @_; - my $error = $output->{error}; - if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) { - $retry--; - my $response = qx/watchman watch "$git_work_tree"/; - die "Failed to make watchman watch '$git_work_tree'.\n" . - "Falling back to scanning...\n" if $? != 0; - $output = $json_pkg->new->utf8->decode($response); - $error = $output->{error}; - die "Watchman: $error.\n" . - "Falling back to scanning...\n" if $error; - - # Uncomment for debugging watchman output - # open (my $fh, ">", ".git/watchman-output.out"); - # close $fh; - - # Watchman will always return all files on the first query so - # return the fast "everything is dirty" flag to git and do the - # Watchman query just to get it over with now so we won't pay - # the cost in git to look up each individual file. - my $o = watchman_clock(); - $error = $output->{error}; - - die "Watchman: $error.\n" . - "Falling back to scanning...\n" if $error; - - output_result($o->{clock}, ("/")); - $last_update_token = $o->{clock}; - - eval { launch_watchman() }; - return 0; - } - - die "Watchman: $error.\n" . - "Falling back to scanning...\n" if $error; - - return 1; -} - -sub get_working_dir { - my $working_dir; - if ($^O =~ 'msys' || $^O =~ 'cygwin') { - $working_dir = Win32::GetCwd(); - $working_dir =~ tr/\\/\//; - } else { - require Cwd; - $working_dir = Cwd::cwd(); - } - - return $working_dir; -} diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/post-update.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/post-update.sample deleted file mode 100755 index ec17ec1939b..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/post-update.sample +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare a packed repository for use over -# dumb transports. -# -# To enable this hook, rename this file to "post-update". - -exec git update-server-info diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-applypatch.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-applypatch.sample deleted file mode 100755 index 4142082bcb9..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-applypatch.sample +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed -# by applypatch from an e-mail message. -# -# The hook should exit with non-zero status after issuing an -# appropriate message if it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-applypatch". - -. git-sh-setup -precommit="$(git rev-parse --git-path hooks/pre-commit)" -test -x "$precommit" && exec "$precommit" ${1+"$@"} -: diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-commit.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-commit.sample deleted file mode 100755 index 29ed5ee486a..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-commit.sample +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed. -# Called by "git commit" with no arguments. The hook should -# exit with non-zero status after issuing an appropriate message if -# it wants to stop the commit. -# -# To enable this hook, rename this file to "pre-commit". - -if git rev-parse --verify HEAD >/dev/null 2>&1 -then - against=HEAD -else - # Initial commit: diff against an empty tree object - against=$(git hash-object -t tree /dev/null) -fi - -# If you want to allow non-ASCII filenames set this variable to true. -allownonascii=$(git config --type=bool hooks.allownonascii) - -# Redirect output to stderr. -exec 1>&2 - -# Cross platform projects tend to avoid non-ASCII filenames; prevent -# them from being added to the repository. We exploit the fact that the -# printable range starts at the space character and ends with tilde. -if [ "$allownonascii" != "true" ] && - # Note that the use of brackets around a tr range is ok here, (it's - # even required, for portability to Solaris 10's /usr/bin/tr), since - # the square bracket bytes happen to fall in the designated range. - test $(git diff-index --cached --name-only --diff-filter=A -z $against | - LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 -then - cat <<\EOF -Error: Attempt to add a non-ASCII file name. - -This can cause problems if you want to work with people on other platforms. - -To be portable it is advisable to rename the file. - -If you know what you are doing you can disable this check using: - - git config hooks.allownonascii true -EOF - exit 1 -fi - -# If there are whitespace errors, print the offending file names and fail. -exec git diff-index --check --cached $against -- diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-merge-commit.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-merge-commit.sample deleted file mode 100755 index 399eab1924e..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-merge-commit.sample +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -# -# An example hook script to verify what is about to be committed. -# Called by "git merge" with no arguments. The hook should -# exit with non-zero status after issuing an appropriate message to -# stderr if it wants to stop the merge commit. -# -# To enable this hook, rename this file to "pre-merge-commit". - -. git-sh-setup -test -x "$GIT_DIR/hooks/pre-commit" && - exec "$GIT_DIR/hooks/pre-commit" -: diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-push.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-push.sample deleted file mode 100755 index 4ce688d32b7..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-push.sample +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh - -# An example hook script to verify what is about to be pushed. Called by "git -# push" after it has checked the remote status, but before anything has been -# pushed. If this script exits with a non-zero status nothing will be pushed. -# -# This hook is called with the following parameters: -# -# $1 -- Name of the remote to which the push is being done -# $2 -- URL to which the push is being done -# -# If pushing without using a named remote those arguments will be equal. -# -# Information about the commits which are being pushed is supplied as lines to -# the standard input in the form: -# -# -# -# This sample shows how to prevent push of commits where the log message starts -# with "WIP" (work in progress). - -remote="$1" -url="$2" - -zero=$(git hash-object --stdin &2 "Found WIP commit in $local_ref, not pushing" - exit 1 - fi - fi -done - -exit 0 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-rebase.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-rebase.sample deleted file mode 100755 index 6cbef5c370d..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-rebase.sample +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2006, 2008 Junio C Hamano -# -# The "pre-rebase" hook is run just before "git rebase" starts doing -# its job, and can prevent the command from running by exiting with -# non-zero status. -# -# The hook is called with the following parameters: -# -# $1 -- the upstream the series was forked from. -# $2 -- the branch being rebased (or empty when rebasing the current branch). -# -# This sample shows how to prevent topic branches that are already -# merged to 'next' branch from getting rebased, because allowing it -# would result in rebasing already published history. - -publish=next -basebranch="$1" -if test "$#" = 2 -then - topic="refs/heads/$2" -else - topic=`git symbolic-ref HEAD` || - exit 0 ;# we do not interrupt rebasing detached HEAD -fi - -case "$topic" in -refs/heads/??/*) - ;; -*) - exit 0 ;# we do not interrupt others. - ;; -esac - -# Now we are dealing with a topic branch being rebased -# on top of master. Is it OK to rebase it? - -# Does the topic really exist? -git show-ref -q "$topic" || { - echo >&2 "No such branch $topic" - exit 1 -} - -# Is topic fully merged to master? -not_in_master=`git rev-list --pretty=oneline ^master "$topic"` -if test -z "$not_in_master" -then - echo >&2 "$topic is fully merged to master; better remove it." - exit 1 ;# we could allow it, but there is no point. -fi - -# Is topic ever merged to next? If so you should not be rebasing it. -only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` -only_next_2=`git rev-list ^master ${publish} | sort` -if test "$only_next_1" = "$only_next_2" -then - not_in_topic=`git rev-list "^$topic" master` - if test -z "$not_in_topic" - then - echo >&2 "$topic is already up to date with master" - exit 1 ;# we could allow it, but there is no point. - else - exit 0 - fi -else - not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` - /usr/bin/perl -e ' - my $topic = $ARGV[0]; - my $msg = "* $topic has commits already merged to public branch:\n"; - my (%not_in_next) = map { - /^([0-9a-f]+) /; - ($1 => 1); - } split(/\n/, $ARGV[1]); - for my $elem (map { - /^([0-9a-f]+) (.*)$/; - [$1 => $2]; - } split(/\n/, $ARGV[2])) { - if (!exists $not_in_next{$elem->[0]}) { - if ($msg) { - print STDERR $msg; - undef $msg; - } - print STDERR " $elem->[1]\n"; - } - } - ' "$topic" "$not_in_next" "$not_in_master" - exit 1 -fi - -<<\DOC_END - -This sample hook safeguards topic branches that have been -published from being rewound. - -The workflow assumed here is: - - * Once a topic branch forks from "master", "master" is never - merged into it again (either directly or indirectly). - - * Once a topic branch is fully cooked and merged into "master", - it is deleted. If you need to build on top of it to correct - earlier mistakes, a new topic branch is created by forking at - the tip of the "master". This is not strictly necessary, but - it makes it easier to keep your history simple. - - * Whenever you need to test or publish your changes to topic - branches, merge them into "next" branch. - -The script, being an example, hardcodes the publish branch name -to be "next", but it is trivial to make it configurable via -$GIT_DIR/config mechanism. - -With this workflow, you would want to know: - -(1) ... if a topic branch has ever been merged to "next". Young - topic branches can have stupid mistakes you would rather - clean up before publishing, and things that have not been - merged into other branches can be easily rebased without - affecting other people. But once it is published, you would - not want to rewind it. - -(2) ... if a topic branch has been fully merged to "master". - Then you can delete it. More importantly, you should not - build on top of it -- other people may already want to - change things related to the topic as patches against your - "master", so if you need further changes, it is better to - fork the topic (perhaps with the same name) afresh from the - tip of "master". - -Let's look at this example: - - o---o---o---o---o---o---o---o---o---o "next" - / / / / - / a---a---b A / / - / / / / - / / c---c---c---c B / - / / / \ / - / / / b---b C \ / - / / / / \ / - ---o---o---o---o---o---o---o---o---o---o---o "master" - - -A, B and C are topic branches. - - * A has one fix since it was merged up to "next". - - * B has finished. It has been fully merged up to "master" and "next", - and is ready to be deleted. - - * C has not merged to "next" at all. - -We would want to allow C to be rebased, refuse A, and encourage -B to be deleted. - -To compute (1): - - git rev-list ^master ^topic next - git rev-list ^master next - - if these match, topic has not merged in next at all. - -To compute (2): - - git rev-list master..topic - - if this is empty, it is fully merged to "master". - -DOC_END diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-receive.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-receive.sample deleted file mode 100755 index a1fd29ec148..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/pre-receive.sample +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# -# An example hook script to make use of push options. -# The example simply echoes all push options that start with 'echoback=' -# and rejects all pushes when the "reject" push option is used. -# -# To enable this hook, rename this file to "pre-receive". - -if test -n "$GIT_PUSH_OPTION_COUNT" -then - i=0 - while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" - do - eval "value=\$GIT_PUSH_OPTION_$i" - case "$value" in - echoback=*) - echo "echo from the pre-receive-hook: ${value#*=}" >&2 - ;; - reject) - exit 1 - esac - i=$((i + 1)) - done -fi diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/prepare-commit-msg.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/prepare-commit-msg.sample deleted file mode 100755 index 10fa14c5ab0..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/prepare-commit-msg.sample +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh -# -# An example hook script to prepare the commit log message. -# Called by "git commit" with the name of the file that has the -# commit message, followed by the description of the commit -# message's source. The hook's purpose is to edit the commit -# message file. If the hook fails with a non-zero status, -# the commit is aborted. -# -# To enable this hook, rename this file to "prepare-commit-msg". - -# This hook includes three examples. The first one removes the -# "# Please enter the commit message..." help message. -# -# The second includes the output of "git diff --name-status -r" -# into the message, just before the "git status" output. It is -# commented because it doesn't cope with --amend or with squashed -# commits. -# -# The third example adds a Signed-off-by line to the message, that can -# still be edited. This is rarely a good idea. - -COMMIT_MSG_FILE=$1 -COMMIT_SOURCE=$2 -SHA1=$3 - -/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" - -# case "$COMMIT_SOURCE,$SHA1" in -# ,|template,) -# /usr/bin/perl -i.bak -pe ' -# print "\n" . `git diff --cached --name-status -r` -# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; -# *) ;; -# esac - -# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') -# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" -# if test -z "$COMMIT_SOURCE" -# then -# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" -# fi diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/push-to-checkout.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/push-to-checkout.sample deleted file mode 100755 index af5a0c0018b..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/push-to-checkout.sample +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/sh - -# An example hook script to update a checked-out tree on a git push. -# -# This hook is invoked by git-receive-pack(1) when it reacts to git -# push and updates reference(s) in its repository, and when the push -# tries to update the branch that is currently checked out and the -# receive.denyCurrentBranch configuration variable is set to -# updateInstead. -# -# By default, such a push is refused if the working tree and the index -# of the remote repository has any difference from the currently -# checked out commit; when both the working tree and the index match -# the current commit, they are updated to match the newly pushed tip -# of the branch. This hook is to be used to override the default -# behaviour; however the code below reimplements the default behaviour -# as a starting point for convenient modification. -# -# The hook receives the commit with which the tip of the current -# branch is going to be updated: -commit=$1 - -# It can exit with a non-zero status to refuse the push (when it does -# so, it must not modify the index or the working tree). -die () { - echo >&2 "$*" - exit 1 -} - -# Or it can make any necessary changes to the working tree and to the -# index to bring them to the desired state when the tip of the current -# branch is updated to the new commit, and exit with a zero status. -# -# For example, the hook can simply run git read-tree -u -m HEAD "$1" -# in order to emulate git fetch that is run in the reverse direction -# with git push, as the two-tree form of git read-tree -u -m is -# essentially the same as git switch or git checkout that switches -# branches while keeping the local changes in the working tree that do -# not interfere with the difference between the branches. - -# The below is a more-or-less exact translation to shell of the C code -# for the default behaviour for git's push-to-checkout hook defined in -# the push_to_deploy() function in builtin/receive-pack.c. -# -# Note that the hook will be executed from the repository directory, -# not from the working tree, so if you want to perform operations on -# the working tree, you will have to adapt your code accordingly, e.g. -# by adding "cd .." or using relative paths. - -if ! git update-index -q --ignore-submodules --refresh -then - die "Up-to-date check failed" -fi - -if ! git diff-files --quiet --ignore-submodules -- -then - die "Working directory has unstaged changes" -fi - -# This is a rough translation of: -# -# head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX -if git cat-file -e HEAD 2>/dev/null -then - head=HEAD -else - head=$(git hash-object -t tree --stdin &2 - exit 1 -} - -unset GIT_DIR GIT_WORK_TREE -cd "$worktree" && - -if grep -q "^diff --git " "$1" -then - validate_patch "$1" -else - validate_cover_letter "$1" -fi && - -if test "$GIT_SENDEMAIL_FILE_COUNTER" = "$GIT_SENDEMAIL_FILE_TOTAL" -then - git config --unset-all sendemail.validateWorktree && - trap 'git worktree remove -ff "$worktree"' EXIT && - validate_series -fi diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/update.sample b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/update.sample deleted file mode 100755 index c4d426bc6ee..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/hooks/update.sample +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/sh -# -# An example hook script to block unannotated tags from entering. -# Called by "git receive-pack" with arguments: refname sha1-old sha1-new -# -# To enable this hook, rename this file to "update". -# -# Config -# ------ -# hooks.allowunannotated -# This boolean sets whether unannotated tags will be allowed into the -# repository. By default they won't be. -# hooks.allowdeletetag -# This boolean sets whether deleting tags will be allowed in the -# repository. By default they won't be. -# hooks.allowmodifytag -# This boolean sets whether a tag may be modified after creation. By default -# it won't be. -# hooks.allowdeletebranch -# This boolean sets whether deleting branches will be allowed in the -# repository. By default they won't be. -# hooks.denycreatebranch -# This boolean sets whether remotely creating branches will be denied -# in the repository. By default this is allowed. -# - -# --- Command line -refname="$1" -oldrev="$2" -newrev="$3" - -# --- Safety check -if [ -z "$GIT_DIR" ]; then - echo "Don't run this script from the command line." >&2 - echo " (if you want, you could supply GIT_DIR then run" >&2 - echo " $0 )" >&2 - exit 1 -fi - -if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then - echo "usage: $0 " >&2 - exit 1 -fi - -# --- Config -allowunannotated=$(git config --type=bool hooks.allowunannotated) -allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch) -denycreatebranch=$(git config --type=bool hooks.denycreatebranch) -allowdeletetag=$(git config --type=bool hooks.allowdeletetag) -allowmodifytag=$(git config --type=bool hooks.allowmodifytag) - -# check for no description -projectdesc=$(sed -e '1q' "$GIT_DIR/description") -case "$projectdesc" in -"Unnamed repository"* | "") - echo "*** Project description file hasn't been set" >&2 - exit 1 - ;; -esac - -# --- Check types -# if $newrev is 0000...0000, it's a commit to delete a ref. -zero=$(git hash-object --stdin &2 - echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 - exit 1 - fi - ;; - refs/tags/*,delete) - # delete tag - if [ "$allowdeletetag" != "true" ]; then - echo "*** Deleting a tag is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/tags/*,tag) - # annotated tag - if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 - then - echo "*** Tag '$refname' already exists." >&2 - echo "*** Modifying a tag is not allowed in this repository." >&2 - exit 1 - fi - ;; - refs/heads/*,commit) - # branch - if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then - echo "*** Creating a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/heads/*,delete) - # delete branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - refs/remotes/*,commit) - # tracking branch - ;; - refs/remotes/*,delete) - # delete tracking branch - if [ "$allowdeletebranch" != "true" ]; then - echo "*** Deleting a tracking branch is not allowed in this repository" >&2 - exit 1 - fi - ;; - *) - # Anything else (is there anything else?) - echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 - exit 1 - ;; -esac - -# --- Finished -exit 0 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/info/exclude b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/info/exclude deleted file mode 100644 index a5196d1be8f..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 deleted file mode 100644 index 33aaacf527e71e09210c0479e92efd9e1dc54ea5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 400 zcmV;B0dM|z0j-fwZ=)~}#rMpo@O`zdjR9k6ceMlvAq`FmkWy|A81e^jN=Xy-)30fJ z+~bZk)|;O+Pow8jcHLnFrlo%y2O)rfmEZ{3)U+i zUH1k4RD9%>Z1yjArR;tKWlNz>)D7S})FIRqRR@paKUg*A=Jn8kA5+czAY>p(79a@& z=A_xi|KJ+P5DPQdE}W@i)m}8IRf(BgJ#A0XF+)*$npl$rCTRm6&@QNxa97w?xv1vZ z@|0^}w(6Jdpo^ZlcJ`9a;k4ludix=!!EuUr9{9>FRC<<9#Kr8LyQnR^5V6!ZH89b5 zeX-6DN4G3kdfYs_Z)+othFL4Od4BH$NTJ0;rD5kZ2|;on-+rOI3n&S&}F3=`z{yN@DrlyL#$cnf3B#41Ve=^Fzmua7D&^!@jM8Ao-S*@~H$>`+9 zC+#OQSzF>&uCdMnjzvOk0B0KAy<8p_A$yR8e;;SpJ8I?Is660)yiin;%U`{V^*Idj zvDoz2Qs81rM`;ixZI6B-M(956i;Qbs_1Ros(@U9sesp0z< Jz&|MVpSURSxc~qF diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 deleted file mode 100644 index 5713a364c0f53d5fc5f4804fea9526f68485eb45..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 399 zcmV;A0dW3!0j-fuZ<|06hI`&$vG*$Je!v1!8x@exkijIQaB75g+z>55-W%0nCe{HwkD=9s0M>L zt8RpdXeqHxML|rBY$k+~CL@FxB9}O)gsNN!;Q;YER{a@zqN`N{`9Ka0oC__!?&ha#*7td-VDepJCpU3!+;W$0ctV{yaY61~BZJ?7V-`h-v#bdTQ zJ_ESebgSk}RL7Tgc1j=7JmKw0^DgGbb@w+B_|vv%(u;H^OUiFziJQF_VV?RXfHQrH zjcc$NejI|;Eh4uaTW4tZ#w}57FISn=asTCaZ4Czpk8joXLWbd`U1P%wUwAy0jnilV tBV=E_Q|R*MsKaHucB@}y^bP#A!{^@r%mCRi{YMpW>rXcL;12|MtZg1{#Q*>R diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f deleted file mode 100644 index 57eb72be65a28d5f689a43f00374ea6addbeb584..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmbH&;f?#!jCb#dcrnM>^Wl4u_wy@? KBpGyb1tI_?PZjn6 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 deleted file mode 100644 index be32d0e3b5368ab64f56d0d5e1458235f46fcaeb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmV-60LlM&0ZYosPf{>7VDL!I$;sDID99XD~D{Ff%bx2y%6F@paY9O<|b&Ja)$I^-c%hpWMg7`k?Y> M)gq4$08!%+@=25!`2YX_ diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 deleted file mode 100644 index 5d38589c034979d3a28af66bfc520c73cea959a3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmV-60LlM&0V^p=O;s>9XD~D{Ff%bx2y%6F@paY9O<`CcrnY6F$m-Kg*KD_+;Lx#g M4|^&N05>xaVkvSJ$p8QV diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature deleted file mode 100644 index c030c81b14e..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature +++ /dev/null @@ -1 +0,0 @@ -1ef73e8a15f4920afa1bd5d0fa1464e745f7e4d6 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master deleted file mode 100644 index ddb3fb20bd3..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -02fcc183ad25f086aaec562224abc1b323ebaaa9 From 0fac3ae245a7599af3ed70a70ea2544610777916 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Wed, 4 Jun 2025 15:43:28 +0200 Subject: [PATCH 19/28] fix forbidden apis --- .../civisibility/git/tree/ShellGitClient.java | 10 ++++++++-- .../civisibility/git/tree/GitClientTest.groovy | 15 ++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java index d8a1cc2068d..9f49d8daceb 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java @@ -9,6 +9,7 @@ import datadog.trace.civisibility.diff.LineDiff; import datadog.trace.civisibility.utils.ShellCommandExecutor; import datadog.trace.util.Strings; +import de.thetaphi.forbiddenapis.SuppressForbidden; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; @@ -41,6 +42,7 @@ public class ShellGitClient implements GitClient { Arrays.asList("main", "master", "preprod", "prod", "dev", "development", "trunk"); private static final Pattern BASE_BRANCH_PATTERN = Pattern.compile("^(" + String.join("|", POSSIBLE_BASE_BRANCHES) + "|release/.*|hotfix/.*)$"); + private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+"); private static final String ORIGIN = "origin"; private final CiVisibilityMetricCollector metricCollector; @@ -638,6 +640,7 @@ public String getBaseCommitSha( }); } + @SuppressForbidden // split on single-character uses fast path public String getRemoteName() throws IOException, InterruptedException, TimeoutException { try { String remote = @@ -679,7 +682,10 @@ public String getSourceBranch() throws IOException, InterruptedException, Timeou } public String removeRemotePrefix(String branch, String remoteName) { - return branch.replaceFirst("^" + remoteName + "/", ""); + if (branch.indexOf(remoteName + "/") != 0) { + return branch; + } + return branch.substring(remoteName.length() + 1); } public boolean isBaseLikeBranch(String branch, String remoteName) { @@ -857,7 +863,7 @@ public Map computeBranchMetrics( candidate + "..." + sourceBranch) .trim(); - String[] counts = countsResult.split("\\s+"); + String[] counts = WHITESPACE_PATTERN.split(countsResult); int behind = Integer.parseInt(counts[0]); int ahead = Integer.parseInt(counts[1]); diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy index 0a79902f957..3300614faab 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy @@ -333,13 +333,14 @@ class GitClientTest extends Specification { gitClient.removeRemotePrefix(branchName, remoteName) == expected where: - branchName | remoteName | expected - "origin/main" | "origin" | "main" - "upstream/master" | "upstream" | "master" - "origin/feature/test" | "origin" | "feature/test" - "main" | "origin" | "main" - "upstream/main" | "origin" | "upstream/main" - "" | "origin" | "" + branchName | remoteName | expected + "origin/main" | "origin" | "main" + "upstream/master" | "upstream" | "master" + "origin/feature/test" | "origin" | "feature/test" + "main" | "origin" | "main" + "upstream/main" | "origin" | "upstream/main" + "upstream/bad_origin/main" | "origin" | "upstream/bad_origin/main" + "" | "origin" | "" } def "test base like branch match"() { From 0e6bc2d8a0f9909456c828809a7195c84c381768 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Wed, 4 Jun 2025 17:44:49 +0200 Subject: [PATCH 20/28] remove smoke test (no backend implementation anymore) --- .../datadog/smoketest/MockBackend.groovy | 23 - .../datadog/smoketest/MavenSmokeTest.groovy | 21 - .../coverages.ftl | 19 - .../events.ftl | 393 ------------------ .../pom.xml | 62 --- .../main/java/datadog/smoke/Calculator.java | 11 - .../test/java/datadog/smoke/TestSucceed.java | 18 - .../trace/api/config/CiVisibilityConfig.java | 2 - 8 files changed, 549 deletions(-) delete mode 100644 dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/coverages.ftl delete mode 100644 dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/events.ftl delete mode 100644 dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/pom.xml delete mode 100644 dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/src/main/java/datadog/smoke/Calculator.java delete mode 100644 dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/src/test/java/datadog/smoke/TestSucceed.java diff --git a/dd-smoke-tests/backend-mock/src/main/groovy/datadog/smoketest/MockBackend.groovy b/dd-smoke-tests/backend-mock/src/main/groovy/datadog/smoketest/MockBackend.groovy index 76ca256f6e9..696bea3ed65 100644 --- a/dd-smoke-tests/backend-mock/src/main/groovy/datadog/smoketest/MockBackend.groovy +++ b/dd-smoke-tests/backend-mock/src/main/groovy/datadog/smoketest/MockBackend.groovy @@ -33,7 +33,6 @@ class MockBackend implements AutoCloseable { private final Collection> flakyTests = new CopyOnWriteArrayList<>() private final Collection> knownTests = new CopyOnWriteArrayList<>() private final Collection> testManagement = new CopyOnWriteArrayList<>() - private final Collection changedFiles = new CopyOnWriteArrayList<>() private boolean itrEnabled = true private boolean codeCoverageEnabled = true @@ -55,7 +54,6 @@ class MockBackend implements AutoCloseable { flakyTests.clear() knownTests.clear() testManagement.clear() - changedFiles.clear() } @Override @@ -83,10 +81,6 @@ class MockBackend implements AutoCloseable { this.impactedTestsDetectionEnabled = impactedTestsDetectionEnabled } - void givenChangedFile(String relativePath) { - changedFiles.add(relativePath) - } - void givenKnownTests(boolean knownTests) { this.knownTestsEnabled = knownTests } @@ -331,23 +325,6 @@ class MockBackend implements AutoCloseable { response.status(200).send() } - - prefix("/api/v2/ci/tests/diffs") { - response.status(200) - .addHeader("Content-Encoding", "gzip") - .send(MockBackend.compress((""" - { - "data": { - "type": "ci_app_tests_diffs_response", - "id": "", - "attributes": { - "base_sha": "ef733331f7cee9b1c89d82df87942d8606edf3f7", - "files": [ ${changedFiles.stream().map(f -> '"' + f + '"').collect(Collectors.joining(","))} ] - } - } - } - """).bytes)) - } } } diff --git a/dd-smoke-tests/maven/src/test/groovy/datadog/smoketest/MavenSmokeTest.groovy b/dd-smoke-tests/maven/src/test/groovy/datadog/smoketest/MavenSmokeTest.groovy index 927f1ce0440..e9092d20d8d 100644 --- a/dd-smoke-tests/maven/src/test/groovy/datadog/smoketest/MavenSmokeTest.groovy +++ b/dd-smoke-tests/maven/src/test/groovy/datadog/smoketest/MavenSmokeTest.groovy @@ -107,27 +107,6 @@ class MavenSmokeTest extends CiVisibilitySmokeTest { "test_successful_maven_run_multiple_forks" | LATEST_MAVEN_VERSION | 5 | 1 | true | true | false | true | [] | 17 } - def "test impacted tests detection"() { - givenWrapperPropertiesFile(mavenVersion) - givenMavenProjectFiles(projectName) - givenMavenDependenciesAreLoaded(projectName, mavenVersion) - - mockBackend.givenImpactedTestsDetection(true) - mockBackend.givenChangedFile("src/test/java/datadog/smoke/TestSucceed.java") - - def exitCode = whenRunningMavenBuild([ - "${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_GIT_CLIENT_ENABLED)}=false" as String, - "${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_IMPACTED_TESTS_BACKEND_REQUEST_ENABLED)}=true" as String - ], [], [:]) - assert exitCode == 0 - - verifyEventsAndCoverages(projectName, "maven", mavenVersion, mockBackend.waitForEvents(5), mockBackend.waitForCoverages(1)) - - where: - projectName | mavenVersion - "test_successful_maven_run_impacted_tests" | "3.9.9" - } - def "test test management"() { givenWrapperPropertiesFile(mavenVersion) givenMavenProjectFiles(projectName) diff --git a/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/coverages.ftl b/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/coverages.ftl deleted file mode 100644 index cb8d26b550c..00000000000 --- a/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/coverages.ftl +++ /dev/null @@ -1,19 +0,0 @@ -[ { - "files" : [ { - "filename" : "src/test/java/datadog/smoke/TestSucceed.java" - }, { - "filename" : "src/main/java/datadog/smoke/Calculator.java" - } ], - "span_id" : ${content_span_id_6}, - "test_session_id" : ${content_test_session_id}, - "test_suite_id" : ${content_test_suite_id} -}, { - "files" : [ { - "filename" : "src/test/java/datadog/smoke/TestSucceed.java" - }, { - "filename" : "src/main/java/datadog/smoke/Calculator.java" - } ], - "span_id" : ${content_span_id_5}, - "test_session_id" : ${content_test_session_id}, - "test_suite_id" : ${content_test_suite_id} -} ] \ No newline at end of file diff --git a/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/events.ftl b/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/events.ftl deleted file mode 100644 index 6ff34b20a28..00000000000 --- a/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/events.ftl +++ /dev/null @@ -1,393 +0,0 @@ -[ { - "content" : { - "duration" : ${content_duration}, - "error" : 0, - "meta" : { - "_dd.p.tid" : ${content_meta__dd_p_tid}, - "_dd.test.is_user_provided_service" : "true", - "_dd.tracer_host" : ${content_meta__dd_tracer_host}, - "ci.workspace_path" : ${content_meta_ci_workspace_path}, - "component" : "maven", - "env" : "integration-test", - "language" : "jvm", - "library_version" : ${content_meta_library_version}, - "os.architecture" : ${content_meta_os_architecture}, - "os.platform" : ${content_meta_os_platform}, - "os.version" : ${content_meta_os_version}, - "runtime-id" : ${content_meta_runtime_id}, - "runtime.name" : ${content_meta_runtime_name}, - "runtime.vendor" : ${content_meta_runtime_vendor}, - "runtime.version" : ${content_meta_runtime_version}, - "span.kind" : "test_session_end", - "test.code_coverage.enabled" : "true", - "test.command" : "mvn -B test", - "test.framework" : "junit4", - "test.framework_version" : "4.13.2", - "test.itr.tests_skipping.enabled" : "true", - "test.itr.tests_skipping.type" : "test", - "test.status" : "pass", - "test.toolchain" : ${content_meta_test_toolchain}, - "test.type" : "test", - "test_session.name" : "mvn -B test" - }, - "metrics" : { - "_dd.host.vcpu_count" : ${content_metrics__dd_host_vcpu_count}, - "_dd.profiling.enabled" : 0, - "_dd.trace_span_attribute_schema" : 0, - "process_id" : ${content_metrics_process_id}, - "test.itr.tests_skipping.count" : 0 - }, - "name" : "maven.test_session", - "resource" : "Maven Smoke Tests Project", - "service" : "test-maven-service", - "start" : ${content_start}, - "test_session_id" : ${content_test_session_id} - }, - "type" : "test_session_end", - "version" : 1 -}, { - "content" : { - "duration" : ${content_duration_2}, - "error" : 0, - "meta" : { - "_dd.p.tid" : ${content_meta__dd_p_tid_2}, - "_dd.test.is_user_provided_service" : "true", - "ci.workspace_path" : ${content_meta_ci_workspace_path}, - "component" : "maven", - "env" : "integration-test", - "language" : "jvm", - "library_version" : ${content_meta_library_version}, - "os.architecture" : ${content_meta_os_architecture}, - "os.platform" : ${content_meta_os_platform}, - "os.version" : ${content_meta_os_version}, - "runtime-id" : ${content_meta_runtime_id}, - "runtime.name" : ${content_meta_runtime_name}, - "runtime.vendor" : ${content_meta_runtime_vendor}, - "runtime.version" : ${content_meta_runtime_version}, - "span.kind" : "test_module_end", - "test.code_coverage.enabled" : "true", - "test.command" : "mvn -B test", - "test.execution" : "maven-surefire-plugin:test:default-test", - "test.framework" : "junit4", - "test.framework_version" : "4.13.2", - "test.itr.tests_skipping.enabled" : "true", - "test.itr.tests_skipping.type" : "test", - "test.module" : "Maven Smoke Tests Project maven-surefire-plugin default-test", - "test.status" : "pass", - "test.type" : "test", - "test_session.name" : "mvn -B test" - }, - "metrics" : { - "_dd.host.vcpu_count" : ${content_metrics__dd_host_vcpu_count_2}, - "test.itr.tests_skipping.count" : 0 - }, - "name" : "maven.test_module", - "resource" : "Maven Smoke Tests Project maven-surefire-plugin default-test", - "service" : "test-maven-service", - "start" : ${content_start_2}, - "test_module_id" : ${content_test_module_id}, - "test_session_id" : ${content_test_session_id} - }, - "type" : "test_module_end", - "version" : 1 -}, { - "content" : { - "duration" : ${content_duration_3}, - "error" : 0, - "meta" : { - "_dd.p.tid" : ${content_meta__dd_p_tid_3}, - "_dd.test.is_user_provided_service" : "true", - "env" : "integration-test", - "execution" : "default-compile", - "language" : "jvm", - "library_version" : ${content_meta_library_version}, - "os.architecture" : ${content_meta_os_architecture}, - "os.platform" : ${content_meta_os_platform}, - "os.version" : ${content_meta_os_version}, - "plugin" : "maven-compiler-plugin", - "project" : "Maven Smoke Tests Project", - "runtime-id" : ${content_meta_runtime_id}, - "runtime.name" : ${content_meta_runtime_name}, - "runtime.vendor" : ${content_meta_runtime_vendor}, - "runtime.version" : ${content_meta_runtime_version} - }, - "metrics" : { }, - "name" : "Maven_Smoke_Tests_Project_maven_compiler_plugin_default_compile", - "parent_id" : ${content_test_session_id}, - "resource" : "Maven_Smoke_Tests_Project_maven_compiler_plugin_default_compile", - "service" : "test-maven-service", - "span_id" : ${content_span_id}, - "start" : ${content_start_3}, - "trace_id" : ${content_test_session_id} - }, - "type" : "span", - "version" : 1 -}, { - "content" : { - "duration" : ${content_duration_4}, - "error" : 0, - "meta" : { - "_dd.p.tid" : ${content_meta__dd_p_tid_4}, - "_dd.test.is_user_provided_service" : "true", - "env" : "integration-test", - "execution" : "default-testCompile", - "language" : "jvm", - "library_version" : ${content_meta_library_version}, - "os.architecture" : ${content_meta_os_architecture}, - "os.platform" : ${content_meta_os_platform}, - "os.version" : ${content_meta_os_version}, - "plugin" : "maven-compiler-plugin", - "project" : "Maven Smoke Tests Project", - "runtime-id" : ${content_meta_runtime_id}, - "runtime.name" : ${content_meta_runtime_name}, - "runtime.vendor" : ${content_meta_runtime_vendor}, - "runtime.version" : ${content_meta_runtime_version} - }, - "metrics" : { }, - "name" : "Maven_Smoke_Tests_Project_maven_compiler_plugin_default_testCompile", - "parent_id" : ${content_test_session_id}, - "resource" : "Maven_Smoke_Tests_Project_maven_compiler_plugin_default_testCompile", - "service" : "test-maven-service", - "span_id" : ${content_span_id_2}, - "start" : ${content_start_4}, - "trace_id" : ${content_test_session_id} - }, - "type" : "span", - "version" : 1 -}, { - "content" : { - "duration" : ${content_duration_5}, - "error" : 0, - "meta" : { - "_dd.p.tid" : ${content_meta__dd_p_tid_5}, - "_dd.test.is_user_provided_service" : "true", - "env" : "integration-test", - "execution" : "default-resources", - "language" : "jvm", - "library_version" : ${content_meta_library_version}, - "os.architecture" : ${content_meta_os_architecture}, - "os.platform" : ${content_meta_os_platform}, - "os.version" : ${content_meta_os_version}, - "plugin" : "maven-resources-plugin", - "project" : "Maven Smoke Tests Project", - "runtime-id" : ${content_meta_runtime_id}, - "runtime.name" : ${content_meta_runtime_name}, - "runtime.vendor" : ${content_meta_runtime_vendor}, - "runtime.version" : ${content_meta_runtime_version} - }, - "metrics" : { }, - "name" : "Maven_Smoke_Tests_Project_maven_resources_plugin_default_resources", - "parent_id" : ${content_test_session_id}, - "resource" : "Maven_Smoke_Tests_Project_maven_resources_plugin_default_resources", - "service" : "test-maven-service", - "span_id" : ${content_span_id_3}, - "start" : ${content_start_5}, - "trace_id" : ${content_test_session_id} - }, - "type" : "span", - "version" : 1 -}, { - "content" : { - "duration" : ${content_duration_6}, - "error" : 0, - "meta" : { - "_dd.p.tid" : ${content_meta__dd_p_tid_6}, - "_dd.test.is_user_provided_service" : "true", - "env" : "integration-test", - "execution" : "default-testResources", - "language" : "jvm", - "library_version" : ${content_meta_library_version}, - "os.architecture" : ${content_meta_os_architecture}, - "os.platform" : ${content_meta_os_platform}, - "os.version" : ${content_meta_os_version}, - "plugin" : "maven-resources-plugin", - "project" : "Maven Smoke Tests Project", - "runtime-id" : ${content_meta_runtime_id}, - "runtime.name" : ${content_meta_runtime_name}, - "runtime.vendor" : ${content_meta_runtime_vendor}, - "runtime.version" : ${content_meta_runtime_version} - }, - "metrics" : { }, - "name" : "Maven_Smoke_Tests_Project_maven_resources_plugin_default_testResources", - "parent_id" : ${content_test_session_id}, - "resource" : "Maven_Smoke_Tests_Project_maven_resources_plugin_default_testResources", - "service" : "test-maven-service", - "span_id" : ${content_span_id_4}, - "start" : ${content_start_6}, - "trace_id" : ${content_test_session_id} - }, - "type" : "span", - "version" : 1 -}, { - "content" : { - "duration" : ${content_duration_7}, - "error" : 0, - "meta" : { - "_dd.p.tid" : ${content_meta__dd_p_tid_7}, - "_dd.test.is_user_provided_service" : "true", - "_dd.tracer_host" : ${content_meta__dd_tracer_host}, - "ci.workspace_path" : ${content_meta_ci_workspace_path}, - "component" : "junit4", - "env" : "integration-test", - "language" : "jvm", - "library_version" : ${content_meta_library_version}, - "os.architecture" : ${content_meta_os_architecture}, - "os.platform" : ${content_meta_os_platform}, - "os.version" : ${content_meta_os_version}, - "runtime-id" : ${content_meta_runtime_id_2}, - "runtime.name" : ${content_meta_runtime_name}, - "runtime.vendor" : ${content_meta_runtime_vendor}, - "runtime.version" : ${content_meta_runtime_version}, - "span.kind" : "test_suite_end", - "test.framework" : "junit4", - "test.framework_version" : "4.13.2", - "test.module" : "Maven Smoke Tests Project maven-surefire-plugin default-test", - "test.source.file" : "src/test/java/datadog/smoke/TestSucceed.java", - "test.status" : "pass", - "test.suite" : "datadog.smoke.TestSucceed", - "test.type" : "test", - "test_session.name" : "mvn -B test" - }, - "metrics" : { - "_dd.host.vcpu_count" : ${content_metrics__dd_host_vcpu_count_3}, - "_dd.profiling.enabled" : 0, - "_dd.trace_span_attribute_schema" : 0, - "process_id" : ${content_metrics_process_id_2}, - "test.source.end" : 18, - "test.source.start" : 7 - }, - "name" : "junit4.test_suite", - "resource" : "datadog.smoke.TestSucceed", - "service" : "test-maven-service", - "start" : ${content_start_7}, - "test_module_id" : ${content_test_module_id}, - "test_session_id" : ${content_test_session_id}, - "test_suite_id" : ${content_test_suite_id} - }, - "type" : "test_suite_end", - "version" : 1 -}, { - "content" : { - "duration" : ${content_duration_8}, - "error" : 0, - "meta" : { - "_dd.library_capabilities.auto_test_retries" : "1", - "_dd.library_capabilities.early_flake_detection" : "1", - "_dd.library_capabilities.fail_fast_test_order" : "1", - "_dd.library_capabilities.impacted_tests" : "1", - "_dd.library_capabilities.test_impact_analysis" : "1", - "_dd.library_capabilities.test_management.attempt_to_fix" : "4", - "_dd.library_capabilities.test_management.disable" : "1", - "_dd.library_capabilities.test_management.quarantine" : "1", - "_dd.p.tid" : ${content_meta__dd_p_tid_8}, - "_dd.test.is_user_provided_service" : "true", - "_dd.tracer_host" : ${content_meta__dd_tracer_host}, - "ci.workspace_path" : ${content_meta_ci_workspace_path}, - "component" : "junit4", - "env" : "integration-test", - "language" : "jvm", - "library_version" : ${content_meta_library_version}, - "os.architecture" : ${content_meta_os_architecture}, - "os.platform" : ${content_meta_os_platform}, - "os.version" : ${content_meta_os_version}, - "runtime-id" : ${content_meta_runtime_id_2}, - "runtime.name" : ${content_meta_runtime_name}, - "runtime.vendor" : ${content_meta_runtime_vendor}, - "runtime.version" : ${content_meta_runtime_version}, - "span.kind" : "test", - "test.framework" : "junit4", - "test.framework_version" : "4.13.2", - "test.is_modified" : "true", - "test.module" : "Maven Smoke Tests Project maven-surefire-plugin default-test", - "test.name" : "test_succeed", - "test.source.file" : "src/test/java/datadog/smoke/TestSucceed.java", - "test.source.method" : "test_succeed()V", - "test.status" : "pass", - "test.suite" : "datadog.smoke.TestSucceed", - "test.type" : "test", - "test_session.name" : "mvn -B test" - }, - "metrics" : { - "_dd.host.vcpu_count" : ${content_metrics__dd_host_vcpu_count_4}, - "_dd.profiling.enabled" : 0, - "_dd.trace_span_attribute_schema" : 0, - "process_id" : ${content_metrics_process_id_2}, - "test.source.end" : 12, - "test.source.start" : 9 - }, - "name" : "junit4.test", - "parent_id" : ${content_parent_id}, - "resource" : "datadog.smoke.TestSucceed.test_succeed", - "service" : "test-maven-service", - "span_id" : ${content_span_id_5}, - "start" : ${content_start_8}, - "test_module_id" : ${content_test_module_id}, - "test_session_id" : ${content_test_session_id}, - "test_suite_id" : ${content_test_suite_id}, - "trace_id" : ${content_trace_id} - }, - "type" : "test", - "version" : 2 -}, { - "content" : { - "duration" : ${content_duration_9}, - "error" : 0, - "meta" : { - "_dd.library_capabilities.auto_test_retries" : "1", - "_dd.library_capabilities.early_flake_detection" : "1", - "_dd.library_capabilities.fail_fast_test_order" : "1", - "_dd.library_capabilities.impacted_tests" : "1", - "_dd.library_capabilities.test_impact_analysis" : "1", - "_dd.library_capabilities.test_management.attempt_to_fix" : "4", - "_dd.library_capabilities.test_management.disable" : "1", - "_dd.library_capabilities.test_management.quarantine" : "1", - "_dd.p.tid" : ${content_meta__dd_p_tid_9}, - "_dd.test.is_user_provided_service" : "true", - "_dd.tracer_host" : ${content_meta__dd_tracer_host}, - "ci.workspace_path" : ${content_meta_ci_workspace_path}, - "component" : "junit4", - "env" : "integration-test", - "language" : "jvm", - "library_version" : ${content_meta_library_version}, - "os.architecture" : ${content_meta_os_architecture}, - "os.platform" : ${content_meta_os_platform}, - "os.version" : ${content_meta_os_version}, - "runtime-id" : ${content_meta_runtime_id_2}, - "runtime.name" : ${content_meta_runtime_name}, - "runtime.vendor" : ${content_meta_runtime_vendor}, - "runtime.version" : ${content_meta_runtime_version}, - "span.kind" : "test", - "test.framework" : "junit4", - "test.framework_version" : "4.13.2", - "test.is_modified" : "true", - "test.module" : "Maven Smoke Tests Project maven-surefire-plugin default-test", - "test.name" : "test_to_skip_with_itr", - "test.source.file" : "src/test/java/datadog/smoke/TestSucceed.java", - "test.source.method" : "test_to_skip_with_itr()V", - "test.status" : "pass", - "test.suite" : "datadog.smoke.TestSucceed", - "test.type" : "test", - "test_session.name" : "mvn -B test" - }, - "metrics" : { - "_dd.host.vcpu_count" : ${content_metrics__dd_host_vcpu_count_5}, - "_dd.profiling.enabled" : 0, - "_dd.trace_span_attribute_schema" : 0, - "process_id" : ${content_metrics_process_id_2}, - "test.source.end" : 17, - "test.source.start" : 14 - }, - "name" : "junit4.test", - "parent_id" : ${content_parent_id}, - "resource" : "datadog.smoke.TestSucceed.test_to_skip_with_itr", - "service" : "test-maven-service", - "span_id" : ${content_span_id_6}, - "start" : ${content_start_9}, - "test_module_id" : ${content_test_module_id}, - "test_session_id" : ${content_test_session_id}, - "test_suite_id" : ${content_test_suite_id}, - "trace_id" : ${content_trace_id_2} - }, - "type" : "test", - "version" : 2 -} ] \ No newline at end of file diff --git a/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/pom.xml b/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/pom.xml deleted file mode 100644 index 48f92df3632..00000000000 --- a/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - 4.0.0 - com.datadog.ci.test - maven-smoke-test - 1.0-SNAPSHOT - Maven Smoke Tests Project - - - 8 - 8 - UTF-8 - - - - - - - false - - central - Central Repository - https://repo.maven.apache.org/maven2 - - - - - - never - - - false - - central - Central Repository - https://repo.maven.apache.org/maven2 - - - - - - junit - junit - 4.13.2 - test - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0 - - - - - diff --git a/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/src/main/java/datadog/smoke/Calculator.java b/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/src/main/java/datadog/smoke/Calculator.java deleted file mode 100644 index 2f4461a279d..00000000000 --- a/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/src/main/java/datadog/smoke/Calculator.java +++ /dev/null @@ -1,11 +0,0 @@ -package datadog.smoke; - -public class Calculator { - public static int add(int a, int b) { - return a + b; - } - - public static int subtract(int a, int b) { - return a - b; - } -} diff --git a/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/src/test/java/datadog/smoke/TestSucceed.java b/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/src/test/java/datadog/smoke/TestSucceed.java deleted file mode 100644 index c9baff75d9e..00000000000 --- a/dd-smoke-tests/maven/src/test/resources/test_successful_maven_run_impacted_tests/src/test/java/datadog/smoke/TestSucceed.java +++ /dev/null @@ -1,18 +0,0 @@ -package datadog.smoke; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class TestSucceed { - - @Test - public void test_succeed() { - assertTrue(Calculator.add(2, 2) == 4); - } - - @Test - public void test_to_skip_with_itr() { - assertTrue(Calculator.subtract(3, 2) == 1); - } -} diff --git a/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java b/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java index d7ab9ad204a..ad93aa9dfc7 100644 --- a/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java +++ b/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java @@ -54,8 +54,6 @@ public final class CiVisibilityConfig { public static final String CIVISIBILITY_FLAKY_RETRY_ENABLED = "civisibility.flaky.retry.enabled"; public static final String CIVISIBILITY_IMPACTED_TESTS_DETECTION_ENABLED = "civisibility.impacted.tests.detection.enabled"; - public static final String CIVISIBILITY_IMPACTED_TESTS_BACKEND_REQUEST_ENABLED = - "civisibility.impacted.tests.backend.request.enabled"; public static final String CIVISIBILITY_KNOWN_TESTS_REQUEST_ENABLED = "civisibility.known.tests.request.enabled"; public static final String CIVISIBILITY_FLAKY_RETRY_ONLY_KNOWN_FLAKES = From 2e3362f6a1190fc96e0618dd6da250b4eed2270f Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Thu, 5 Jun 2025 15:04:50 +0200 Subject: [PATCH 21/28] remove FileDiff --- .../datadog/trace/civisibility/diff/Diff.java | 3 +- .../trace/civisibility/diff/FileDiff.java | 53 ------------------- .../trace/civisibility/diff/DiffTest.groovy | 3 -- .../civisibility/diff/FileDiffTest.groovy | 39 -------------- .../src/test/groovy/MUnitTest.groovy | 3 -- .../src/test/groovy/JUnit4Test.groovy | 32 +++++++++-- .../src/test/groovy/SpockTest.groovy | 14 ++--- .../src/test/groovy/JUnit5Test.groovy | 17 ++---- .../src/test/groovy/ScalatestTest.groovy | 3 -- .../instrumentation/testng/TestNGTest.groovy | 4 -- 10 files changed, 38 insertions(+), 133 deletions(-) delete mode 100644 dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/diff/FileDiff.java delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/diff/FileDiffTest.groovy diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/diff/Diff.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/diff/Diff.java index dfccfa41351..eeaedcb321f 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/diff/Diff.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/diff/Diff.java @@ -5,8 +5,7 @@ public interface Diff extends SerializableType { - PolymorphicSerializer SERIALIZER = - new PolymorphicSerializer<>(LineDiff.class, FileDiff.class); + PolymorphicSerializer SERIALIZER = new PolymorphicSerializer<>(LineDiff.class); boolean contains(String relativePath, int startLine, int endLine); } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/diff/FileDiff.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/diff/FileDiff.java deleted file mode 100644 index d404aba92ea..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/diff/FileDiff.java +++ /dev/null @@ -1,53 +0,0 @@ -package datadog.trace.civisibility.diff; - -import datadog.trace.civisibility.ipc.serialization.Serializer; -import java.nio.ByteBuffer; -import java.util.Objects; -import java.util.Set; -import javax.annotation.Nonnull; - -/** Diff data with per-file granularity. */ -public class FileDiff implements Diff { - - private final @Nonnull Set changedFiles; - - public FileDiff(@Nonnull Set changedFiles) { - this.changedFiles = changedFiles; - } - - @Override - public boolean contains(String relativePath, int startLine, int endLine) { - return changedFiles.contains(relativePath); - } - - @Override - public void serialize(Serializer s) { - s.write(changedFiles); - } - - public static FileDiff deserialize(ByteBuffer buffer) { - return new FileDiff(Serializer.readSet(buffer, Serializer::readString)); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - FileDiff diff = (FileDiff) o; - return Objects.equals(changedFiles, diff.changedFiles); - } - - @Override - public int hashCode() { - return Objects.hashCode(changedFiles); - } - - @Override - public String toString() { - return "FileDiff{changedFiles=" + changedFiles + '}'; - } -} diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/diff/DiffTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/diff/DiffTest.groovy index 8e9c155ec71..2ee353760e9 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/diff/DiffTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/diff/DiffTest.groovy @@ -19,9 +19,6 @@ class DiffTest extends Specification { where: diff << [ - new FileDiff(Collections.emptySet()), - new FileDiff(Collections.singleton("path")), - new FileDiff(new HashSet<>(["path-a", "path-b"])), new LineDiff([:]), new LineDiff(["path": lines(10)]), new LineDiff(["path": lines(10, 11, 13)]), diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/diff/FileDiffTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/diff/FileDiffTest.groovy deleted file mode 100644 index 31bfbd1e2b2..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/diff/FileDiffTest.groovy +++ /dev/null @@ -1,39 +0,0 @@ -package datadog.trace.civisibility.diff - -import datadog.trace.civisibility.ipc.serialization.Serializer -import spock.lang.Specification - -class FileDiffTest extends Specification { - - def "test diff contains file"() { - when: - def diff = new FileDiff(new HashSet<>(paths)) - - then: - diff.contains(path, 0, Integer.MAX_VALUE) == result - - where: - paths | path | result - ["path-a"] | "path-a" | true - ["path-a"] | "path-b" | false - ["path-a", "path-b"] | "path-a" | true - ["path-a", "path-b"] | "path-b" | true - ["path-a", "path-b"] | "path-c" | false - } - - def "test serialization: #paths"() { - given: - def diff = new FileDiff(new HashSet<>(paths)) - - when: - def serializer = new Serializer() - diff.serialize(serializer) - def buf = serializer.flush() - - then: - FileDiff.deserialize(buf) == diff - - where: - paths << [[], ["path-a"], ["path-a", "path-b"]] - } -} diff --git a/dd-java-agent/instrumentation/junit-4.10/munit-junit-4/src/test/groovy/MUnitTest.groovy b/dd-java-agent/instrumentation/junit-4.10/munit-junit-4/src/test/groovy/MUnitTest.groovy index 5df618caa3c..2c490c78046 100644 --- a/dd-java-agent/instrumentation/junit-4.10/munit-junit-4/src/test/groovy/MUnitTest.groovy +++ b/dd-java-agent/instrumentation/junit-4.10/munit-junit-4/src/test/groovy/MUnitTest.groovy @@ -2,7 +2,6 @@ import datadog.trace.api.DisableTestTrace import datadog.trace.api.civisibility.config.TestFQN import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation import datadog.trace.civisibility.CiVisibilityInstrumentationTest -import datadog.trace.civisibility.diff.FileDiff import datadog.trace.civisibility.diff.LineDiff import datadog.trace.instrumentation.junit4.MUnitTracingListener import datadog.trace.instrumentation.junit4.MUnitUtils @@ -77,8 +76,6 @@ class MUnitTest extends CiVisibilityInstrumentationTest { where: testcaseName | tests | prDiff "test-succeed" | [TestSucceedMUnit] | LineDiff.EMPTY - "test-succeed" | [TestSucceedMUnit] | new FileDiff(new HashSet()) - "test-succeed-impacted" | [TestSucceedMUnit] | new FileDiff(new HashSet([DUMMY_SOURCE_PATH])) "test-succeed" | [TestSucceedMUnit] | new LineDiff([(DUMMY_SOURCE_PATH): lines()]) "test-succeed-impacted" | [TestSucceedMUnit] | new LineDiff([(DUMMY_SOURCE_PATH): lines(DUMMY_TEST_METHOD_START)]) } diff --git a/dd-java-agent/instrumentation/junit-4.10/src/test/groovy/JUnit4Test.groovy b/dd-java-agent/instrumentation/junit-4.10/src/test/groovy/JUnit4Test.groovy index c6e438c1e3e..aa9eaa8eb29 100644 --- a/dd-java-agent/instrumentation/junit-4.10/src/test/groovy/JUnit4Test.groovy +++ b/dd-java-agent/instrumentation/junit-4.10/src/test/groovy/JUnit4Test.groovy @@ -3,11 +3,37 @@ import datadog.trace.api.civisibility.config.TestFQN import datadog.trace.api.civisibility.config.TestIdentifier import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation import datadog.trace.civisibility.CiVisibilityInstrumentationTest -import datadog.trace.civisibility.diff.FileDiff import datadog.trace.civisibility.diff.LineDiff import datadog.trace.instrumentation.junit4.JUnit4Utils import datadog.trace.instrumentation.junit4.TestEventsHandlerHolder -import org.example.* +import org.example.TestAssumption +import org.example.TestAssumptionAndSucceed +import org.example.TestError +import org.example.TestFailed +import org.example.TestFailedAndSucceed +import org.example.TestFailedParameterized +import org.example.TestFailedSuiteSetUpAssumption +import org.example.TestFailedSuiteSetup +import org.example.TestFailedSuiteTearDown +import org.example.TestFailedThenSucceed +import org.example.TestInheritance +import org.example.TestParameterized +import org.example.TestParameterizedJUnitParams +import org.example.TestSkipped +import org.example.TestSkippedClass +import org.example.TestSucceed +import org.example.TestSucceedAndSkipped +import org.example.TestSucceedExpectedException +import org.example.TestSucceedKotlin +import org.example.TestSucceedLegacy +import org.example.TestSucceedParameterizedKotlin +import org.example.TestSucceedSkipEfd +import org.example.TestSucceedSlow +import org.example.TestSucceedSuite +import org.example.TestSucceedUnskippable +import org.example.TestSucceedUnskippableSuite +import org.example.TestSucceedVerySlow +import org.example.TestSucceedWithCategories import org.junit.jupiter.api.Assumptions import org.junit.runner.JUnitCore @@ -124,8 +150,6 @@ class JUnit4Test extends CiVisibilityInstrumentationTest { where: testcaseName | tests | prDiff "test-succeed" | [TestSucceed] | LineDiff.EMPTY - "test-succeed" | [TestSucceed] | new FileDiff(new HashSet()) - "test-succeed-impacted" | [TestSucceed] | new FileDiff(new HashSet([DUMMY_SOURCE_PATH])) "test-succeed" | [TestSucceed] | new LineDiff([(DUMMY_SOURCE_PATH): lines()]) "test-succeed-impacted" | [TestSucceed] | new LineDiff([(DUMMY_SOURCE_PATH): lines(DUMMY_TEST_METHOD_START)]) } diff --git a/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/groovy/SpockTest.groovy b/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/groovy/SpockTest.groovy index fe54b7399fa..577cef7bdcf 100644 --- a/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/groovy/SpockTest.groovy +++ b/dd-java-agent/instrumentation/junit-5.3/spock-junit-5/src/test/groovy/SpockTest.groovy @@ -1,11 +1,14 @@ +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass + import datadog.trace.api.DisableTestTrace import datadog.trace.api.civisibility.config.TestFQN import datadog.trace.api.civisibility.config.TestIdentifier import datadog.trace.civisibility.CiVisibilityInstrumentationTest -import datadog.trace.civisibility.diff.FileDiff import datadog.trace.civisibility.diff.LineDiff import datadog.trace.instrumentation.junit5.JUnitPlatformUtils import datadog.trace.instrumentation.junit5.TestEventsHandlerHolder +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.CopyOnWriteArrayList import org.example.TestFailedParameterizedSpock import org.example.TestFailedSpock import org.example.TestFailedThenSucceedParameterizedSpock @@ -29,11 +32,6 @@ import org.junit.platform.launcher.core.LauncherFactory import org.spockframework.runtime.SpockEngine import org.spockframework.util.SpockReleaseInfo -import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.CopyOnWriteArrayList - -import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass - @DisableTestTrace(reason = "avoid self-tracing") class SpockTest extends CiVisibilityInstrumentationTest { @@ -115,7 +113,7 @@ class SpockTest extends CiVisibilityInstrumentationTest { "test-efd-new-slow-test" | true | [TestSucceedSpockSlow] | [] // is executed only twice "test-efd-new-very-slow-test" | true | [TestSucceedSpockVerySlow] | [] // is executed only once "test-efd-faulty-session-threshold" | false | [TestSucceedAndFailedSpock] | [] - "test-efd-skip-new-test" | true | [TestSucceedSpockSkipEfd] | [] + "test-efd-skip-new-test" | true | [TestSucceedSpockSkipEfd] | [] } def "test impacted tests detection #testcaseName"() { @@ -129,8 +127,6 @@ class SpockTest extends CiVisibilityInstrumentationTest { where: testcaseName | tests | prDiff "test-succeed" | [TestSucceedSpock] | LineDiff.EMPTY - "test-succeed" | [TestSucceedSpock] | new FileDiff(new HashSet()) - "test-succeed-impacted" | [TestSucceedSpock] | new FileDiff(new HashSet([DUMMY_SOURCE_PATH])) "test-succeed" | [TestSucceedSpock] | new LineDiff([(DUMMY_SOURCE_PATH): lines()]) "test-succeed-impacted" | [TestSucceedSpock] | new LineDiff([(DUMMY_SOURCE_PATH): lines(DUMMY_TEST_METHOD_START)]) } diff --git a/dd-java-agent/instrumentation/junit-5.3/src/test/groovy/JUnit5Test.groovy b/dd-java-agent/instrumentation/junit-5.3/src/test/groovy/JUnit5Test.groovy index 20e5f45aa4d..ef11eaff56c 100644 --- a/dd-java-agent/instrumentation/junit-5.3/src/test/groovy/JUnit5Test.groovy +++ b/dd-java-agent/instrumentation/junit-5.3/src/test/groovy/JUnit5Test.groovy @@ -1,15 +1,14 @@ -import datadog.trace.agent.test.asserts.ListWriterAssert -import datadog.trace.api.DDSpanTypes +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass + import datadog.trace.api.DisableTestTrace -import datadog.trace.api.civisibility.config.LibraryCapability import datadog.trace.api.civisibility.config.TestFQN import datadog.trace.api.civisibility.config.TestIdentifier import datadog.trace.civisibility.CiVisibilityInstrumentationTest -import datadog.trace.civisibility.CiVisibilityTestUtils -import datadog.trace.civisibility.diff.FileDiff import datadog.trace.civisibility.diff.LineDiff import datadog.trace.instrumentation.junit5.JUnitPlatformUtils import datadog.trace.instrumentation.junit5.TestEventsHandlerHolder +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.CopyOnWriteArrayList import org.example.TestAssumption import org.example.TestAssumptionAndSucceed import org.example.TestAssumptionLegacy @@ -50,12 +49,6 @@ import org.junit.platform.launcher.core.LauncherConfig import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder import org.junit.platform.launcher.core.LauncherFactory -import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.CopyOnWriteArrayList -import java.util.stream.Collectors - -import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass - @DisableTestTrace(reason = "avoid self-tracing") class JUnit5Test extends CiVisibilityInstrumentationTest { @@ -168,8 +161,6 @@ class JUnit5Test extends CiVisibilityInstrumentationTest { where: testcaseName | tests | prDiff "test-succeed" | [TestSucceed] | LineDiff.EMPTY - "test-succeed" | [TestSucceed] | new FileDiff(new HashSet()) - "test-succeed-impacted" | [TestSucceed] | new FileDiff(new HashSet([DUMMY_SOURCE_PATH])) "test-succeed" | [TestSucceed] | new LineDiff([(DUMMY_SOURCE_PATH): lines()]) "test-succeed-impacted" | [TestSucceed] | new LineDiff([(DUMMY_SOURCE_PATH): lines(DUMMY_TEST_METHOD_START)]) } diff --git a/dd-java-agent/instrumentation/scalatest/src/test/groovy/ScalatestTest.groovy b/dd-java-agent/instrumentation/scalatest/src/test/groovy/ScalatestTest.groovy index f9e551788d4..7686255dcd7 100644 --- a/dd-java-agent/instrumentation/scalatest/src/test/groovy/ScalatestTest.groovy +++ b/dd-java-agent/instrumentation/scalatest/src/test/groovy/ScalatestTest.groovy @@ -1,7 +1,6 @@ import datadog.trace.api.civisibility.config.TestFQN import datadog.trace.api.civisibility.config.TestIdentifier import datadog.trace.civisibility.CiVisibilityInstrumentationTest -import datadog.trace.civisibility.diff.FileDiff import datadog.trace.civisibility.diff.LineDiff import datadog.trace.instrumentation.scalatest.ScalatestUtils import org.example.TestFailed @@ -98,8 +97,6 @@ class ScalatestTest extends CiVisibilityInstrumentationTest { where: testcaseName | tests | prDiff "test-succeed" | [TestSucceed] | LineDiff.EMPTY - "test-succeed" | [TestSucceed] | new FileDiff(new HashSet()) - "test-succeed-impacted" | [TestSucceed] | new FileDiff(new HashSet([DUMMY_SOURCE_PATH])) "test-succeed" | [TestSucceed] | new LineDiff([(DUMMY_SOURCE_PATH): lines()]) "test-succeed-impacted" | [TestSucceed] | new LineDiff([(DUMMY_SOURCE_PATH): lines(DUMMY_TEST_METHOD_START)]) } diff --git a/dd-java-agent/instrumentation/testng/src/testFixtures/groovy/datadog/trace/instrumentation/testng/TestNGTest.groovy b/dd-java-agent/instrumentation/testng/src/testFixtures/groovy/datadog/trace/instrumentation/testng/TestNGTest.groovy index f737cafd5ef..c20783d5260 100644 --- a/dd-java-agent/instrumentation/testng/src/testFixtures/groovy/datadog/trace/instrumentation/testng/TestNGTest.groovy +++ b/dd-java-agent/instrumentation/testng/src/testFixtures/groovy/datadog/trace/instrumentation/testng/TestNGTest.groovy @@ -1,10 +1,8 @@ package datadog.trace.instrumentation.testng - import datadog.trace.api.civisibility.config.TestFQN import datadog.trace.api.civisibility.config.TestIdentifier import datadog.trace.civisibility.CiVisibilityInstrumentationTest -import datadog.trace.civisibility.diff.FileDiff import datadog.trace.civisibility.diff.LineDiff import org.example.* import org.junit.jupiter.api.Assumptions @@ -149,8 +147,6 @@ abstract class TestNGTest extends CiVisibilityInstrumentationTest { where: testcaseName | tests | prDiff "test-succeed" | [TestSucceed] | LineDiff.EMPTY - "test-succeed" | [TestSucceed] | new FileDiff(new HashSet()) - "test-succeed-impacted" | [TestSucceed] | new FileDiff(new HashSet([DUMMY_SOURCE_PATH])) "test-succeed" | [TestSucceed] | new LineDiff([(DUMMY_SOURCE_PATH): lines()]) "test-succeed-impacted" | [TestSucceed] | new LineDiff([(DUMMY_SOURCE_PATH): lines(DUMMY_TEST_METHOD_START)]) } From 4198fe37506bf62b6ed9f9d1714c91457be40a6a Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Thu, 5 Jun 2025 15:05:52 +0200 Subject: [PATCH 22/28] correctly reset all settings tags for mock backend --- .../datadog/smoketest/MockBackend.groovy | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/dd-smoke-tests/backend-mock/src/main/groovy/datadog/smoketest/MockBackend.groovy b/dd-smoke-tests/backend-mock/src/main/groovy/datadog/smoketest/MockBackend.groovy index 696bea3ed65..e16b118f0be 100644 --- a/dd-smoke-tests/backend-mock/src/main/groovy/datadog/smoketest/MockBackend.groovy +++ b/dd-smoke-tests/backend-mock/src/main/groovy/datadog/smoketest/MockBackend.groovy @@ -1,19 +1,17 @@ package datadog.smoketest +import static datadog.trace.agent.test.server.http.TestHttpServer.httpServer + import com.fasterxml.jackson.databind.ObjectMapper import datadog.trace.agent.test.server.http.TestHttpServer import datadog.trace.test.util.MultipartRequestParser -import org.apache.commons.io.IOUtils -import org.msgpack.jackson.dataformat.MessagePackFactory -import spock.util.concurrent.PollingConditions - import java.util.concurrent.ConcurrentLinkedQueue import java.util.concurrent.CopyOnWriteArrayList -import java.util.stream.Collectors import java.util.zip.GZIPInputStream import java.util.zip.GZIPOutputStream - -import static datadog.trace.agent.test.server.http.TestHttpServer.httpServer +import org.apache.commons.io.IOUtils +import org.msgpack.jackson.dataformat.MessagePackFactory +import spock.util.concurrent.PollingConditions class MockBackend implements AutoCloseable { @@ -54,6 +52,15 @@ class MockBackend implements AutoCloseable { flakyTests.clear() knownTests.clear() testManagement.clear() + + itrEnabled = true + codeCoverageEnabled = true + testsSkippingEnabled = true + flakyRetriesEnabled = false + impactedTestsDetectionEnabled = false + knownTestsEnabled = false + testManagementEnabled = false + attemptToFixRetries = 0 } @Override @@ -74,7 +81,7 @@ class MockBackend implements AutoCloseable { } void givenSkippableTest(String module, String suite, String name, Map coverage = null) { - skippableTests.add(["module": module, "suite": suite, "name": name, "coverage": coverage ]) + skippableTests.add(["module": module, "suite": suite, "name": name, "coverage": coverage]) } void givenImpactedTestsDetection(boolean impactedTestsDetectionEnabled) { @@ -99,27 +106,27 @@ class MockBackend implements AutoCloseable { void givenQuarantinedTests(String module, String suite, String name) { testManagement.add([ - "module": module, - "suite": suite, - "name": name, + "module" : module, + "suite" : suite, + "name" : name, "properties": ["quarantined": true] ]) } void givenDisabledTests(String module, String suite, String name) { testManagement.add([ - "module": module, - "suite": suite, - "name": name, + "module" : module, + "suite" : suite, + "name" : name, "properties": ["disabled": true] ]) } void givenAttemptToFixTests(String module, String suite, String name) { testManagement.add([ - "module": module, - "suite": suite, - "name": name, + "module" : module, + "suite" : suite, + "name" : name, "properties": ["attempt_to_fix": true] ]) } @@ -273,7 +280,7 @@ class MockBackend implements AutoCloseable { prefix("/api/v2/ci/libraries/tests") { Map modules = [:] - for (Map test : knownTests) { + for (Map test : knownTests) { Map suites = modules.computeIfAbsent("${test.module}", k -> [:]) List tests = suites.computeIfAbsent("${test.suite}", k -> []) tests.add(test.name) From a99cff82f39b834e348f5596ee629e28a294cd20 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Thu, 5 Jun 2025 15:12:14 +0200 Subject: [PATCH 23/28] create isBlank method to avoid double negation with isNotBlank --- .../civisibility/ci/GithubActionsInfo.java | 2 +- .../civisibility/git/tree/ShellGitClient.java | 46 +++++++++---------- .../main/java/datadog/trace/util/Strings.java | 4 ++ 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GithubActionsInfo.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GithubActionsInfo.java index 6eb8f8c6444..7bec546bf3e 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GithubActionsInfo.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/GithubActionsInfo.java @@ -94,7 +94,7 @@ public CIInfo buildCIInfo() { @Override public PullRequestInfo buildPullRequestInfo() { String baseRef = environment.get(GITHUB_BASE_REF); - if (!Strings.isNotBlank(baseRef)) { + if (Strings.isBlank(baseRef)) { return PullRequestInfo.EMPTY; } diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java index 9f49d8daceb..40958ca3121 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java @@ -606,37 +606,37 @@ public String getBaseCommitSha( return executeCommand( Command.BASE_COMMIT_SHA, () -> { - String remoteName = getRemoteName(); - LOGGER.debug("Remote name: {}", remoteName); - String sourceBranch = getSourceBranch(); if (sourceBranch == null) { return null; } LOGGER.debug("Source branch: {}", sourceBranch); - if (baseBranch != null) { - return getCommonAncestor(baseBranch, sourceBranch); - } + if (baseBranch == null) { + String remoteName = getRemoteName(); + LOGGER.debug("Remote name: {}", remoteName); - String defaultBranch = - Strings.isNotBlank(settingsDefaultBranch) - ? settingsDefaultBranch - : detectDefaultBranch(remoteName); + String defaultBranch = + Strings.isNotBlank(settingsDefaultBranch) + ? settingsDefaultBranch + : detectDefaultBranch(remoteName); - for (String branch : POSSIBLE_BASE_BRANCHES) { - checkAndFetchBranch(branch, remoteName); - } + for (String branch : POSSIBLE_BASE_BRANCHES) { + tryFetchingIfNotFoundLocally(branch, remoteName); + } - List candidates = getBaseBranchCandidates(sourceBranch, remoteName); - if (candidates.isEmpty()) { - LOGGER.debug("No base branch candidates found"); - return null; + List candidates = getBaseBranchCandidates(sourceBranch, remoteName); + if (candidates.isEmpty()) { + LOGGER.debug("No base branch candidates found"); + return null; + } + + // select best candidate based on "ahead" metrics + Map metrics = computeBranchMetrics(candidates, sourceBranch); + return findBestBranchSha(metrics, defaultBranch, remoteName); } - // select best candidate based on "ahead" metrics - Map metrics = computeBranchMetrics(candidates, sourceBranch); - return findBestBranchSha(metrics, defaultBranch, remoteName); + return getCommonAncestor(baseBranch, sourceBranch); }); } @@ -736,7 +736,7 @@ public String detectDefaultBranch(String remoteName) return null; } - public void checkAndFetchBranch(String branch, String remoteName) + public void tryFetchingIfNotFoundLocally(String branch, String remoteName) throws IOException, InterruptedException, TimeoutException { try { // check if branch exists locally as a remote ref @@ -763,7 +763,7 @@ public void checkAndFetchBranch(String branch, String remoteName) } catch (ShellCommandExecutor.ShellCommandFailedException ignored) { } - if (!Strings.isNotBlank(remoteHeads)) { + if (Strings.isBlank(remoteHeads)) { LOGGER.debug("Branch {} does not exist in remote", branch); return; } @@ -911,7 +911,7 @@ public String findBestBranchSha( @Override public LineDiff getGitDiff(String baseCommit, String targetCommit) throws IOException, TimeoutException, InterruptedException { - if (!Strings.isNotBlank(baseCommit)) { + if (Strings.isBlank(baseCommit)) { LOGGER.debug("Base commit info is not available, returning empty git diff"); return null; } else if (Strings.isNotBlank(targetCommit)) { diff --git a/internal-api/src/main/java/datadog/trace/util/Strings.java b/internal-api/src/main/java/datadog/trace/util/Strings.java index 2fea0e107e5..23e7dbd7827 100644 --- a/internal-api/src/main/java/datadog/trace/util/Strings.java +++ b/internal-api/src/main/java/datadog/trace/util/Strings.java @@ -194,6 +194,10 @@ public static boolean isNotBlank(String s) { return false; } + public static boolean isBlank(String s) { + return !isNotBlank(s); + } + /** * Generates a random string of the given length from lowercase characters a-z * From f060e732bee4fac14d0443dcc150da4a8df9c253 Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Fri, 6 Jun 2025 11:20:28 +0200 Subject: [PATCH 24/28] clean up base branch sha logic --- .../civisibility/git/tree/ShellGitClient.java | 363 ++++++++++-------- .../git/tree/GitClientTest.groovy | 81 ++-- .../ghub_actions_clone/git/FETCH_HEAD | 2 +- .../02/fcc183ad25f086aaec562224abc1b323ebaaa9 | Bin 400 -> 0 bytes .../07/30f8c84174f476a9493f9d779640d7c971a2ef | Bin 363 -> 0 bytes .../1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 | Bin 399 -> 0 bytes .../2f/df0c87f0a59400612ea7bff833507e8b4572eb | Bin 0 -> 400 bytes .../8b/0f2672722a266e3f4730727fd51466f8f96ce8 | Bin 0 -> 363 bytes .../c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 | Bin 0 -> 395 bytes .../ghub_actions_clone/git/refs/heads/feature | 2 +- .../git/refs/remotes/origin/feature | 2 +- .../ci/git/impacted/new_clone/git/FETCH_HEAD | 2 +- .../02/fcc183ad25f086aaec562224abc1b323ebaaa9 | Bin 400 -> 0 bytes .../07/30f8c84174f476a9493f9d779640d7c971a2ef | Bin 363 -> 0 bytes .../1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 | Bin 399 -> 0 bytes .../2f/df0c87f0a59400612ea7bff833507e8b4572eb | Bin 0 -> 400 bytes .../8b/0f2672722a266e3f4730727fd51466f8f96ce8 | Bin 0 -> 363 bytes .../c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 | Bin 0 -> 395 bytes .../impacted/new_clone/git/refs/heads/master | 2 +- .../new_clone/git/refs/remotes/origin/feature | 2 +- .../5a/4f2a814b65e38641d6d947ec67781c010bf61c | Bin 0 -> 358 bytes .../d8/a57e1a0937c50c15cc7b9a3e39dc73a1249eaa | Bin 364 -> 0 bytes .../impacted/no_remote/git/refs/heads/master | 2 +- .../ci/git/impacted/repo_origin/HEAD | 1 + .../ci/git/impacted/repo_origin/config | 6 + .../2f/df0c87f0a59400612ea7bff833507e8b4572eb | Bin 0 -> 400 bytes .../3b/bf06262d9604dc0667c1e96b13fbf88f25a43f | Bin 0 -> 54 bytes .../82/ac08af7cb3071716559cc26257ee21dfc8e4d3 | Bin 0 -> 54 bytes .../8b/0f2672722a266e3f4730727fd51466f8f96ce8 | Bin 0 -> 363 bytes .../95/e75d98dbaf42c1efc9be0405e079f97aa24888 | Bin 0 -> 32 bytes .../af/5626b4a114abcb82d63db7c8082c3c4756e51b | Bin 0 -> 30 bytes .../c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 | Bin 0 -> 395 bytes .../e0/dea118958b3ce7d0b353aaf37177a4eac87d59 | Bin 0 -> 54 bytes .../eb/fd7499dae526dcbaf30e1250b1f875946729f8 | Bin 0 -> 54 bytes .../impacted/repo_origin/refs/heads/feature | 1 + .../impacted/repo_origin/refs/heads/master | 1 + .../02/fcc183ad25f086aaec562224abc1b323ebaaa9 | Bin 400 -> 0 bytes .../07/30f8c84174f476a9493f9d779640d7c971a2ef | Bin 363 -> 0 bytes .../1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 | Bin 399 -> 0 bytes .../2f/df0c87f0a59400612ea7bff833507e8b4572eb | Bin 0 -> 400 bytes .../8b/0f2672722a266e3f4730727fd51466f8f96ce8 | Bin 0 -> 363 bytes .../c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 | Bin 0 -> 395 bytes .../source_repo/git/refs/heads/feature | 2 +- .../source_repo/git/refs/heads/master | 2 +- .../git/refs/remotes/origin/feature | 2 +- .../git/refs/remotes/origin/master | 2 +- 46 files changed, 272 insertions(+), 203 deletions(-) delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/07/30f8c84174f476a9493f9d779640d7c971a2ef delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/8b/0f2672722a266e3f4730727fd51466f8f96ce8 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/07/30f8c84174f476a9493f9d779640d7c971a2ef delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/8b/0f2672722a266e3f4730727fd51466f8f96ce8 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/5a/4f2a814b65e38641d6d947ec67781c010bf61c delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/d8/a57e1a0937c50c15cc7b9a3e39dc73a1249eaa create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/HEAD create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/config create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/3b/bf06262d9604dc0667c1e96b13fbf88f25a43f create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/8b/0f2672722a266e3f4730727fd51466f8f96ce8 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/95/e75d98dbaf42c1efc9be0405e079f97aa24888 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/e0/dea118958b3ce7d0b353aaf37177a4eac87d59 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/07/30f8c84174f476a9493f9d779640d7c971a2ef delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/8b/0f2672722a266e3f4730727fd51466f8f96ce8 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java index 40958ca3121..a85b737f4d7 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java @@ -9,7 +9,6 @@ import datadog.trace.civisibility.diff.LineDiff; import datadog.trace.civisibility.utils.ShellCommandExecutor; import datadog.trace.util.Strings; -import de.thetaphi.forbiddenapis.SuppressForbidden; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; @@ -22,12 +21,11 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.concurrent.TimeoutException; import java.util.regex.Pattern; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.slf4j.Logger; @@ -40,8 +38,8 @@ public class ShellGitClient implements GitClient { private static final String DD_TEMP_DIRECTORY_PREFIX = "dd-ci-vis-"; private static final List POSSIBLE_BASE_BRANCHES = Arrays.asList("main", "master", "preprod", "prod", "dev", "development", "trunk"); - private static final Pattern BASE_BRANCH_PATTERN = - Pattern.compile("^(" + String.join("|", POSSIBLE_BASE_BRANCHES) + "|release/.*|hotfix/.*)$"); + private static final List POSSIBLE_BASE_BRANCH_PREFIXES = + Arrays.asList("release/", "hotfix/"); private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+"); private static final String ORIGIN = "origin"; @@ -606,42 +604,27 @@ public String getBaseCommitSha( return executeCommand( Command.BASE_COMMIT_SHA, () -> { - String sourceBranch = getSourceBranch(); - if (sourceBranch == null) { + String sourceBranch = getCurrentBranch(); + if (Strings.isBlank(sourceBranch)) { return null; } LOGGER.debug("Source branch: {}", sourceBranch); - if (baseBranch == null) { - String remoteName = getRemoteName(); - LOGGER.debug("Remote name: {}", remoteName); + String remoteName = getRemoteName(); + LOGGER.debug("Remote name: {}", remoteName); - String defaultBranch = - Strings.isNotBlank(settingsDefaultBranch) - ? settingsDefaultBranch - : detectDefaultBranch(remoteName); - - for (String branch : POSSIBLE_BASE_BRANCHES) { - tryFetchingIfNotFoundLocally(branch, remoteName); - } - - List candidates = getBaseBranchCandidates(sourceBranch, remoteName); - if (candidates.isEmpty()) { - LOGGER.debug("No base branch candidates found"); - return null; - } - - // select best candidate based on "ahead" metrics - Map metrics = computeBranchMetrics(candidates, sourceBranch); - return findBestBranchSha(metrics, defaultBranch, remoteName); + if (baseBranch != null) { + tryFetchingIfNotFoundLocally(baseBranch, remoteName); + String fullBaseBranchName = + remoteName + "/" + removeRemotePrefix(baseBranch, remoteName); + return getMergeBase(fullBaseBranchName, sourceBranch); + } else { + return guessBestBaseBranchSha(sourceBranch, remoteName, settingsDefaultBranch); } - - return getCommonAncestor(baseBranch, sourceBranch); }); } - @SuppressForbidden // split on single-character uses fast path - public String getRemoteName() throws IOException, InterruptedException, TimeoutException { + String getRemoteName() throws IOException, InterruptedException, TimeoutException { try { String remote = commandExecutor @@ -654,7 +637,8 @@ public String getRemoteName() throws IOException, InterruptedException, TimeoutE "@{upstream}") .trim(); - return remote.split("/")[0]; + int slashIdx = remote.indexOf("/"); + return slashIdx != -1 ? remote.substring(0, slashIdx) : remote; } catch (ShellCommandExecutor.ShellCommandFailedException e) { LOGGER.debug("Error getting remote from upstream, falling back to first remote", e); } @@ -670,74 +654,49 @@ public String getRemoteName() throws IOException, InterruptedException, TimeoutE } @Nullable - public String getSourceBranch() throws IOException, InterruptedException, TimeoutException { - try { - return commandExecutor - .executeCommand(IOUtils::readFully, "git", "rev-parse", "--abbrev-ref", "HEAD") - .trim(); - } catch (ShellCommandExecutor.ShellCommandFailedException e) { - LOGGER.debug("Error getting source branch", e); + String guessBestBaseBranchSha( + String sourceBranch, String remoteName, @Nullable String settingsDefaultBranch) + throws IOException, InterruptedException, TimeoutException { + for (String branch : POSSIBLE_BASE_BRANCHES) { + tryFetchingIfNotFoundLocally(branch, remoteName); + } + if (settingsDefaultBranch != null) { + tryFetchingIfNotFoundLocally(settingsDefaultBranch, remoteName); + } + + List candidates = getBaseBranchCandidates(settingsDefaultBranch, remoteName); + if (candidates.isEmpty()) { + LOGGER.debug("No base branch candidates found"); return null; } - } - public String removeRemotePrefix(String branch, String remoteName) { - if (branch.indexOf(remoteName + "/") != 0) { - return branch; + List metrics = computeBranchMetrics(candidates, sourceBranch); + LOGGER.debug("Metrics found: {}", metrics); + if (metrics.isEmpty()) { + return null; } - return branch.substring(remoteName.length() + 1); - } - public boolean isBaseLikeBranch(String branch, String remoteName) { - // remove remote prefix - String shortBranchName = removeRemotePrefix(branch, remoteName); + String defaultBranch = + Strings.isNotBlank(settingsDefaultBranch) + ? settingsDefaultBranch + : detectDefaultBranch(remoteName); - return BASE_BRANCH_PATTERN.matcher(shortBranchName).matches(); - } + List sortedMetrics = + sortBaseBranchCandidates(metrics, defaultBranch, remoteName); - @Nullable - public String detectDefaultBranch(String remoteName) - throws IOException, InterruptedException, TimeoutException { - try { - String defaultRef = - commandExecutor - .executeCommand( - IOUtils::readFully, - "git", - "symbolic-ref", - "--quiet", - "--short", - "refs/remotes/" + remoteName + "/HEAD") - .trim(); - if (Strings.isNotBlank(defaultRef)) { - return removeRemotePrefix(defaultRef, remoteName); + for (BaseBranchMetric metric : sortedMetrics) { + String sha = getMergeBase(metric.branch, sourceBranch); + if (Strings.isNotBlank(sha)) { + return sha; } - } catch (ShellCommandExecutor.ShellCommandFailedException ignored) { } - LOGGER.debug("Could not get symbolic-ref for default branch, trying fallback"); - List fallbackBranches = Arrays.asList("main", "master"); - for (String branch : fallbackBranches) { - try { - commandExecutor.executeCommand( - ShellCommandExecutor.OutputParser.IGNORE, - "git", - "show-ref", - "--verify", - "--quiet", - "refs/remotes/" + remoteName + "/" + branch); - LOGGER.debug("Found fallback default branch: {}", branch); - return branch; - } catch (ShellCommandExecutor.ShellCommandFailedException ignored) { - } - } - - LOGGER.debug("No fallback default branch found"); return null; } - public void tryFetchingIfNotFoundLocally(String branch, String remoteName) + void tryFetchingIfNotFoundLocally(String branch, String remoteName) throws IOException, InterruptedException, TimeoutException { + String shortBranchName = removeRemotePrefix(branch, remoteName); try { // check if branch exists locally as a remote ref commandExecutor.executeCommand( @@ -746,11 +705,12 @@ public void tryFetchingIfNotFoundLocally(String branch, String remoteName) "show-ref", "--verify", "--quiet", - "refs/remotes/" + remoteName + "/" + branch); - LOGGER.debug("Branch {} exists locally, skipping fetch", branch); + "refs/remotes/" + remoteName + "/" + shortBranchName); + LOGGER.debug("Branch {}/{} exists locally, skipping fetch", remoteName, shortBranchName); return; } catch (ShellCommandExecutor.ShellCommandFailedException e) { - LOGGER.debug("Branch {} does not exist locally, checking remote", branch); + LOGGER.debug( + "Branch {}/{} does not exist locally, checking remote", remoteName, shortBranchName); } // check if branch exists in remote @@ -758,29 +718,34 @@ public void tryFetchingIfNotFoundLocally(String branch, String remoteName) try { remoteHeads = commandExecutor - .executeCommand(IOUtils::readFully, "git", "ls-remote", "--heads", remoteName, branch) + .executeCommand( + IOUtils::readFully, "git", "ls-remote", "--heads", remoteName, shortBranchName) .trim(); } catch (ShellCommandExecutor.ShellCommandFailedException ignored) { } if (Strings.isBlank(remoteHeads)) { - LOGGER.debug("Branch {} does not exist in remote", branch); + LOGGER.debug("Branch {}/{} does not exist in remote", remoteName, shortBranchName); return; } // fetch latest commit for branch from remote - LOGGER.debug("Branch {} exists in remote, fetching", branch); - commandExecutor.executeCommand( - ShellCommandExecutor.OutputParser.IGNORE, - "git", - "fetch", - "--depth", - "1", - remoteName, - branch); - } - - public List getBaseBranchCandidates(String sourceBranch, String remoteName) + LOGGER.debug("Branch {}/{} exists in remote, fetching", remoteName, shortBranchName); + try { + commandExecutor.executeCommand( + ShellCommandExecutor.OutputParser.IGNORE, + "git", + "fetch", + "--depth", + "1", + remoteName, + shortBranchName); + } catch (ShellCommandExecutor.ShellCommandFailedException e) { + LOGGER.debug("Branch {}/{} couldn't be fetched from remote", remoteName, shortBranchName, e); + } + } + + List getBaseBranchCandidates(@Nullable String defaultBranch, String remoteName) throws IOException, InterruptedException, TimeoutException { List candidates = new ArrayList<>(); try { @@ -790,10 +755,11 @@ public List getBaseBranchCandidates(String sourceBranch, String remoteNa IOUtils::readLines, "git", "for-each-ref", - "--format='%(refname:short)'", + "--format=%(refname:short)", "refs/remotes/" + remoteName); for (String branch : branches) { - if (!branch.equals(sourceBranch) && isBaseLikeBranch(branch, remoteName)) { + if (isBaseLikeBranch(branch, remoteName) + || branchesEquals(branch, defaultBranch, remoteName)) { candidates.add(branch); } } @@ -804,96 +770,175 @@ public List getBaseBranchCandidates(String sourceBranch, String remoteNa return candidates; } - public String getCommonAncestor(String candidateBranch, String sourceBranch) + boolean branchesEquals(String branchA, String branchB, @Nonnull String remoteName) { + return branchA != null + && branchB != null + && removeRemotePrefix(branchA, remoteName).equals(removeRemotePrefix(branchB, remoteName)); + } + + String removeRemotePrefix(@Nonnull String branch, @Nonnull String remoteName) { + if (branch.startsWith(remoteName + "/")) { + return branch.substring(remoteName.length() + 1); + } + return branch; + } + + boolean isBaseLikeBranch(@Nonnull String branch, @Nonnull String remoteName) { + String shortBranchName = removeRemotePrefix(branch, remoteName); + if (POSSIBLE_BASE_BRANCHES.contains(shortBranchName)) { + return true; + } + + for (String prefix : POSSIBLE_BASE_BRANCH_PREFIXES) { + if (shortBranchName.startsWith(prefix)) { + return true; + } + } + + return false; + } + + @Nullable + String detectDefaultBranch(String remoteName) throws IOException, InterruptedException, TimeoutException { try { - return commandExecutor - .executeCommand(IOUtils::readFully, "git", "merge-base", candidateBranch, sourceBranch) - .trim(); - } catch (ShellCommandExecutor.ShellCommandFailedException e) { - LOGGER.debug( - "Error calculating common ancestor for {} and {}", candidateBranch, sourceBranch, e); + String defaultRef = + commandExecutor + .executeCommand( + IOUtils::readFully, + "git", + "symbolic-ref", + "--quiet", + "--short", + "refs/remotes/" + remoteName + "/HEAD") + .trim(); + if (Strings.isNotBlank(defaultRef)) { + return removeRemotePrefix(defaultRef, remoteName); + } + } catch (ShellCommandExecutor.ShellCommandFailedException ignored) { } + + LOGGER.debug("Could not get symbolic-ref for default branch, trying fallback"); + List fallbackBranches = Arrays.asList("main", "master"); + for (String branch : fallbackBranches) { + try { + commandExecutor.executeCommand( + ShellCommandExecutor.OutputParser.IGNORE, + "git", + "show-ref", + "--verify", + "--quiet", + "refs/remotes/" + remoteName + "/" + branch); + LOGGER.debug("Found fallback default branch: {}", branch); + return branch; + } catch (ShellCommandExecutor.ShellCommandFailedException ignored) { + } + } + + LOGGER.debug("No fallback default branch found"); return null; } - public static class BaseBranchMetric { + static class BaseBranchMetric { + private final String branch; private final int behind; private final int ahead; - private final String baseSha; - public BaseBranchMetric(int behind, int ahead, String baseSha) { + BaseBranchMetric(String branch, int behind, int ahead) { + this.branch = branch; this.behind = behind; this.ahead = ahead; - this.baseSha = baseSha; } @Override public boolean equals(Object o) { if (!(o instanceof BaseBranchMetric)) return false; BaseBranchMetric that = (BaseBranchMetric) o; - return behind == that.behind && ahead == that.ahead && Objects.equals(baseSha, that.baseSha); + return behind == that.behind && ahead == that.ahead && Objects.equals(branch, that.branch); } @Override public int hashCode() { - return Objects.hash(behind, ahead, baseSha); + return Objects.hash(branch, behind, ahead); + } + + @Override + public String toString() { + return "BaseBranchMetric{" + + "branch='" + + branch + + '\'' + + ", behind=" + + behind + + ", ahead=" + + ahead + + '}'; } } - public Map computeBranchMetrics( - List candidates, String sourceBranch) + List computeBranchMetrics(List candidates, String sourceBranch) throws IOException, InterruptedException, TimeoutException { - Map branchMetrics = new HashMap<>(); + List branchMetrics = new ArrayList<>(); for (String candidate : candidates) { - String baseSha = getCommonAncestor(candidate, sourceBranch); - if (baseSha == null || baseSha.isEmpty()) { - continue; + try { + String countsResult = + commandExecutor + .executeCommand( + IOUtils::readFully, + "git", + "rev-list", + "--left-right", + "--count", + candidate + "..." + sourceBranch) + .trim(); + + String[] counts = WHITESPACE_PATTERN.split(countsResult); + int behind = Integer.parseInt(counts[0]); + int ahead = Integer.parseInt(counts[1]); + if (behind == 0 && ahead == 0) { + LOGGER.debug("Branch {} is up to date", candidate); + } else { + branchMetrics.add(new BaseBranchMetric(candidate, behind, ahead)); + } + } catch (ShellCommandExecutor.ShellCommandFailedException ignored) { + LOGGER.debug("Could not get metrics for candidate {}", candidate); } - - String countsResult = - commandExecutor - .executeCommand( - IOUtils::readFully, - "git", - "rev-list", - "--left-right", - "--count", - candidate + "..." + sourceBranch) - .trim(); - - String[] counts = WHITESPACE_PATTERN.split(countsResult); - int behind = Integer.parseInt(counts[0]); - int ahead = Integer.parseInt(counts[1]); - - branchMetrics.put(candidate, new BaseBranchMetric(behind, ahead, baseSha)); } return branchMetrics; } - public boolean isDefaultBranch(String branch, @Nullable String defaultBranch, String remoteName) { - return defaultBranch != null - && (branch.equals(defaultBranch) || branch.equals(remoteName + "/" + defaultBranch)); + boolean isDefaultBranch(String branch, @Nullable String defaultBranch, String remoteName) { + return defaultBranch != null && branchesEquals(branch, defaultBranch, remoteName); } - public String findBestBranchSha( - Map metrics, String defaultBranch, String remoteName) { - if (metrics.isEmpty()) { - return null; - } - - // Find branch with smallest "ahead" value, prioritizing default branch on tie - Comparator> comparator = - Comparator.comparingInt((Map.Entry e) -> e.getValue().ahead) - .thenComparing( // negated to prioritize default branch on min search - e -> !isDefaultBranch(e.getKey(), defaultBranch, remoteName)); + List sortBaseBranchCandidates( + List metrics, String defaultBranch, String remoteName) { + Comparator comparator = + Comparator.comparingInt((BaseBranchMetric b) -> b.ahead) + .thenComparing(b -> !isDefaultBranch(b.branch, defaultBranch, remoteName)); - Map.Entry bestMetric = - metrics.entrySet().stream().min(comparator).orElse(null); + return metrics.stream().sorted(comparator).collect(Collectors.toList()); + } - return bestMetric != null ? bestMetric.getValue().baseSha : null; + /** + * Returns the merge base between to branches + * + * @param baseBranch Base branch. Must be remote, i.e. "origin/master" + * @param sourceBranch Source branch + * @return Merge base between the two branches + */ + String getMergeBase(String baseBranch, String sourceBranch) + throws IOException, InterruptedException, TimeoutException { + try { + return commandExecutor + .executeCommand(IOUtils::readFully, "git", "merge-base", baseBranch, sourceBranch) + .trim(); + } catch (ShellCommandExecutor.ShellCommandFailedException e) { + LOGGER.debug("Error calculating common ancestor for {} and {}", baseBranch, sourceBranch, e); + } + return null; } /** diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy index 3300614faab..f6674d9e598 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy @@ -165,9 +165,9 @@ class GitClientTest extends Specification { then: message == "Adding Git information to test spans (#1242)\n\n" + - "* Initial basic GitInfo implementation.\r\n\r\n" + - "* Adds Author, Committer and Message git parser.\r\n\r\n" + - "* Changes based on the review." + "* Initial basic GitInfo implementation.\r\n\r\n" + + "* Adds Author, Committer and Message git parser.\r\n\r\n" + + "* Changes based on the review." } def "test get author name"() { @@ -330,6 +330,8 @@ class GitClientTest extends Specification { def "test remove remote prefix"() { def gitClient = givenGitClient() + + expect: gitClient.removeRemotePrefix(branchName, remoteName) == expected where: @@ -343,8 +345,25 @@ class GitClientTest extends Specification { "" | "origin" | "" } + def "test branch equals"() { + def gitClient = givenGitClient() + + expect: + gitClient.branchesEquals(branchA, branchB, remoteName) == expected + + where: + branchA | branchB | remoteName | expected + "main" | "main" | "origin" | true + "upsteam/main" | "main" | "upsteam" | true + "origin/main" | "origin/main" | "origin" | true + "main" | "master" | "origin" | false + "upsteam/main" | "origin/main" | "origin" | false + } + def "test base like branch match"() { def gitClient = givenGitClient() + + expect: gitClient.isBaseLikeBranch(branchName, remoteName) == expected where: @@ -374,6 +393,8 @@ class GitClientTest extends Specification { def "test is default branch"() { def gitClient = givenGitClient() + + expect: gitClient.isDefaultBranch(branch, defaultBranch, remoteName) == expected where: @@ -391,6 +412,8 @@ class GitClientTest extends Specification { def "test get remote name"() { givenGitRepo(repoPath) def gitClient = givenGitClient() + + expect: gitClient.getRemoteName() == remoteName where: @@ -400,18 +423,6 @@ class GitClientTest extends Specification { "ci/git/with_pack/git" | "origin" // ambiguous '@{upstream}' argument } - def "test get source branch"() { - given: - givenGitRepo("ci/git/impacted/source_repo/git") - def gitClient = givenGitClient() - - when: - def branch = gitClient.getSourceBranch() - - then: - branch == "feature" - } - def "test detect default branch"() { given: givenGitRepo("ci/git/impacted/source_repo/git") @@ -433,40 +444,44 @@ class GitClientTest extends Specification { def metrics = gitClient.computeBranchMetrics(["origin/master"], "feature") then: - metrics.size() == 1 - metrics["origin/master"] == new ShellGitClient.BaseBranchMetric(0, 1, "02fcc183ad25f086aaec562224abc1b323ebaaa9") + metrics == [new ShellGitClient.BaseBranchMetric("origin/master", 0, 1)] } - def "test find best branch sha"() { + def "test sort base branches candidates"() { def gitClient = givenGitClient() - gitClient.findBestBranchSha(metrics, "main", "origin") == expected + def sortedMetrics = gitClient.sortBaseBranchCandidates(metrics, "main", "origin") + def sortedBranches = sortedMetrics.collect(m -> m.branch) + + expect: + sortedBranches == expectedOrder where: - metrics | expected + metrics | expectedOrder [ - "main" : new ShellGitClient.BaseBranchMetric(10, 2, "sha1"), - "master" : new ShellGitClient.BaseBranchMetric(15, 1, "sha2"), - "origin/main": new ShellGitClient.BaseBranchMetric(5, 2, "sha3")] | "sha2" + new ShellGitClient.BaseBranchMetric("main", 10, 2), + new ShellGitClient.BaseBranchMetric("master", 15, 1), + new ShellGitClient.BaseBranchMetric("origin/main", 5, 2)] | ["master", "main", "origin/main"] [ - "main" : new ShellGitClient.BaseBranchMetric(10, 2, "sha1"), - "master" : new ShellGitClient.BaseBranchMetric(15, 2, "sha2"), - "origin/main": new ShellGitClient.BaseBranchMetric(5, 2, "sha3")] | "sha3" - [:] | null + new ShellGitClient.BaseBranchMetric("main", 10, 2), + new ShellGitClient.BaseBranchMetric("master", 15, 2), + new ShellGitClient.BaseBranchMetric("origin/main", 5, 2)] | ["main", "origin/main", "master"] + [] | [] } def "test get base branch sha: #testcaseName"() { givenGitRepo(repo) def gitClient = givenGitClient() + expect: gitClient.getBaseCommitSha(baseBranch, null) == expected where: - testcaseName | repo | baseBranch | expected - "base branch provided" | "ci/git/impacted/source_repo/git" | "master" | "02fcc183ad25f086aaec562224abc1b323ebaaa9" - "base branch not provided" | "ci/git/impacted/source_repo/git" | null | "02fcc183ad25f086aaec562224abc1b323ebaaa9" - "fresh clone" | "ci/git/impacted/new_clone/git" | null | "02fcc183ad25f086aaec562224abc1b323ebaaa9" - "no remote clone" | "ci/git/impacted/no_remote/git" | null | null - "Github Actions style clone" | "ci/git/impacted/ghub_actions_clone/git" | null | "02fcc183ad25f086aaec562224abc1b323ebaaa9" + testcaseName | repo | baseBranch | expected + "base branch provided" | "ci/git/impacted/source_repo/git" | "master" | "c0a09c420836a5d2c1ce4c74d9c4e732d4ccd065" + "base branch not provided" | "ci/git/impacted/source_repo/git" | null | "c0a09c420836a5d2c1ce4c74d9c4e732d4ccd065" + "fresh clone with remote cloned into master" | "ci/git/impacted/new_clone/git" | null | "c0a09c420836a5d2c1ce4c74d9c4e732d4ccd065" + "no remote clone" | "ci/git/impacted/no_remote/git" | null | null + "Github Actions style clone" | "ci/git/impacted/ghub_actions_clone/git" | null | "c0a09c420836a5d2c1ce4c74d9c4e732d4ccd065" } private void givenGitRepo() { diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/FETCH_HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/FETCH_HEAD index 189fccde139..136e833a01e 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/FETCH_HEAD +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/FETCH_HEAD @@ -1 +1 @@ -1ef73e8a15f4920afa1bd5d0fa1464e745f7e4d6 branch 'feature' of /tmp/impacted/repo_origin +2fdf0c87f0a59400612ea7bff833507e8b4572eb branch 'feature' of /tmp/impacted/repo_origin diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 deleted file mode 100644 index 33aaacf527e71e09210c0479e92efd9e1dc54ea5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 400 zcmV;B0dM|z0j-fwZ=)~}#rMpo@O`zdjR9k6ceMlvAq`FmkWy|A81e^jN=Xy-)30fJ z+~bZk)|;O+Pow8jcHLnFrlo%y2O)rfmEZ{3)U+i zUH1k4RD9%>Z1yjArR;tKWlNz>)D7S})FIRqRR@paKUg*A=Jn8kA5+czAY>p(79a@& z=A_xi|KJ+P5DPQdE}W@i)m}8IRf(BgJ#A0XF+)*$npl$rCTRm6&@QNxa97w?xv1vZ z@|0^}w(6Jdpo^ZlcJ`9a;k4ludix=!!EuUr9{9>FRC<<9#Kr8LyQnR^5V6!ZH89b5 zeX-6DN4G3kdfYs_Z)+othFL4Od4BH$NTJ0;rD5kZ2|;on-+rOI3n&S&}F3=`z{yN@DrlyL#$cnf3B#41Ve=^Fzmua7D&^!@jM8Ao-S*@~H$>`+9 zC+#OQSzF>&uCdMnjzvOk0B0KAy<8p_A$yR8e;;SpJ8I?Is660)yiin;%U`{V^*Idj zvDoz2Qs81rM`;ixZI6B-M(956i;Qbs_1Ros(@U9sesp0z< Jz&|MVpSURSxc~qF diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 deleted file mode 100644 index 5713a364c0f53d5fc5f4804fea9526f68485eb45..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 399 zcmV;A0dW3!0j-fuZ<|06hI`&$vG*$Je!v1!8x@exkijIQaB75g+z>55-W%0nCe{HwkD=9s0M>L zt8RpdXeqHxML|rBY$k+~CL@FxB9}O)gsNN!;Q;YER{a@zqN`N{`9Ka0oC__!?&ha#*7td-VDepJCpU3!+;W$0ctV{yaY61~BZJ?7V-`h-v#bdTQ zJ_ESebgSk}RL7Tgc1j=7JmKw0^DgGbb@w+B_|vv%(u;H^OUiFziJQF_VV?RXfHQrH zjcc$NejI|;Eh4uaTW4tZ#w}57FISn=asTCaZ4Czpk8joXLWbd`U1P%wUwAy0jnilV tBV=E_Q|R*MsKaHucB@}y^bP#A!{^@r%mCRi{YMpW>rXcL;12|MtZg1{#Q*>R diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb new file mode 100644 index 0000000000000000000000000000000000000000..fc762bfc0f430fd942884db636179febd4390b0f GIT binary patch literal 400 zcmV;B0dM|z0j-hSZks?5hI_qFvG-QvJ%K@LtAfE8$7~Z0Ny^=_yI{v0e86$a(-+cS z_Oc_*=$}uT(dZx9HO;<qN+ggi89^2`g`tSVQZu<=YJ_@0iDFVJWEwzR`(1a2o@n>FhEccEO0*sPGS(5? zHGjc(C3>N{YInMmUGoj%1+xjllrcC%1R*fe@!($nhgH?Fy6h|Xc?#DLLJpH;4U;h7 zPMXF32L~|2Jj_tNcBXh7(~Bmxm6Uhe=chyTn&ButOsq-*V^Iepu$!Pv!Xmd!xmK%e zb9e#J-L{+hOmxeaR(48PXqxbHQh$i4ah!Y*fj@2wNA0E)SyDcTC9ZQX#60y404Ms$ zy%^6=_p;Hq_jz{XRFJ`9Khq)l6%>)1R$9l`hy3_-nXjI0&93D2-F1@~-(K1u!}fpx u95%BhzC5tE{VZQ4K~y;Rx9BVQV~5YZf0+TY1$?Y z*=3Jp>)cQB(baJ=_Pv@RLFChXlM>3jDlOA-N+Ai}ltnJ8wILBEMvf}mB96JSuv6JU z{GOZf27NIo*}-^hWGRLbe$lrE5B&%DR*G4aW8F*-#n^v^NQYwstxXJ91~v?!sa{}~ z{~@Zr*1uE@KQGz_G-NPM_b?49b2I)Uc;f(a#6oU#dv{Tyj~_2CD%Na_em-B~mZLbk zEUZo`u{tWK)6*&q^RvAv_T`QrE++uD(QxQ)SPsmy`IPO9<%NI7-J4kk*FE0_4Rl(l z{We>Ow`OclROnXOjpStaHpc&{U1{=doq;h<(EI{5wz J;4ky^pFI~*uv!2B literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 new file mode 100644 index 0000000000000000000000000000000000000000..d17db308f43031c3d32a404b62f792e443b636b4 GIT binary patch literal 395 zcmV;60d)R&0j-hCj+`(MMYHx-ct6SvwgH2bMBxoR4e4$mJz{6Dd4xAZvY4-rnPiz| zN~+SWBUPz%tD48L+o7i85Bnwr6bcs%A;Z*+l2n3nr6d|*tR@su%2dHBgL2IT3){rB zL!(q`tW!)eW?0t+sZ~l8+1Fe{s;<{YZR(XU0QORoAfl>?6+~1F9~7)8KvH?|F8;%+W@%o#27Wxk_JSyZX&S;b3KA>J zZ{9lxFh@z0D??}KKNdt`z0SnAAsMDw{4801upP%{{ z0PXX18a6DZ#4++U^Oa-5E%5Lzj>fWzHx_tuTO_re9mFBY8*|W5xDiS+PXq9v*SK1T zdVQWxVKMDb&Co=)|Ki*9+og5+i zUH1k4RD9%>Z1yjArR;tKWlNz>)D7S})FIRqRR@paKUg*A=Jn8kA5+czAY>p(79a@& z=A_xi|KJ+P5DPQdE}W@i)m}8IRf(BgJ#A0XF+)*$npl$rCTRm6&@QNxa97w?xv1vZ z@|0^}w(6Jdpo^ZlcJ`9a;k4ludix=!!EuUr9{9>FRC<<9#Kr8LyQnR^5V6!ZH89b5 zeX-6DN4G3kdfYs_Z)+othFL4Od4BH$NTJ0;rD5kZ2|;on-+rOI3n&S&}F3=`z{yN@DrlyL#$cnf3B#41Ve=^Fzmua7D&^!@jM8Ao-S*@~H$>`+9 zC+#OQSzF>&uCdMnjzvOk0B0KAy<8p_A$yR8e;;SpJ8I?Is660)yiin;%U`{V^*Idj zvDoz2Qs81rM`;ixZI6B-M(956i;Qbs_1Ros(@U9sesp0z< Jz&|MVpSURSxc~qF diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 deleted file mode 100644 index 5713a364c0f53d5fc5f4804fea9526f68485eb45..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 399 zcmV;A0dW3!0j-fuZ<|06hI`&$vG*$Je!v1!8x@exkijIQaB75g+z>55-W%0nCe{HwkD=9s0M>L zt8RpdXeqHxML|rBY$k+~CL@FxB9}O)gsNN!;Q;YER{a@zqN`N{`9Ka0oC__!?&ha#*7td-VDepJCpU3!+;W$0ctV{yaY61~BZJ?7V-`h-v#bdTQ zJ_ESebgSk}RL7Tgc1j=7JmKw0^DgGbb@w+B_|vv%(u;H^OUiFziJQF_VV?RXfHQrH zjcc$NejI|;Eh4uaTW4tZ#w}57FISn=asTCaZ4Czpk8joXLWbd`U1P%wUwAy0jnilV tBV=E_Q|R*MsKaHucB@}y^bP#A!{^@r%mCRi{YMpW>rXcL;12|MtZg1{#Q*>R diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb new file mode 100644 index 0000000000000000000000000000000000000000..fc762bfc0f430fd942884db636179febd4390b0f GIT binary patch literal 400 zcmV;B0dM|z0j-hSZks?5hI_qFvG-QvJ%K@LtAfE8$7~Z0Ny^=_yI{v0e86$a(-+cS z_Oc_*=$}uT(dZx9HO;<qN+ggi89^2`g`tSVQZu<=YJ_@0iDFVJWEwzR`(1a2o@n>FhEccEO0*sPGS(5? zHGjc(C3>N{YInMmUGoj%1+xjllrcC%1R*fe@!($nhgH?Fy6h|Xc?#DLLJpH;4U;h7 zPMXF32L~|2Jj_tNcBXh7(~Bmxm6Uhe=chyTn&ButOsq-*V^Iepu$!Pv!Xmd!xmK%e zb9e#J-L{+hOmxeaR(48PXqxbHQh$i4ah!Y*fj@2wNA0E)SyDcTC9ZQX#60y404Ms$ zy%^6=_p;Hq_jz{XRFJ`9Khq)l6%>)1R$9l`hy3_-nXjI0&93D2-F1@~-(K1u!}fpx u95%BhzC5tE{VZQ4K~y;Rx9BVQV~5YZf0+TY1$?Y z*=3Jp>)cQB(baJ=_Pv@RLFChXlM>3jDlOA-N+Ai}ltnJ8wILBEMvf}mB96JSuv6JU z{GOZf27NIo*}-^hWGRLbe$lrE5B&%DR*G4aW8F*-#n^v^NQYwstxXJ91~v?!sa{}~ z{~@Zr*1uE@KQGz_G-NPM_b?49b2I)Uc;f(a#6oU#dv{Tyj~_2CD%Na_em-B~mZLbk zEUZo`u{tWK)6*&q^RvAv_T`QrE++uD(QxQ)SPsmy`IPO9<%NI7-J4kk*FE0_4Rl(l z{We>Ow`OclROnXOjpStaHpc&{U1{=doq;h<(EI{5wz J;4ky^pFI~*uv!2B literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 new file mode 100644 index 0000000000000000000000000000000000000000..d17db308f43031c3d32a404b62f792e443b636b4 GIT binary patch literal 395 zcmV;60d)R&0j-hCj+`(MMYHx-ct6SvwgH2bMBxoR4e4$mJz{6Dd4xAZvY4-rnPiz| zN~+SWBUPz%tD48L+o7i85Bnwr6bcs%A;Z*+l2n3nr6d|*tR@su%2dHBgL2IT3){rB zL!(q`tW!)eW?0t+sZ~l8+1Fe{s;<{YZR(XU0QORoAfl>?6+~1F9~7)8KvH?|F8;%+W@%o#27Wxk_JSyZX&S;b3KA>J zZ{9lxFh@z0D??}KKNdt`z0SnAAsMDw{4801upP%{{ z0PXX18a6DZ#4++U^Oa-5E%5Lzj>fWzHx_tuTO_re9mFBY8*|W5xDiS+PXq9v*SK1T zdVQWxVKMDb&Co=)|Ki*9+og5G+PdENP{!gz-!TTMp6h9zim4__l8|XkmQy9)d_)35V5H*$J^Kf% z;=4HQ3-~m}+;&_7gJ1~**C9q2ecCq;V1$VqA-*)GSdVG>lkzf=v|jvG`G*MmVKuQL zaAcJ`)X{5a7r5zGQ?g~gh(4+Wz`56a@J?V2F}3IzF3>b#Z3TW4Q)3w0D|PJA%^meT zoQNrsD>X6SS}rD`Edw~wwU4+Tn!~zbMn$^K>QW7Hc@b7PGn0*?JeQajaqrM$LPM@o zKe0N^@LUg@1vj#ToB?PLNpWhrW39H{*^I4fQ4PZ@xSzu&)?dc}yM1@+;r$2T2UZH6 E%wxW%=>Px# literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/d8/a57e1a0937c50c15cc7b9a3e39dc73a1249eaa b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/d8/a57e1a0937c50c15cc7b9a3e39dc73a1249eaa deleted file mode 100644 index d1304fc58e55e69be44389a3a3eca5505d498e3a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 364 zcmV-y0h9iC0j-hSZlf>|hWFY};rnP?b1(*}t(Jt7(?FE~X_q^L&7lFD5UOnR^b1Wd z_i{&?(LbLwzeY2K?7C)zSkZorgAkBe+{$^b<))_VYGDeDbAy-MP;x{pWa@;dNC*?K zkFk~mbXebr7KXAGob?huOmzZx-8cBf*~qx8>eF2zyCPsS+lK znN_imN$WG;>ijaMd1e|#z`b;Rcmr^`>DTR`iauJI=_&EhJmF+&`z7YawzDhq-N}tk zdYQ~*rA1e^QrgU+N|d-5z?p7?G2Y8pu^}3b@3GCh;nTaI!|wSiKdR$!5ubQl1_m|m zdqTUH#ha^}i?;Y(l_snIqN+ggi89^2`g`tSVQZu<=YJ_@0iDFVJWEwzR`(1a2o@n>FhEccEO0*sPGS(5? zHGjc(C3>N{YInMmUGoj%1+xjllrcC%1R*fe@!($nhgH?Fy6h|Xc?#DLLJpH;4U;h7 zPMXF32L~|2Jj_tNcBXh7(~Bmxm6Uhe=chyTn&ButOsq-*V^Iepu$!Pv!Xmd!xmK%e zb9e#J-L{+hOmxeaR(48PXqxbHQh$i4ah!Y*fj@2wNA0E)SyDcTC9ZQX#60y404Ms$ zy%^6=_p;Hq_jz{XRFJ`9Khq)l6%>)1R$9l`hy3_-nXjI0&93D2-F1@~-(K1u!}fpx u95%BhzC5tE{VZQ4K~y;Rx9BVQV~5YZf0+TYH&;f?#!jCb#dcrnM>^Wl4u_wy@? KBpGyb1tI_?PZjn6 literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/82/ac08af7cb3071716559cc26257ee21dfc8e4d3 new file mode 100644 index 0000000000000000000000000000000000000000..be32d0e3b5368ab64f56d0d5e1458235f46fcaeb GIT binary patch literal 54 zcmV-60LlM&0ZYosPf{>7VDL!I$;sDID91$?Y z*=3Jp>)cQB(baJ=_Pv@RLFChXlM>3jDlOA-N+Ai}ltnJ8wILBEMvf}mB96JSuv6JU z{GOZf27NIo*}-^hWGRLbe$lrE5B&%DR*G4aW8F*-#n^v^NQYwstxXJ91~v?!sa{}~ z{~@Zr*1uE@KQGz_G-NPM_b?49b2I)Uc;f(a#6oU#dv{Tyj~_2CD%Na_em-B~mZLbk zEUZo`u{tWK)6*&q^RvAv_T`QrE++uD(QxQ)SPsmy`IPO9<%NI7-J4kk*FE0_4Rl(l z{We>Ow`OclROnXOjpStaHpc&{U1{=doq;h<(EI{5wz J;4ky^pFI~*uv!2B literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/95/e75d98dbaf42c1efc9be0405e079f97aa24888 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/95/e75d98dbaf42c1efc9be0405e079f97aa24888 new file mode 100644 index 0000000000000000000000000000000000000000..ede3afb759c9162dfa082dea54e57098db5c54a8 GIT binary patch literal 32 ocmbORoAfl>?6+~1F9~7)8KvH?|F8;%+W@%o#27Wxk_JSyZX&S;b3KA>J zZ{9lxFh@z0D??}KKNdt`z0SnAAsMDw{4801upP%{{ z0PXX18a6DZ#4++U^Oa-5E%5Lzj>fWzHx_tuTO_re9mFBY8*|W5xDiS+PXq9v*SK1T zdVQWxVKMDb&Co=)|Ki*9+og59XD~D{Ff%bx2y%6F@paY9O<|b&Ja)$I^-c%hpWMg7`k?Y> M)gq4$08!%+@=25!`2YX_ literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/eb/fd7499dae526dcbaf30e1250b1f875946729f8 new file mode 100644 index 0000000000000000000000000000000000000000..5d38589c034979d3a28af66bfc520c73cea959a3 GIT binary patch literal 54 zcmV-60LlM&0V^p=O;s>9XD~D{Ff%bx2y%6F@paY9O<`CcrnY6F$m-Kg*KD_+;Lx#g M4|^&N05>xaVkvSJ$p8QV literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature new file mode 100644 index 00000000000..212e8c1b10f --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature @@ -0,0 +1 @@ +2fdf0c87f0a59400612ea7bff833507e8b4572eb diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master new file mode 100644 index 00000000000..8afc163067b --- /dev/null +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master @@ -0,0 +1 @@ +c0a09c420836a5d2c1ce4c74d9c4e732d4ccd065 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/02/fcc183ad25f086aaec562224abc1b323ebaaa9 deleted file mode 100644 index 33aaacf527e71e09210c0479e92efd9e1dc54ea5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 400 zcmV;B0dM|z0j-fwZ=)~}#rMpo@O`zdjR9k6ceMlvAq`FmkWy|A81e^jN=Xy-)30fJ z+~bZk)|;O+Pow8jcHLnFrlo%y2O)rfmEZ{3)U+i zUH1k4RD9%>Z1yjArR;tKWlNz>)D7S})FIRqRR@paKUg*A=Jn8kA5+czAY>p(79a@& z=A_xi|KJ+P5DPQdE}W@i)m}8IRf(BgJ#A0XF+)*$npl$rCTRm6&@QNxa97w?xv1vZ z@|0^}w(6Jdpo^ZlcJ`9a;k4ludix=!!EuUr9{9>FRC<<9#Kr8LyQnR^5V6!ZH89b5 zeX-6DN4G3kdfYs_Z)+othFL4Od4BH$NTJ0;rD5kZ2|;on-+rOI3n&S&}F3=`z{yN@DrlyL#$cnf3B#41Ve=^Fzmua7D&^!@jM8Ao-S*@~H$>`+9 zC+#OQSzF>&uCdMnjzvOk0B0KAy<8p_A$yR8e;;SpJ8I?Is660)yiin;%U`{V^*Idj zvDoz2Qs81rM`;ixZI6B-M(956i;Qbs_1Ros(@U9sesp0z< Jz&|MVpSURSxc~qF diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/1e/f73e8a15f4920afa1bd5d0fa1464e745f7e4d6 deleted file mode 100644 index 5713a364c0f53d5fc5f4804fea9526f68485eb45..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 399 zcmV;A0dW3!0j-fuZ<|06hI`&$vG*$Je!v1!8x@exkijIQaB75g+z>55-W%0nCe{HwkD=9s0M>L zt8RpdXeqHxML|rBY$k+~CL@FxB9}O)gsNN!;Q;YER{a@zqN`N{`9Ka0oC__!?&ha#*7td-VDepJCpU3!+;W$0ctV{yaY61~BZJ?7V-`h-v#bdTQ zJ_ESebgSk}RL7Tgc1j=7JmKw0^DgGbb@w+B_|vv%(u;H^OUiFziJQF_VV?RXfHQrH zjcc$NejI|;Eh4uaTW4tZ#w}57FISn=asTCaZ4Czpk8joXLWbd`U1P%wUwAy0jnilV tBV=E_Q|R*MsKaHucB@}y^bP#A!{^@r%mCRi{YMpW>rXcL;12|MtZg1{#Q*>R diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb new file mode 100644 index 0000000000000000000000000000000000000000..fc762bfc0f430fd942884db636179febd4390b0f GIT binary patch literal 400 zcmV;B0dM|z0j-hSZks?5hI_qFvG-QvJ%K@LtAfE8$7~Z0Ny^=_yI{v0e86$a(-+cS z_Oc_*=$}uT(dZx9HO;<qN+ggi89^2`g`tSVQZu<=YJ_@0iDFVJWEwzR`(1a2o@n>FhEccEO0*sPGS(5? zHGjc(C3>N{YInMmUGoj%1+xjllrcC%1R*fe@!($nhgH?Fy6h|Xc?#DLLJpH;4U;h7 zPMXF32L~|2Jj_tNcBXh7(~Bmxm6Uhe=chyTn&ButOsq-*V^Iepu$!Pv!Xmd!xmK%e zb9e#J-L{+hOmxeaR(48PXqxbHQh$i4ah!Y*fj@2wNA0E)SyDcTC9ZQX#60y404Ms$ zy%^6=_p;Hq_jz{XRFJ`9Khq)l6%>)1R$9l`hy3_-nXjI0&93D2-F1@~-(K1u!}fpx u95%BhzC5tE{VZQ4K~y;Rx9BVQV~5YZf0+TY1$?Y z*=3Jp>)cQB(baJ=_Pv@RLFChXlM>3jDlOA-N+Ai}ltnJ8wILBEMvf}mB96JSuv6JU z{GOZf27NIo*}-^hWGRLbe$lrE5B&%DR*G4aW8F*-#n^v^NQYwstxXJ91~v?!sa{}~ z{~@Zr*1uE@KQGz_G-NPM_b?49b2I)Uc;f(a#6oU#dv{Tyj~_2CD%Na_em-B~mZLbk zEUZo`u{tWK)6*&q^RvAv_T`QrE++uD(QxQ)SPsmy`IPO9<%NI7-J4kk*FE0_4Rl(l z{We>Ow`OclROnXOjpStaHpc&{U1{=doq;h<(EI{5wz J;4ky^pFI~*uv!2B literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 new file mode 100644 index 0000000000000000000000000000000000000000..d17db308f43031c3d32a404b62f792e443b636b4 GIT binary patch literal 395 zcmV;60d)R&0j-hCj+`(MMYHx-ct6SvwgH2bMBxoR4e4$mJz{6Dd4xAZvY4-rnPiz| zN~+SWBUPz%tD48L+o7i85Bnwr6bcs%A;Z*+l2n3nr6d|*tR@su%2dHBgL2IT3){rB zL!(q`tW!)eW?0t+sZ~l8+1Fe{s;<{YZR(XU0QORoAfl>?6+~1F9~7)8KvH?|F8;%+W@%o#27Wxk_JSyZX&S;b3KA>J zZ{9lxFh@z0D??}KKNdt`z0SnAAsMDw{4801upP%{{ z0PXX18a6DZ#4++U^Oa-5E%5Lzj>fWzHx_tuTO_re9mFBY8*|W5xDiS+PXq9v*SK1T zdVQWxVKMDb&Co=)|Ki*9+og5 Date: Fri, 6 Jun 2025 11:24:59 +0200 Subject: [PATCH 25/28] fix code violation --- .../datadog/trace/civisibility/git/tree/ShellGitClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java index a85b737f4d7..4d1f3ce2534 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/git/tree/ShellGitClient.java @@ -637,7 +637,7 @@ String getRemoteName() throws IOException, InterruptedException, TimeoutExceptio "@{upstream}") .trim(); - int slashIdx = remote.indexOf("/"); + int slashIdx = remote.indexOf('/'); return slashIdx != -1 ? remote.substring(0, slashIdx) : remote; } catch (ShellCommandExecutor.ShellCommandFailedException e) { LOGGER.debug("Error getting remote from upstream, falling back to first remote", e); From 2970e68656019c86c982673225414f83efaa093a Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Fri, 6 Jun 2025 11:29:52 +0200 Subject: [PATCH 26/28] junit 4 test import wildcard --- .../src/test/groovy/JUnit4Test.groovy | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/dd-java-agent/instrumentation/junit-4.10/src/test/groovy/JUnit4Test.groovy b/dd-java-agent/instrumentation/junit-4.10/src/test/groovy/JUnit4Test.groovy index aa9eaa8eb29..b6729a25612 100644 --- a/dd-java-agent/instrumentation/junit-4.10/src/test/groovy/JUnit4Test.groovy +++ b/dd-java-agent/instrumentation/junit-4.10/src/test/groovy/JUnit4Test.groovy @@ -6,34 +6,7 @@ import datadog.trace.civisibility.CiVisibilityInstrumentationTest import datadog.trace.civisibility.diff.LineDiff import datadog.trace.instrumentation.junit4.JUnit4Utils import datadog.trace.instrumentation.junit4.TestEventsHandlerHolder -import org.example.TestAssumption -import org.example.TestAssumptionAndSucceed -import org.example.TestError -import org.example.TestFailed -import org.example.TestFailedAndSucceed -import org.example.TestFailedParameterized -import org.example.TestFailedSuiteSetUpAssumption -import org.example.TestFailedSuiteSetup -import org.example.TestFailedSuiteTearDown -import org.example.TestFailedThenSucceed -import org.example.TestInheritance -import org.example.TestParameterized -import org.example.TestParameterizedJUnitParams -import org.example.TestSkipped -import org.example.TestSkippedClass -import org.example.TestSucceed -import org.example.TestSucceedAndSkipped -import org.example.TestSucceedExpectedException -import org.example.TestSucceedKotlin -import org.example.TestSucceedLegacy -import org.example.TestSucceedParameterizedKotlin -import org.example.TestSucceedSkipEfd -import org.example.TestSucceedSlow -import org.example.TestSucceedSuite -import org.example.TestSucceedUnskippable -import org.example.TestSucceedUnskippableSuite -import org.example.TestSucceedVerySlow -import org.example.TestSucceedWithCategories +import org.example.* import org.junit.jupiter.api.Assumptions import org.junit.runner.JUnitCore From 99980be4b4a457f407395c52c0d3d9e1db3e60bd Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Fri, 6 Jun 2025 14:22:29 +0200 Subject: [PATCH 27/28] use relative paths in remotes and add remote origin to resources --- .../git/tree/GitClientTest.groovy | 49 +++++++--- .../ci/git/impacted/build_script.txt | 86 ++++++++++-------- .../git/impacted/ghub_actions_clone/README.md | 3 - .../ghub_actions_clone/git/FETCH_HEAD | 2 +- .../impacted/ghub_actions_clone/git/config | 2 +- .../15/567afb8426f72157c523d49dd49c24d6fe855e | Bin 0 -> 399 bytes .../26/0c03f5848ec8054374407916e806a80bec3729 | Bin 0 -> 402 bytes .../2f/df0c87f0a59400612ea7bff833507e8b4572eb | Bin 400 -> 0 bytes .../8b/0f2672722a266e3f4730727fd51466f8f96ce8 | Bin 363 -> 0 bytes .../c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 | Bin 395 -> 0 bytes .../da/b68487befcc4660679e7218fc5c171b32bc3c1 | Bin 0 -> 361 bytes .../ghub_actions_clone/git/refs/heads/feature | 2 +- .../git/refs/remotes/origin/feature | 2 +- .../ci/git/impacted/new_clone/README.md | 3 - .../ci/git/impacted/new_clone/git/FETCH_HEAD | 2 +- .../ci/git/impacted/new_clone/git/config | 2 +- .../15/567afb8426f72157c523d49dd49c24d6fe855e | Bin 0 -> 399 bytes .../26/0c03f5848ec8054374407916e806a80bec3729 | Bin 0 -> 402 bytes .../2f/df0c87f0a59400612ea7bff833507e8b4572eb | Bin 400 -> 0 bytes .../8b/0f2672722a266e3f4730727fd51466f8f96ce8 | Bin 363 -> 0 bytes .../c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 | Bin 395 -> 0 bytes .../da/b68487befcc4660679e7218fc5c171b32bc3c1 | Bin 0 -> 361 bytes .../impacted/new_clone/git/refs/heads/master | 2 +- .../new_clone/git/refs/remotes/origin/feature | 2 +- .../ci/git/impacted/no_remote/README.md | 1 - .../12/713d09915d037135ac7a4fdc092730ee493b2f | Bin 0 -> 365 bytes .../5a/4f2a814b65e38641d6d947ec67781c010bf61c | Bin 358 -> 0 bytes .../impacted/no_remote/git/refs/heads/master | 2 +- .../15/567afb8426f72157c523d49dd49c24d6fe855e | Bin 0 -> 399 bytes .../26/0c03f5848ec8054374407916e806a80bec3729 | Bin 0 -> 402 bytes .../2f/df0c87f0a59400612ea7bff833507e8b4572eb | Bin 400 -> 0 bytes .../8b/0f2672722a266e3f4730727fd51466f8f96ce8 | Bin 363 -> 0 bytes .../c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 | Bin 395 -> 0 bytes .../da/b68487befcc4660679e7218fc5c171b32bc3c1 | Bin 0 -> 361 bytes .../impacted/repo_origin/refs/heads/feature | 2 +- .../impacted/repo_origin/refs/heads/master | 2 +- .../ci/git/impacted/source_repo/README.md | 3 - .../ci/git/impacted/source_repo/git/config | 2 +- .../15/567afb8426f72157c523d49dd49c24d6fe855e | Bin 0 -> 399 bytes .../26/0c03f5848ec8054374407916e806a80bec3729 | Bin 0 -> 402 bytes .../2f/df0c87f0a59400612ea7bff833507e8b4572eb | Bin 400 -> 0 bytes .../8b/0f2672722a266e3f4730727fd51466f8f96ce8 | Bin 363 -> 0 bytes .../c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 | Bin 395 -> 0 bytes .../da/b68487befcc4660679e7218fc5c171b32bc3c1 | Bin 0 -> 361 bytes .../source_repo/git/refs/heads/feature | 2 +- .../source_repo/git/refs/heads/master | 2 +- .../git/refs/remotes/origin/feature | 2 +- .../git/refs/remotes/origin/master | 2 +- 48 files changed, 101 insertions(+), 76 deletions(-) delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/README.md create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/15/567afb8426f72157c523d49dd49c24d6fe855e create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/26/0c03f5848ec8054374407916e806a80bec3729 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/8b/0f2672722a266e3f4730727fd51466f8f96ce8 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/da/b68487befcc4660679e7218fc5c171b32bc3c1 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/README.md create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/15/567afb8426f72157c523d49dd49c24d6fe855e create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/26/0c03f5848ec8054374407916e806a80bec3729 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/8b/0f2672722a266e3f4730727fd51466f8f96ce8 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/da/b68487befcc4660679e7218fc5c171b32bc3c1 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/README.md create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/12/713d09915d037135ac7a4fdc092730ee493b2f delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/5a/4f2a814b65e38641d6d947ec67781c010bf61c create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/15/567afb8426f72157c523d49dd49c24d6fe855e create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/26/0c03f5848ec8054374407916e806a80bec3729 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/8b/0f2672722a266e3f4730727fd51466f8f96ce8 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/da/b68487befcc4660679e7218fc5c171b32bc3c1 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/README.md create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/15/567afb8426f72157c523d49dd49c24d6fe855e create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/26/0c03f5848ec8054374407916e806a80bec3729 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/2f/df0c87f0a59400612ea7bff833507e8b4572eb delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/8b/0f2672722a266e3f4730727fd51466f8f96ce8 delete mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 create mode 100644 dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/da/b68487befcc4660679e7218fc5c171b32bc3c1 diff --git a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy index f6674d9e598..7e59c128afa 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy +++ b/dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/git/tree/GitClientTest.groovy @@ -9,6 +9,7 @@ import datadog.trace.civisibility.telemetry.CiVisibilityMetricCollectorImpl import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths +import java.util.stream.Collectors import spock.lang.Specification import spock.lang.TempDir @@ -469,19 +470,19 @@ class GitClientTest extends Specification { } def "test get base branch sha: #testcaseName"() { - givenGitRepo(repo) - def gitClient = givenGitClient() + givenGitRepos(["ci/git/impacted/repo_origin", "ci/git/impacted/$repoName"]) + def gitClient = givenGitClient(repoName) expect: gitClient.getBaseCommitSha(baseBranch, null) == expected where: - testcaseName | repo | baseBranch | expected - "base branch provided" | "ci/git/impacted/source_repo/git" | "master" | "c0a09c420836a5d2c1ce4c74d9c4e732d4ccd065" - "base branch not provided" | "ci/git/impacted/source_repo/git" | null | "c0a09c420836a5d2c1ce4c74d9c4e732d4ccd065" - "fresh clone with remote cloned into master" | "ci/git/impacted/new_clone/git" | null | "c0a09c420836a5d2c1ce4c74d9c4e732d4ccd065" - "no remote clone" | "ci/git/impacted/no_remote/git" | null | null - "Github Actions style clone" | "ci/git/impacted/ghub_actions_clone/git" | null | "c0a09c420836a5d2c1ce4c74d9c4e732d4ccd065" + testcaseName | repoName | baseBranch | expected + "base branch provided" | "source_repo" | "master" | "15567afb8426f72157c523d49dd49c24d6fe855e" + "base branch not provided" | "source_repo" | null | "15567afb8426f72157c523d49dd49c24d6fe855e" + "fresh clone with remote cloned into master" | "new_clone" | null | "15567afb8426f72157c523d49dd49c24d6fe855e" + "no remote clone" | "no_remote" | null | null + "Github Actions style clone" | "ghub_actions_clone" | null | "15567afb8426f72157c523d49dd49c24d6fe855e" } private void givenGitRepo() { @@ -491,12 +492,36 @@ class GitClientTest extends Specification { private void givenGitRepo(String resourceName) { def gitFolder = Paths.get(getClass().getClassLoader().getResource(resourceName).toURI()) def tempGitFolder = tempDir.resolve(GIT_FOLDER) - Files.createDirectories(tempGitFolder) - IOUtils.copyFolder(gitFolder, tempGitFolder) + copyFolder(gitFolder, tempGitFolder) } - private givenGitClient() { + private void givenGitRepos(List resourceDirs) { + def resources = resourceDirs.stream().map(dir -> Paths.get(getClass().getClassLoader().getResource(dir).toURI())).collect(Collectors.toList()) + for (def resource : resources) { + def gitFolder = resource.resolve("git") + def destFolder = tempDir.resolve(resource.getFileName()) + if (Files.isDirectory(gitFolder)) { + // repos with git/ folder + def tempGitFolder = destFolder.resolve(GIT_FOLDER) + copyFolder(gitFolder, tempGitFolder) + } else { + // dirs with no git/ folder, i.e. a remote + copyFolder(resource, destFolder) + } + } + } + + private static void copyFolder(Path src, Path dest) { + Files.createDirectories(dest) + IOUtils.copyFolder(src, dest) + } + + private givenGitClient(String tempRelPath) { def metricCollector = Stub(CiVisibilityMetricCollectorImpl) - new ShellGitClient(metricCollector, tempDir.toString(), "25 years ago", 10, GIT_COMMAND_TIMEOUT_MILLIS) + new ShellGitClient(metricCollector, tempDir.resolve(tempRelPath).toString(), "25 years ago", 10, GIT_COMMAND_TIMEOUT_MILLIS) + } + + private givenGitClient() { + givenGitClient("") } } diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/build_script.txt b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/build_script.txt index 50d79f78a67..05876ce5294 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/build_script.txt +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/build_script.txt @@ -1,55 +1,65 @@ #!/bin/bash -origin_path="/tmp/impacted/repo_origin" -source_path="/tmp/impacted/source_repo" -new_clone_path="/tmp/impacted/new_clone" -no_remote_path="/tmp/impacted/no_remote" -ghub_actions_path="/tmp/impacted/ghub_actions_clone" +# IMPORTANT: always use relative paths, as tests move the folders to temp dirs +base_path="/tmp/impacted/" +origin_path="repo_origin" +source_path="source_repo" +new_clone_path="new_clone" +no_remote_path="no_remote" +ghub_actions_path="ghub_actions_clone" + +base_branch="master" +feature_branch="feature" + +mkdir -p $base_path +cd $base_path # create origin mkdir -p $origin_path -(cd $origin_path && git init --bare) +cd $origin_path && git init --bare +cd .. # create git repo -mkdir -p $source_path -(cd $source_path && git init && git remote add origin $origin_path) -(cd $source_path && echo "Hello, world!" >>README.md && git add README.md && git commit -m "Initial commit") -(cd $source_path && echo "Hello, world!" >>README.md && git add README.md && git commit -m "Update README") -(cd $source_path && git push origin master) - -base_branch="master" -feature_branch="feature" -base_commit=$(cd $source_path && git rev-parse HEAD) - +mkdir -p $source_path && cd $source_path +git init && git remote add origin "../$origin_path" +echo "Hello, world!" >>README.md && git add README.md && git commit -m "Initial commit" +echo "Hello, world!" >>README.md && git add README.md && git commit -m "Update README" +git push origin master +base_commit=$(git rev-parse HEAD) # create feature branch -(cd $source_path && git checkout -b $feature_branch) -(cd $source_path && echo "Feature branch change" >>README.md && git add README.md && git commit -m "Updated README") -(cd $source_path && git push origin $feature_branch) +git checkout -b $feature_branch +echo "Feature branch change" >>README.md && git add README.md && git commit -m "Feature branch commit" +git push origin $feature_branch +cd .. -# create new clone -mkdir -p $new_clone_path -(cd $new_clone_path && git init) -(cd $new_clone_path && git remote add origin $origin_path) -(cd $new_clone_path && git fetch origin $feature_branch) -(cd $new_clone_path && git reset --hard "origin/$feature_branch") +# clone with remote branch cloned into master branch of local repo +mkdir -p $new_clone_path && cd $new_clone_path +git init +git remote add origin "../$origin_path" +git fetch origin $feature_branch +git reset --hard "origin/$feature_branch" +cd .. # remote pointing to non existing repo -mkdir -p $no_remote_path -(cd $no_remote_path && git init) -(cd $no_remote_path && echo "base branch file" >>README.md && git add README.md && git commit -m "first commit") -(cd $no_remote_path && git remote add origin "git@git.com:datadog/non_existing_repo.git") +mkdir -p $no_remote_path && cd $no_remote_path +git init +echo "base branch file" >>README.md && git add README.md && git commit -m "first commit" +git remote add origin "git@git.com:datadog/non_existing_repo.git" +cd .. # github actions style clone -mkdir -p $ghub_actions_path -(cd $ghub_actions_path && git init) -(cd $ghub_actions_path && git remote add origin $origin_path) -(cd $ghub_actions_path && git fetch --no-tags --prune --no-recurse-submodules origin $feature_branch) -(cd $ghub_actions_path && git checkout --progress --force -B $feature_branch "refs/remotes/origin/$feature_branch") +mkdir -p $ghub_actions_path && cd $ghub_actions_path +git init +git remote add origin "../$origin_path" +git fetch --no-tags --prune --no-recurse-submodules origin $feature_branch +git checkout --progress --force -B $feature_branch "refs/remotes/origin/$feature_branch" +cd .. echo "BASE COMMIT: $base_commit" # cleanup -(cd $source_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index && mv .git git) -(cd $new_clone_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index && mv .git git) -(cd $no_remote_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index && mv .git git) -(cd $ghub_actions_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index && mv .git git) +(cd $origin_path && rm -rf hooks info logs COMMIT_EDITMSG description index README.md) +(cd $source_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index README.md && mv .git git) +(cd $new_clone_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index README.md && mv .git git) +(cd $no_remote_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index README.md && mv .git git) +(cd $ghub_actions_path && rm -rf .git/hooks .git/info .git/logs .git/COMMIT_EDITMSG .git/description .git/index README.md && mv .git git) diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/README.md b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/README.md deleted file mode 100644 index 82ac08af7cb..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Hello, world! -Hello, world! -Feature branch change diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/FETCH_HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/FETCH_HEAD index 136e833a01e..5f3b6da5777 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/FETCH_HEAD +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/FETCH_HEAD @@ -1 +1 @@ -2fdf0c87f0a59400612ea7bff833507e8b4572eb branch 'feature' of /tmp/impacted/repo_origin +260c03f5848ec8054374407916e806a80bec3729 branch 'feature' of ../repo_origin diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/config b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/config index 60dbbbd3c84..275c8aa9057 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/config +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/config @@ -6,7 +6,7 @@ ignorecase = true precomposeunicode = true [remote "origin"] - url = /tmp/impacted/repo_origin + url = ../repo_origin fetch = +refs/heads/*:refs/remotes/origin/* [branch "feature"] remote = origin diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/15/567afb8426f72157c523d49dd49c24d6fe855e b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/15/567afb8426f72157c523d49dd49c24d6fe855e new file mode 100644 index 0000000000000000000000000000000000000000..a5652bfaff0301ff35b0634296623fbd8362d86c GIT binary patch literal 399 zcmV;A0dW3!0j-fukDD+MhI{s}@O{;dZ9a^pwkiP!*ag}IXd-U5ae#!6Y(lr%{QAPS z#~wSohrWVSfmBqkC zT=g))N=Vx=9V+!vDbu!*O_`MD{501Y zJobOV*Gf#H8tdleQH}iJExy4Dpp21#`_=V~!uH)gUyAnO5o>RQ!8?;RLCF$P9(ztGU7XhEQMYCS#3-OHfE=y2exZ_OUx&$nAkR@_d*9g9wzXF`hC#%*3J t03*i2_T+E2{M7YkZLapEyZsFQ*uhi(UuJ;fGXF=z9iLs`;5WIfsts^Q%_IN- literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/26/0c03f5848ec8054374407916e806a80bec3729 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/26/0c03f5848ec8054374407916e806a80bec3729 new file mode 100644 index 0000000000000000000000000000000000000000..6a1524dae5b164f25a34b72d4815ebb4e93620a9 GIT binary patch literal 402 zcmV;D0d4+x0j-fukDD+MhI{s}@IC6*7;HdltCBz*BCtw;Zp6*lhOpryVaZm>uP^NO z*kebU(L0YcuSPR+=(=Wt#73W{QEOaX=s<0hFO)B<5ZXk%dEgf zjJltoK?t=)RXP@?m5mKzOM*>hxoS>{Ek!Hs5Tb#&O{ZamzUUj>!gx4oCHet=o$Cyq zy1(Fu5|dCveY!r$q5BRE+j22-9c;oC!U%zx&I?caKUme5`n9Ry=Oxww3pq^F9ZW;U zy(~Wj?;OC~;9-v1owr0XrynmWk|rOb=U?aeB{$;iys$cD#BP~jZpW%LEDMLqo!aL6 z^AW&x)bHC7>z;3%{F-giGT|4veHTmPdBsDpV0H^qN+ggi89^2`g`tSVQZu<=YJ_@0iDFVJWEwzR`(1a2o@n>FhEccEO0*sPGS(5? zHGjc(C3>N{YInMmUGoj%1+xjllrcC%1R*fe@!($nhgH?Fy6h|Xc?#DLLJpH;4U;h7 zPMXF32L~|2Jj_tNcBXh7(~Bmxm6Uhe=chyTn&ButOsq-*V^Iepu$!Pv!Xmd!xmK%e zb9e#J-L{+hOmxeaR(48PXqxbHQh$i4ah!Y*fj@2wNA0E)SyDcTC9ZQX#60y404Ms$ zy%^6=_p;Hq_jz{XRFJ`9Khq)l6%>)1R$9l`hy3_-nXjI0&93D2-F1@~-(K1u!}fpx u95%BhzC5tE{VZQ4K~y;Rx9BVQV~5YZf0+TY1$?Y z*=3Jp>)cQB(baJ=_Pv@RLFChXlM>3jDlOA-N+Ai}ltnJ8wILBEMvf}mB96JSuv6JU z{GOZf27NIo*}-^hWGRLbe$lrE5B&%DR*G4aW8F*-#n^v^NQYwstxXJ91~v?!sa{}~ z{~@Zr*1uE@KQGz_G-NPM_b?49b2I)Uc;f(a#6oU#dv{Tyj~_2CD%Na_em-B~mZLbk zEUZo`u{tWK)6*&q^RvAv_T`QrE++uD(QxQ)SPsmy`IPO9<%NI7-J4kk*FE0_4Rl(l z{We>Ow`OclROnXOjpStaHpc&{U1{=doq;h<(EI{5wz J;4ky^pFI~*uv!2B diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 deleted file mode 100644 index d17db308f43031c3d32a404b62f792e443b636b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 395 zcmV;60d)R&0j-hCj+`(MMYHx-ct6SvwgH2bMBxoR4e4$mJz{6Dd4xAZvY4-rnPiz| zN~+SWBUPz%tD48L+o7i85Bnwr6bcs%A;Z*+l2n3nr6d|*tR@su%2dHBgL2IT3){rB zL!(q`tW!)eW?0t+sZ~l8+1Fe{s;<{YZR(XU0QORoAfl>?6+~1F9~7)8KvH?|F8;%+W@%o#27Wxk_JSyZX&S;b3KA>J zZ{9lxFh@z0D??}KKNdt`z0SnAAsMDw{4801upP%{{ z0PXX18a6DZ#4++U^Oa-5E%5Lzj>fWzHx_tuTO_re9mFBY8*|W5xDiS+PXq9v*SK1T zdVQWxVKMDb&Co=)|Ki*9+og54HU&Y%$XW}l$ZdsPM84G0YW?*E?XkyB zGLv_nWZq0>;<_xe1}a#2Xih>vv6YEB)b)f5g^ZGT%jEzGOcb=mQd1RuI8uo&HNZcc zU44QUuQE|UuilA-S2cWUYYY12FL+IO!;?DQ9s6-zzChfX6QpYd!yY0CftI!lG~yqu z(nI=@rSP!}({@}6eSZpl*P%wh-t8L)kYVaFR7{O7mTg*Ir{?j1*7Nl$_x22XLEf>{ zcNDd7xTBYj^xbWwjpAuCVY560(41GZ;zUG6#~M2Z6Vy#u5h-q>YYZd0a>s7n+*X@G zN5%ts8aKxlt@!;sdJYs%uQ%j`S2XbMf{zu(w^81sqb&DW^cyA z{OcmmrLmKjT-$5nEoCZzi}mt2Kdh697sX;9#s%9O#xuB|!=~0>#{h1XH5o79{R`j+ H&v~CEy;`zV literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/heads/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/heads/feature index 212e8c1b10f..0d64cb911b3 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/heads/feature +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/heads/feature @@ -1 +1 @@ -2fdf0c87f0a59400612ea7bff833507e8b4572eb +260c03f5848ec8054374407916e806a80bec3729 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/remotes/origin/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/remotes/origin/feature index 212e8c1b10f..0d64cb911b3 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/remotes/origin/feature +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/ghub_actions_clone/git/refs/remotes/origin/feature @@ -1 +1 @@ -2fdf0c87f0a59400612ea7bff833507e8b4572eb +260c03f5848ec8054374407916e806a80bec3729 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/README.md b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/README.md deleted file mode 100644 index 82ac08af7cb..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Hello, world! -Hello, world! -Feature branch change diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/FETCH_HEAD b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/FETCH_HEAD index 136e833a01e..5f3b6da5777 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/FETCH_HEAD +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/FETCH_HEAD @@ -1 +1 @@ -2fdf0c87f0a59400612ea7bff833507e8b4572eb branch 'feature' of /tmp/impacted/repo_origin +260c03f5848ec8054374407916e806a80bec3729 branch 'feature' of ../repo_origin diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/config b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/config index b83d6f41726..69520278b4d 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/config +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/config @@ -6,5 +6,5 @@ ignorecase = true precomposeunicode = true [remote "origin"] - url = /tmp/impacted/repo_origin + url = ../repo_origin fetch = +refs/heads/*:refs/remotes/origin/* diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/15/567afb8426f72157c523d49dd49c24d6fe855e b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/15/567afb8426f72157c523d49dd49c24d6fe855e new file mode 100644 index 0000000000000000000000000000000000000000..a5652bfaff0301ff35b0634296623fbd8362d86c GIT binary patch literal 399 zcmV;A0dW3!0j-fukDD+MhI{s}@O{;dZ9a^pwkiP!*ag}IXd-U5ae#!6Y(lr%{QAPS z#~wSohrWVSfmBqkC zT=g))N=Vx=9V+!vDbu!*O_`MD{501Y zJobOV*Gf#H8tdleQH}iJExy4Dpp21#`_=V~!uH)gUyAnO5o>RQ!8?;RLCF$P9(ztGU7XhEQMYCS#3-OHfE=y2exZ_OUx&$nAkR@_d*9g9wzXF`hC#%*3J t03*i2_T+E2{M7YkZLapEyZsFQ*uhi(UuJ;fGXF=z9iLs`;5WIfsts^Q%_IN- literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/26/0c03f5848ec8054374407916e806a80bec3729 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/26/0c03f5848ec8054374407916e806a80bec3729 new file mode 100644 index 0000000000000000000000000000000000000000..6a1524dae5b164f25a34b72d4815ebb4e93620a9 GIT binary patch literal 402 zcmV;D0d4+x0j-fukDD+MhI{s}@IC6*7;HdltCBz*BCtw;Zp6*lhOpryVaZm>uP^NO z*kebU(L0YcuSPR+=(=Wt#73W{QEOaX=s<0hFO)B<5ZXk%dEgf zjJltoK?t=)RXP@?m5mKzOM*>hxoS>{Ek!Hs5Tb#&O{ZamzUUj>!gx4oCHet=o$Cyq zy1(Fu5|dCveY!r$q5BRE+j22-9c;oC!U%zx&I?caKUme5`n9Ry=Oxww3pq^F9ZW;U zy(~Wj?;OC~;9-v1owr0XrynmWk|rOb=U?aeB{$;iys$cD#BP~jZpW%LEDMLqo!aL6 z^AW&x)bHC7>z;3%{F-giGT|4veHTmPdBsDpV0H^qN+ggi89^2`g`tSVQZu<=YJ_@0iDFVJWEwzR`(1a2o@n>FhEccEO0*sPGS(5? zHGjc(C3>N{YInMmUGoj%1+xjllrcC%1R*fe@!($nhgH?Fy6h|Xc?#DLLJpH;4U;h7 zPMXF32L~|2Jj_tNcBXh7(~Bmxm6Uhe=chyTn&ButOsq-*V^Iepu$!Pv!Xmd!xmK%e zb9e#J-L{+hOmxeaR(48PXqxbHQh$i4ah!Y*fj@2wNA0E)SyDcTC9ZQX#60y404Ms$ zy%^6=_p;Hq_jz{XRFJ`9Khq)l6%>)1R$9l`hy3_-nXjI0&93D2-F1@~-(K1u!}fpx u95%BhzC5tE{VZQ4K~y;Rx9BVQV~5YZf0+TY1$?Y z*=3Jp>)cQB(baJ=_Pv@RLFChXlM>3jDlOA-N+Ai}ltnJ8wILBEMvf}mB96JSuv6JU z{GOZf27NIo*}-^hWGRLbe$lrE5B&%DR*G4aW8F*-#n^v^NQYwstxXJ91~v?!sa{}~ z{~@Zr*1uE@KQGz_G-NPM_b?49b2I)Uc;f(a#6oU#dv{Tyj~_2CD%Na_em-B~mZLbk zEUZo`u{tWK)6*&q^RvAv_T`QrE++uD(QxQ)SPsmy`IPO9<%NI7-J4kk*FE0_4Rl(l z{We>Ow`OclROnXOjpStaHpc&{U1{=doq;h<(EI{5wz J;4ky^pFI~*uv!2B diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 deleted file mode 100644 index d17db308f43031c3d32a404b62f792e443b636b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 395 zcmV;60d)R&0j-hCj+`(MMYHx-ct6SvwgH2bMBxoR4e4$mJz{6Dd4xAZvY4-rnPiz| zN~+SWBUPz%tD48L+o7i85Bnwr6bcs%A;Z*+l2n3nr6d|*tR@su%2dHBgL2IT3){rB zL!(q`tW!)eW?0t+sZ~l8+1Fe{s;<{YZR(XU0QORoAfl>?6+~1F9~7)8KvH?|F8;%+W@%o#27Wxk_JSyZX&S;b3KA>J zZ{9lxFh@z0D??}KKNdt`z0SnAAsMDw{4801upP%{{ z0PXX18a6DZ#4++U^Oa-5E%5Lzj>fWzHx_tuTO_re9mFBY8*|W5xDiS+PXq9v*SK1T zdVQWxVKMDb&Co=)|Ki*9+og54HU&Y%$XW}l$ZdsPM84G0YW?*E?XkyB zGLv_nWZq0>;<_xe1}a#2Xih>vv6YEB)b)f5g^ZGT%jEzGOcb=mQd1RuI8uo&HNZcc zU44QUuQE|UuilA-S2cWUYYY12FL+IO!;?DQ9s6-zzChfX6QpYd!yY0CftI!lG~yqu z(nI=@rSP!}({@}6eSZpl*P%wh-t8L)kYVaFR7{O7mTg*Ir{?j1*7Nl$_x22XLEf>{ zcNDd7xTBYj^xbWwjpAuCVY560(41GZ;zUG6#~M2Z6Vy#u5h-q>YYZd0a>s7n+*X@G zN5%ts8aKxlt@!;sdJYs%uQ%j`S2XbMf{zu(w^81sqb&DW^cyA z{OcmmrLmKjT-$5nEoCZzi}mt2Kdh697sX;9#s%9O#xuB|!=~0>#{h1XH5o79{R`j+ H&v~CEy;`zV literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/heads/master b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/heads/master index 212e8c1b10f..0d64cb911b3 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/heads/master +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/heads/master @@ -1 +1 @@ -2fdf0c87f0a59400612ea7bff833507e8b4572eb +260c03f5848ec8054374407916e806a80bec3729 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/remotes/origin/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/remotes/origin/feature index 212e8c1b10f..0d64cb911b3 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/remotes/origin/feature +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/new_clone/git/refs/remotes/origin/feature @@ -1 +1 @@ -2fdf0c87f0a59400612ea7bff833507e8b4572eb +260c03f5848ec8054374407916e806a80bec3729 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/README.md b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/README.md deleted file mode 100644 index ad686ebdcb3..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/README.md +++ /dev/null @@ -1 +0,0 @@ -base branch file diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/12/713d09915d037135ac7a4fdc092730ee493b2f b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/objects/12/713d09915d037135ac7a4fdc092730ee493b2f new file mode 100644 index 0000000000000000000000000000000000000000..a869f80166988d76da6d72e7675c2c82ac22d40d GIT binary patch literal 365 zcmV-z0h0cB0j-fubDJ;_hI`hp&^?n_5@2Aa%|sZCaf}*Q5P#ex5Fat1n$X1cuP-D$ z_Sl`-op+y^eP?Gk(`{Q1(89)-p;rnDH+N+&4e1!BNis)SmYnBBKF1Q-E^OWYOKg-v;gtt?8K^QT}`3mwVWHd>C1Ros06tgHr&5BO39n+5|waE;oH@oLk{F350 zIZdqOp=CFr2;DX;cqEU`JX__C7LGuBWXUw)KGf7iZB@6 zqEUOvL>30SiUn?teuP;PSO89RyQH&Sb;0%Fdbsc>jfzWSGjIDyhXQwAaG+PdENP{!gz-!TTMp6h9zim4__l8|XkmQy9)d_)35V5H*$J^Kf% z;=4HQ3-~m}+;&_7gJ1~**C9q2ecCq;V1$VqA-*)GSdVG>lkzf=v|jvG`G*MmVKuQL zaAcJ`)X{5a7r5zGQ?g~gh(4+Wz`56a@J?V2F}3IzF3>b#Z3TW4Q)3w0D|PJA%^meT zoQNrsD>X6SS}rD`Edw~wwU4+Tn!~zbMn$^K>QW7Hc@b7PGn0*?JeQajaqrM$LPM@o zKe0N^@LUg@1vj#ToB?PLNpWhrW39H{*^I4fQ4PZ@xSzu&)?dc}yM1@+;r$2T2UZH6 E%wxW%=>Px# diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/refs/heads/master b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/refs/heads/master index e1420bc6705..298cf07c2cd 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/refs/heads/master +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/no_remote/git/refs/heads/master @@ -1 +1 @@ -5a4f2a814b65e38641d6d947ec67781c010bf61c +12713d09915d037135ac7a4fdc092730ee493b2f diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/15/567afb8426f72157c523d49dd49c24d6fe855e b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/15/567afb8426f72157c523d49dd49c24d6fe855e new file mode 100644 index 0000000000000000000000000000000000000000..a5652bfaff0301ff35b0634296623fbd8362d86c GIT binary patch literal 399 zcmV;A0dW3!0j-fukDD+MhI{s}@O{;dZ9a^pwkiP!*ag}IXd-U5ae#!6Y(lr%{QAPS z#~wSohrWVSfmBqkC zT=g))N=Vx=9V+!vDbu!*O_`MD{501Y zJobOV*Gf#H8tdleQH}iJExy4Dpp21#`_=V~!uH)gUyAnO5o>RQ!8?;RLCF$P9(ztGU7XhEQMYCS#3-OHfE=y2exZ_OUx&$nAkR@_d*9g9wzXF`hC#%*3J t03*i2_T+E2{M7YkZLapEyZsFQ*uhi(UuJ;fGXF=z9iLs`;5WIfsts^Q%_IN- literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/26/0c03f5848ec8054374407916e806a80bec3729 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/26/0c03f5848ec8054374407916e806a80bec3729 new file mode 100644 index 0000000000000000000000000000000000000000..6a1524dae5b164f25a34b72d4815ebb4e93620a9 GIT binary patch literal 402 zcmV;D0d4+x0j-fukDD+MhI{s}@IC6*7;HdltCBz*BCtw;Zp6*lhOpryVaZm>uP^NO z*kebU(L0YcuSPR+=(=Wt#73W{QEOaX=s<0hFO)B<5ZXk%dEgf zjJltoK?t=)RXP@?m5mKzOM*>hxoS>{Ek!Hs5Tb#&O{ZamzUUj>!gx4oCHet=o$Cyq zy1(Fu5|dCveY!r$q5BRE+j22-9c;oC!U%zx&I?caKUme5`n9Ry=Oxww3pq^F9ZW;U zy(~Wj?;OC~;9-v1owr0XrynmWk|rOb=U?aeB{$;iys$cD#BP~jZpW%LEDMLqo!aL6 z^AW&x)bHC7>z;3%{F-giGT|4veHTmPdBsDpV0H^qN+ggi89^2`g`tSVQZu<=YJ_@0iDFVJWEwzR`(1a2o@n>FhEccEO0*sPGS(5? zHGjc(C3>N{YInMmUGoj%1+xjllrcC%1R*fe@!($nhgH?Fy6h|Xc?#DLLJpH;4U;h7 zPMXF32L~|2Jj_tNcBXh7(~Bmxm6Uhe=chyTn&ButOsq-*V^Iepu$!Pv!Xmd!xmK%e zb9e#J-L{+hOmxeaR(48PXqxbHQh$i4ah!Y*fj@2wNA0E)SyDcTC9ZQX#60y404Ms$ zy%^6=_p;Hq_jz{XRFJ`9Khq)l6%>)1R$9l`hy3_-nXjI0&93D2-F1@~-(K1u!}fpx u95%BhzC5tE{VZQ4K~y;Rx9BVQV~5YZf0+TY1$?Y z*=3Jp>)cQB(baJ=_Pv@RLFChXlM>3jDlOA-N+Ai}ltnJ8wILBEMvf}mB96JSuv6JU z{GOZf27NIo*}-^hWGRLbe$lrE5B&%DR*G4aW8F*-#n^v^NQYwstxXJ91~v?!sa{}~ z{~@Zr*1uE@KQGz_G-NPM_b?49b2I)Uc;f(a#6oU#dv{Tyj~_2CD%Na_em-B~mZLbk zEUZo`u{tWK)6*&q^RvAv_T`QrE++uD(QxQ)SPsmy`IPO9<%NI7-J4kk*FE0_4Rl(l z{We>Ow`OclROnXOjpStaHpc&{U1{=doq;h<(EI{5wz J;4ky^pFI~*uv!2B diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 deleted file mode 100644 index d17db308f43031c3d32a404b62f792e443b636b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 395 zcmV;60d)R&0j-hCj+`(MMYHx-ct6SvwgH2bMBxoR4e4$mJz{6Dd4xAZvY4-rnPiz| zN~+SWBUPz%tD48L+o7i85Bnwr6bcs%A;Z*+l2n3nr6d|*tR@su%2dHBgL2IT3){rB zL!(q`tW!)eW?0t+sZ~l8+1Fe{s;<{YZR(XU0QORoAfl>?6+~1F9~7)8KvH?|F8;%+W@%o#27Wxk_JSyZX&S;b3KA>J zZ{9lxFh@z0D??}KKNdt`z0SnAAsMDw{4801upP%{{ z0PXX18a6DZ#4++U^Oa-5E%5Lzj>fWzHx_tuTO_re9mFBY8*|W5xDiS+PXq9v*SK1T zdVQWxVKMDb&Co=)|Ki*9+og54HU&Y%$XW}l$ZdsPM84G0YW?*E?XkyB zGLv_nWZq0>;<_xe1}a#2Xih>vv6YEB)b)f5g^ZGT%jEzGOcb=mQd1RuI8uo&HNZcc zU44QUuQE|UuilA-S2cWUYYY12FL+IO!;?DQ9s6-zzChfX6QpYd!yY0CftI!lG~yqu z(nI=@rSP!}({@}6eSZpl*P%wh-t8L)kYVaFR7{O7mTg*Ir{?j1*7Nl$_x22XLEf>{ zcNDd7xTBYj^xbWwjpAuCVY560(41GZ;zUG6#~M2Z6Vy#u5h-q>YYZd0a>s7n+*X@G zN5%ts8aKxlt@!;sdJYs%uQ%j`S2XbMf{zu(w^81sqb&DW^cyA z{OcmmrLmKjT-$5nEoCZzi}mt2Kdh697sX;9#s%9O#xuB|!=~0>#{h1XH5o79{R`j+ H&v~CEy;`zV literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature index 212e8c1b10f..0d64cb911b3 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/feature @@ -1 +1 @@ -2fdf0c87f0a59400612ea7bff833507e8b4572eb +260c03f5848ec8054374407916e806a80bec3729 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master index 8afc163067b..690791ba203 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/repo_origin/refs/heads/master @@ -1 +1 @@ -c0a09c420836a5d2c1ce4c74d9c4e732d4ccd065 +15567afb8426f72157c523d49dd49c24d6fe855e diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/README.md b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/README.md deleted file mode 100644 index 82ac08af7cb..00000000000 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Hello, world! -Hello, world! -Feature branch change diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/config b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/config index b83d6f41726..69520278b4d 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/config +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/config @@ -6,5 +6,5 @@ ignorecase = true precomposeunicode = true [remote "origin"] - url = /tmp/impacted/repo_origin + url = ../repo_origin fetch = +refs/heads/*:refs/remotes/origin/* diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/15/567afb8426f72157c523d49dd49c24d6fe855e b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/15/567afb8426f72157c523d49dd49c24d6fe855e new file mode 100644 index 0000000000000000000000000000000000000000..a5652bfaff0301ff35b0634296623fbd8362d86c GIT binary patch literal 399 zcmV;A0dW3!0j-fukDD+MhI{s}@O{;dZ9a^pwkiP!*ag}IXd-U5ae#!6Y(lr%{QAPS z#~wSohrWVSfmBqkC zT=g))N=Vx=9V+!vDbu!*O_`MD{501Y zJobOV*Gf#H8tdleQH}iJExy4Dpp21#`_=V~!uH)gUyAnO5o>RQ!8?;RLCF$P9(ztGU7XhEQMYCS#3-OHfE=y2exZ_OUx&$nAkR@_d*9g9wzXF`hC#%*3J t03*i2_T+E2{M7YkZLapEyZsFQ*uhi(UuJ;fGXF=z9iLs`;5WIfsts^Q%_IN- literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/26/0c03f5848ec8054374407916e806a80bec3729 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/26/0c03f5848ec8054374407916e806a80bec3729 new file mode 100644 index 0000000000000000000000000000000000000000..6a1524dae5b164f25a34b72d4815ebb4e93620a9 GIT binary patch literal 402 zcmV;D0d4+x0j-fukDD+MhI{s}@IC6*7;HdltCBz*BCtw;Zp6*lhOpryVaZm>uP^NO z*kebU(L0YcuSPR+=(=Wt#73W{QEOaX=s<0hFO)B<5ZXk%dEgf zjJltoK?t=)RXP@?m5mKzOM*>hxoS>{Ek!Hs5Tb#&O{ZamzUUj>!gx4oCHet=o$Cyq zy1(Fu5|dCveY!r$q5BRE+j22-9c;oC!U%zx&I?caKUme5`n9Ry=Oxww3pq^F9ZW;U zy(~Wj?;OC~;9-v1owr0XrynmWk|rOb=U?aeB{$;iys$cD#BP~jZpW%LEDMLqo!aL6 z^AW&x)bHC7>z;3%{F-giGT|4veHTmPdBsDpV0H^qN+ggi89^2`g`tSVQZu<=YJ_@0iDFVJWEwzR`(1a2o@n>FhEccEO0*sPGS(5? zHGjc(C3>N{YInMmUGoj%1+xjllrcC%1R*fe@!($nhgH?Fy6h|Xc?#DLLJpH;4U;h7 zPMXF32L~|2Jj_tNcBXh7(~Bmxm6Uhe=chyTn&ButOsq-*V^Iepu$!Pv!Xmd!xmK%e zb9e#J-L{+hOmxeaR(48PXqxbHQh$i4ah!Y*fj@2wNA0E)SyDcTC9ZQX#60y404Ms$ zy%^6=_p;Hq_jz{XRFJ`9Khq)l6%>)1R$9l`hy3_-nXjI0&93D2-F1@~-(K1u!}fpx u95%BhzC5tE{VZQ4K~y;Rx9BVQV~5YZf0+TY1$?Y z*=3Jp>)cQB(baJ=_Pv@RLFChXlM>3jDlOA-N+Ai}ltnJ8wILBEMvf}mB96JSuv6JU z{GOZf27NIo*}-^hWGRLbe$lrE5B&%DR*G4aW8F*-#n^v^NQYwstxXJ91~v?!sa{}~ z{~@Zr*1uE@KQGz_G-NPM_b?49b2I)Uc;f(a#6oU#dv{Tyj~_2CD%Na_em-B~mZLbk zEUZo`u{tWK)6*&q^RvAv_T`QrE++uD(QxQ)SPsmy`IPO9<%NI7-J4kk*FE0_4Rl(l z{We>Ow`OclROnXOjpStaHpc&{U1{=doq;h<(EI{5wz J;4ky^pFI~*uv!2B diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/objects/c0/a09c420836a5d2c1ce4c74d9c4e732d4ccd065 deleted file mode 100644 index d17db308f43031c3d32a404b62f792e443b636b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 395 zcmV;60d)R&0j-hCj+`(MMYHx-ct6SvwgH2bMBxoR4e4$mJz{6Dd4xAZvY4-rnPiz| zN~+SWBUPz%tD48L+o7i85Bnwr6bcs%A;Z*+l2n3nr6d|*tR@su%2dHBgL2IT3){rB zL!(q`tW!)eW?0t+sZ~l8+1Fe{s;<{YZR(XU0QORoAfl>?6+~1F9~7)8KvH?|F8;%+W@%o#27Wxk_JSyZX&S;b3KA>J zZ{9lxFh@z0D??}KKNdt`z0SnAAsMDw{4801upP%{{ z0PXX18a6DZ#4++U^Oa-5E%5Lzj>fWzHx_tuTO_re9mFBY8*|W5xDiS+PXq9v*SK1T zdVQWxVKMDb&Co=)|Ki*9+og54HU&Y%$XW}l$ZdsPM84G0YW?*E?XkyB zGLv_nWZq0>;<_xe1}a#2Xih>vv6YEB)b)f5g^ZGT%jEzGOcb=mQd1RuI8uo&HNZcc zU44QUuQE|UuilA-S2cWUYYY12FL+IO!;?DQ9s6-zzChfX6QpYd!yY0CftI!lG~yqu z(nI=@rSP!}({@}6eSZpl*P%wh-t8L)kYVaFR7{O7mTg*Ir{?j1*7Nl$_x22XLEf>{ zcNDd7xTBYj^xbWwjpAuCVY560(41GZ;zUG6#~M2Z6Vy#u5h-q>YYZd0a>s7n+*X@G zN5%ts8aKxlt@!;sdJYs%uQ%j`S2XbMf{zu(w^81sqb&DW^cyA z{OcmmrLmKjT-$5nEoCZzi}mt2Kdh697sX;9#s%9O#xuB|!=~0>#{h1XH5o79{R`j+ H&v~CEy;`zV literal 0 HcmV?d00001 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/feature index 212e8c1b10f..0d64cb911b3 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/feature +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/feature @@ -1 +1 @@ -2fdf0c87f0a59400612ea7bff833507e8b4572eb +260c03f5848ec8054374407916e806a80bec3729 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/master b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/master index 8afc163067b..690791ba203 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/master +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/heads/master @@ -1 +1 @@ -c0a09c420836a5d2c1ce4c74d9c4e732d4ccd065 +15567afb8426f72157c523d49dd49c24d6fe855e diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/feature b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/feature index 212e8c1b10f..0d64cb911b3 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/feature +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/feature @@ -1 +1 @@ -2fdf0c87f0a59400612ea7bff833507e8b4572eb +260c03f5848ec8054374407916e806a80bec3729 diff --git a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/master b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/master index 8afc163067b..690791ba203 100644 --- a/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/master +++ b/dd-java-agent/agent-ci-visibility/src/test/resources/ci/git/impacted/source_repo/git/refs/remotes/origin/master @@ -1 +1 @@ -c0a09c420836a5d2c1ce4c74d9c4e732d4ccd065 +15567afb8426f72157c523d49dd49c24d6fe855e From a7381120fe7f5a5a410d58f8298edaca7308b0ae Mon Sep 17 00:00:00 2001 From: Daniel Mohedano Date: Tue, 17 Jun 2025 11:53:58 +0200 Subject: [PATCH 28/28] add javadoc and update tests for Strings.isBlank --- internal-api/src/main/java/datadog/trace/util/Strings.java | 7 +++++++ .../src/test/groovy/datadog/trace/util/StringsTest.groovy | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal-api/src/main/java/datadog/trace/util/Strings.java b/internal-api/src/main/java/datadog/trace/util/Strings.java index 23e7dbd7827..604298bcbe7 100644 --- a/internal-api/src/main/java/datadog/trace/util/Strings.java +++ b/internal-api/src/main/java/datadog/trace/util/Strings.java @@ -194,6 +194,13 @@ public static boolean isNotBlank(String s) { return false; } + /** + * Checks that a string is blank, i.e. doest not contain characters or is null + * + * @param s The string to be checked + * @return {@code true} if string is blank (string is {@code null}, empty, or contains only + * whitespace characters), {@code false} otherwise + */ public static boolean isBlank(String s) { return !isNotBlank(s); } diff --git a/internal-api/src/test/groovy/datadog/trace/util/StringsTest.groovy b/internal-api/src/test/groovy/datadog/trace/util/StringsTest.groovy index b7958191c8d..544874c6816 100644 --- a/internal-api/src/test/groovy/datadog/trace/util/StringsTest.groovy +++ b/internal-api/src/test/groovy/datadog/trace/util/StringsTest.groovy @@ -117,12 +117,14 @@ class StringsTest extends DDSpecification { "hélló wórld" | 5 | "hélló" } - def "test isNotBlank: #input"() { + def "test isNotBlank and isBlank: #input"() { when: def notBlank = Strings.isNotBlank(input) + def isBlank = Strings.isBlank(input) then: notBlank == expected + isBlank == !notBlank where: input | expected