Skip to content

Use tag as fallback in api requests if no branch is available #8876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private TracerEnvironment buildTracerEnvironment(JvmInfo jvmInfo, @Nullable Stri
.env(config.getEnv())
.repositoryUrl(gitInfo.getRepositoryURL())
.branch(gitInfo.getBranch())
.tag(gitInfo.getTag())
.sha(gitInfo.getCommit().getSha())
.commitMessage(gitInfo.getCommit().getFullMessage())
.osPlatform(wellKnownTags.getOsPlatform().toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.squareup.moshi.Json;
import datadog.trace.api.civisibility.config.Configurations;
import datadog.trace.util.Strings;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -111,6 +112,7 @@ public static final class Builder {
private String env;
private String repositoryUrl;
private String branch;
private String tag; // will act as fallback if no branch is provided
private String sha;
private String commitMessage;
private String osPlatform;
Expand Down Expand Up @@ -143,6 +145,11 @@ public Builder branch(String branch) {
return this;
}

public Builder tag(String tag) {
this.tag = tag;
return this;
}

public Builder sha(String sha) {
this.sha = sha;
return this;
Expand Down Expand Up @@ -203,7 +210,7 @@ public TracerEnvironment build() {
service,
env,
repositoryUrl,
branch,
Strings.isNotBlank(branch) ? branch : tag,
sha,
commitMessage,
new Configurations(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package datadog.trace.civisibility.config

import spock.lang.Specification

class TracerEnvironmentTest extends Specification {
def "test fallback to tag on no branch"() {
setup:
def builder = TracerEnvironment.builder()
def environment = builder.branch(branch).tag(tag).build()

expect:
environment.branch == environmentBranch

where:
branch | tag | environmentBranch
"main" | "v.1.0.0" | "main"
"main" | null | "main"
null | "v.1.0.0" | "v.1.0.0"
null | null | null
}
}