Skip to content

Commit e590c41

Browse files
Add pr.number tag and improve PR information building (#8990)
1 parent 8e58785 commit e590c41

33 files changed

+293
-51
lines changed

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityRepoServices.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ private static PullRequestInfo buildUserPullRequestInfo(
129129
new PullRequestInfo(
130130
config.getGitPullRequestBaseBranch(),
131131
config.getGitPullRequestBaseBranchSha(),
132-
config.getGitCommitHeadSha());
132+
config.getGitCommitHeadSha(),
133+
null);
133134

134135
if (userInfo.isComplete()) {
135136
return userInfo;
@@ -140,7 +141,8 @@ private static PullRequestInfo buildUserPullRequestInfo(
140141
new PullRequestInfo(
141142
null,
142143
environment.get(Constants.DDCI_PULL_REQUEST_TARGET_SHA),
143-
environment.get(Constants.DDCI_PULL_REQUEST_SOURCE_SHA));
144+
environment.get(Constants.DDCI_PULL_REQUEST_SOURCE_SHA),
145+
null);
144146

145147
return PullRequestInfo.merge(userInfo, ddCiInfo);
146148
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AppVeyorInfo.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ class AppVeyorInfo implements CIProviderInfo {
2424
public static final String APPVEYOR_REPO_PROVIDER = "APPVEYOR_REPO_PROVIDER";
2525
public static final String APPVEYOR_REPO_COMMIT = "APPVEYOR_REPO_COMMIT";
2626
public static final String APPVEYOR_REPO_BRANCH = "APPVEYOR_REPO_BRANCH";
27-
public static final String APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH =
28-
"APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH";
29-
public static final String APPVEYOR_PULL_REQUEST_HEAD_COMMIT =
30-
"APPVEYOR_PULL_REQUEST_HEAD_COMMIT";
3127
public static final String APPVEYOR_REPO_TAG_NAME = "APPVEYOR_REPO_TAG_NAME";
3228
public static final String APPVEYOR_REPO_COMMIT_MESSAGE_SUBJECT = "APPVEYOR_REPO_COMMIT_MESSAGE";
3329
public static final String APPVEYOR_REPO_COMMIT_MESSAGE_BODY =
3430
"APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED";
3531
public static final String APPVEYOR_REPO_COMMIT_AUTHOR_NAME = "APPVEYOR_REPO_COMMIT_AUTHOR";
3632
public static final String APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL =
3733
"APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL";
34+
public static final String APPVEYOR_PR_HEAD_REPO_BRANCH =
35+
"APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH";
36+
public static final String APPVEYOR_PR_HEAD_COMMIT = "APPVEYOR_PULL_REQUEST_HEAD_COMMIT";
37+
public static final String APPVEYOR_PR_NUMBER = "APPVEYOR_PULL_REQUEST_NUMBER";
3838

3939
private final CiEnvironment environment;
4040

@@ -87,19 +87,20 @@ public CIInfo buildCIInfo() {
8787
@Override
8888
public PullRequestInfo buildPullRequestInfo() {
8989
// check if PR is detected
90-
if (Strings.isNotBlank(environment.get(APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH))) {
90+
if (Strings.isNotBlank(environment.get(APPVEYOR_PR_HEAD_REPO_BRANCH))) {
9191
return new PullRequestInfo(
9292
normalizeBranch(environment.get(APPVEYOR_REPO_BRANCH)),
9393
null,
94-
environment.get(APPVEYOR_PULL_REQUEST_HEAD_COMMIT));
94+
environment.get(APPVEYOR_PR_HEAD_COMMIT),
95+
environment.get(APPVEYOR_PR_NUMBER));
9596
} else {
9697
return PullRequestInfo.EMPTY;
9798
}
9899
}
99100

100101
private String buildGitBranch(final String repoProvider) {
101102
if ("github".equals(repoProvider)) {
102-
String branch = environment.get(APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH);
103+
String branch = environment.get(APPVEYOR_PR_HEAD_REPO_BRANCH);
103104
if (branch == null || branch.isEmpty()) {
104105
branch = environment.get(APPVEYOR_REPO_BRANCH);
105106
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/AzurePipelinesInfo.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class AzurePipelinesInfo implements CIProviderInfo {
4040
public static final String AZURE_BUILD_SOURCEVERSION_MESSAGE = "BUILD_SOURCEVERSIONMESSAGE";
4141
public static final String AZURE_BUILD_REQUESTED_FOR_ID = "BUILD_REQUESTEDFORID";
4242
public static final String AZURE_BUILD_REQUESTED_FOR_EMAIL = "BUILD_REQUESTEDFOREMAIL";
43+
public static final String AZURE_PR_NUMBER = "SYSTEM_PULLREQUEST_PULLREQUESTNUMBER";
44+
public static final String AZURE_PR_TARGET_BRANCH = "SYSTEM_PULLREQUEST_TARGETBRANCH";
4345

4446
private final CiEnvironment environment;
4547

@@ -85,7 +87,11 @@ public CIInfo buildCIInfo() {
8587
@Nonnull
8688
@Override
8789
public PullRequestInfo buildPullRequestInfo() {
88-
return PullRequestInfo.EMPTY;
90+
return new PullRequestInfo(
91+
normalizeBranch(environment.get(AZURE_PR_TARGET_BRANCH)),
92+
null,
93+
null,
94+
environment.get(AZURE_PR_NUMBER));
8995
}
9096

9197
private String buildGitBranch() {

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitBucketInfo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class BitBucketInfo implements CIProviderInfo {
2727
public static final String BITBUCKET_GIT_BRANCH = "BITBUCKET_BRANCH";
2828
public static final String BITBUCKET_GIT_TAG = "BITBUCKET_TAG";
2929
public static final String BITBUCKET_PR_DESTINATION_BRANCH = "BITBUCKET_PR_DESTINATION_BRANCH";
30+
public static final String BITBUCKET_PR_NUMBER = "BITBUCKET_PR_ID";
3031

3132
private final CiEnvironment environment;
3233

@@ -76,7 +77,10 @@ public CIInfo buildCIInfo() {
7677
@Override
7778
public PullRequestInfo buildPullRequestInfo() {
7879
return new PullRequestInfo(
79-
normalizeBranch(environment.get(BITBUCKET_PR_DESTINATION_BRANCH)), null, null);
80+
normalizeBranch(environment.get(BITBUCKET_PR_DESTINATION_BRANCH)),
81+
null,
82+
null,
83+
environment.get(BITBUCKET_PR_NUMBER));
8084
}
8185

8286
private String buildPipelineUrl(final String repo, final String number) {

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BitriseInfo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class BitriseInfo implements CIProviderInfo {
3333
public static final String BITRISE_GIT_COMMITER_NAME = "GIT_CLONE_COMMIT_COMMITER_NAME";
3434
public static final String BITRISE_GIT_COMMITER_EMAIL = "GIT_CLONE_COMMIT_COMMITER_EMAIL";
3535
public static final String BITRISE_GIT_BRANCH_DEST = "BITRISEIO_GIT_BRANCH_DEST";
36+
public static final String BITRISE_PR_NUMBER = "BITRISE_PULL_REQUEST";
3637

3738
private final CiEnvironment environment;
3839

@@ -73,7 +74,10 @@ public CIInfo buildCIInfo() {
7374
@Override
7475
public PullRequestInfo buildPullRequestInfo() {
7576
return new PullRequestInfo(
76-
normalizeBranch(environment.get(BITRISE_GIT_BRANCH_DEST)), null, null);
77+
normalizeBranch(environment.get(BITRISE_GIT_BRANCH_DEST)),
78+
null,
79+
null,
80+
environment.get(BITRISE_PR_NUMBER));
7781
}
7882

7983
private String buildGitCommit() {

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuddyInfo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class BuddyInfo implements CIProviderInfo {
2828
public static final String BUDDY_GIT_COMMIT_AUTHOR = "BUDDY_EXECUTION_REVISION_COMMITTER_NAME";
2929
public static final String BUDDY_GIT_COMMIT_EMAIL = "BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL";
3030
public static final String BUDDY_RUN_PR_BASE_BRANCH = "BUDDY_RUN_PR_BASE_BRANCH";
31+
public static final String BUDDY_RUN_PR_NUMBER = "BUDDY_RUN_PR_NO";
3132

3233
private final CiEnvironment environment;
3334

@@ -64,7 +65,10 @@ public CIInfo buildCIInfo() {
6465
@Override
6566
public PullRequestInfo buildPullRequestInfo() {
6667
return new PullRequestInfo(
67-
normalizeBranch(environment.get(BUDDY_RUN_PR_BASE_BRANCH)), null, null);
68+
normalizeBranch(environment.get(BUDDY_RUN_PR_BASE_BRANCH)),
69+
null,
70+
null,
71+
environment.get(BUDDY_RUN_PR_NUMBER));
6872
}
6973

7074
private String getPipelineId(String pipelineNumber) {

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/BuildkiteInfo.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class BuildkiteInfo implements CIProviderInfo {
3737
public static final String BUILDKITE_GIT_AUTHOR_EMAIL = "BUILDKITE_BUILD_AUTHOR_EMAIL";
3838
public static final String BUILDKITE_AGENT_ID = "BUILDKITE_AGENT_ID";
3939
private static final String BUILDKITE_CI_NODE_LABEL_PREFIX = "BUILDKITE_AGENT_META_DATA_";
40-
private static final String BUILDKITE_PULL_REQUEST = "BUILDKITE_PULL_REQUEST";
40+
private static final String BUILDKITE_PULL_REQUEST_NUMBER = "BUILDKITE_PULL_REQUEST";
4141
private static final String BUILDKITE_PULL_REQUEST_BASE_BRANCH =
4242
"BUILDKITE_PULL_REQUEST_BASE_BRANCH";
4343

@@ -83,13 +83,16 @@ public CIInfo buildCIInfo() {
8383
public PullRequestInfo buildPullRequestInfo() {
8484
if (isPullRequest()) {
8585
return new PullRequestInfo(
86-
normalizeBranch(environment.get(BUILDKITE_PULL_REQUEST_BASE_BRANCH)), null, null);
86+
normalizeBranch(environment.get(BUILDKITE_PULL_REQUEST_BASE_BRANCH)),
87+
null,
88+
null,
89+
environment.get(BUILDKITE_PULL_REQUEST_NUMBER));
8790
}
8891
return PullRequestInfo.EMPTY;
8992
}
9093

9194
private boolean isPullRequest() {
92-
String pullRequest = environment.get(BUILDKITE_PULL_REQUEST);
95+
String pullRequest = environment.get(BUILDKITE_PULL_REQUEST_NUMBER);
9396
return pullRequest != null && !"false".equals(pullRequest);
9497
}
9598

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CITagsProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public Map<String, String> getCiTags(CIInfo ciInfo, PullRequestInfo pullRequestI
4242
.withPullRequestBaseBranch(pullRequestInfo)
4343
.withPullRequestBaseBranchSha(pullRequestInfo)
4444
.withGitCommitHeadSha(pullRequestInfo)
45+
.withPullRequestNumber(pullRequestInfo)
4546
.withGitRepositoryUrl(gitInfo)
4647
.withGitCommit(gitInfo)
4748
.withGitBranch(gitInfo)
@@ -135,6 +136,10 @@ public CITagsBuilder withGitCommitHeadSha(final PullRequestInfo pullRequestInfo)
135136
return putTagValue(Tags.GIT_COMMIT_HEAD_SHA, pullRequestInfo.getGitCommitHeadSha());
136137
}
137138

139+
public CITagsBuilder withPullRequestNumber(final PullRequestInfo pullRequestInfo) {
140+
return putTagValue(Tags.PULL_REQUEST_NUMBER, pullRequestInfo.getPullRequestNumber());
141+
}
142+
138143
public CITagsBuilder withGitRepositoryUrl(final GitInfo gitInfo) {
139144
return putTagValue(Tags.GIT_REPOSITORY_URL, gitInfo.getRepositoryURL());
140145
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CircleCIInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class CircleCIInfo implements CIProviderInfo {
2626
public static final String CIRCLECI_GIT_BRANCH = "CIRCLE_BRANCH";
2727
public static final String CIRCLECI_GIT_TAG = "CIRCLE_TAG";
2828
public static final String CIRCLECI_JOB_NAME = "CIRCLE_JOB";
29+
public static final String CIRCLECI_PR_NUMBER = "CIRCLE_PR_NUMBER";
2930

3031
private final CiEnvironment environment;
3132

@@ -60,7 +61,7 @@ public CIInfo buildCIInfo() {
6061
@Nonnull
6162
@Override
6263
public PullRequestInfo buildPullRequestInfo() {
63-
return PullRequestInfo.EMPTY;
64+
return new PullRequestInfo(null, null, null, environment.get(CIRCLECI_PR_NUMBER));
6465
}
6566

6667
private String buildPipelineUrl(final String pipelineId) {

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/ci/CodefreshInfo.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class CodefreshInfo implements CIProviderInfo {
2323
private static final String CF_REVISION = "CF_REVISION";
2424
private static final String CF_COMMIT_MESSAGE = "CF_COMMIT_MESSAGE";
2525
private static final String CF_COMMIT_AUTHOR = "CF_COMMIT_AUTHOR";
26+
private static final String CF_PULL_REQUEST_NUMBER = "CF_PULL_REQUEST_NUMBER";
27+
private static final String CF_PULL_REQUEST_TARGET_BRANCH = "CF_PULL_REQUEST_TARGET";
2628

2729
private final CiEnvironment environment;
2830

@@ -46,7 +48,11 @@ public GitInfo buildCIGitInfo() {
4648
@Nonnull
4749
@Override
4850
public PullRequestInfo buildPullRequestInfo() {
49-
return PullRequestInfo.EMPTY;
51+
return new PullRequestInfo(
52+
normalizeBranch(environment.get(CF_PULL_REQUEST_TARGET_BRANCH)),
53+
null,
54+
null,
55+
environment.get(CF_PULL_REQUEST_NUMBER));
5056
}
5157

5258
private String buildGitBranch() {

0 commit comments

Comments
 (0)