-
Notifications
You must be signed in to change notification settings - Fork 344
Expand file tree
/
Copy pathPullRequestInfo.java
More file actions
127 lines (111 loc) · 3.47 KB
/
Copy pathPullRequestInfo.java
File metadata and controls
127 lines (111 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package datadog.trace.civisibility.ci;
import datadog.config.util.Strings;
import datadog.trace.api.git.CommitInfo;
import java.util.Objects;
import javax.annotation.Nonnull;
public class PullRequestInfo {
public static final PullRequestInfo EMPTY =
new PullRequestInfo(null, null, null, CommitInfo.NOOP, null);
private final String baseBranch;
private final String baseBranchSha;
private final String baseBranchHeadSha;
@Nonnull private final CommitInfo headCommit;
private final String pullRequestNumber;
public PullRequestInfo(
String baseBranch,
String baseBranchSha,
String baseBranchHeadSha,
@Nonnull CommitInfo headCommit,
String pullRequestNumber) {
this.baseBranch = baseBranch;
this.baseBranchSha = baseBranchSha;
this.baseBranchHeadSha = baseBranchHeadSha;
this.headCommit = headCommit;
this.pullRequestNumber = pullRequestNumber;
}
public String getBaseBranch() {
return baseBranch;
}
public String getBaseBranchSha() {
return baseBranchSha;
}
public String getBaseBranchHeadSha() {
return baseBranchHeadSha;
}
@Nonnull
public CommitInfo getHeadCommit() {
return headCommit;
}
public String getPullRequestNumber() {
return pullRequestNumber;
}
public boolean isEmpty() {
return Strings.isBlank(baseBranch)
&& Strings.isBlank(baseBranchSha)
&& Strings.isBlank(baseBranchHeadSha)
&& headCommit.isEmpty()
&& Strings.isBlank(pullRequestNumber);
}
public boolean isComplete() {
return Strings.isNotBlank(baseBranch)
&& Strings.isNotBlank(baseBranchSha)
&& Strings.isNotBlank(baseBranchHeadSha)
&& headCommit.isComplete()
&& Strings.isNotBlank(pullRequestNumber);
}
/**
* Combine infos by completing the empty information fields in {@code first} with {@code second}'s
*
* @param first Base PR info
* @param second Fallback PR info
* @return Combined PR info
*/
public static PullRequestInfo coalesce(
final PullRequestInfo first, final PullRequestInfo second) {
return new PullRequestInfo(
Strings.coalesce(first.baseBranch, second.baseBranch),
Strings.coalesce(first.baseBranchSha, second.baseBranchSha),
Strings.coalesce(first.baseBranchHeadSha, second.baseBranchHeadSha),
CommitInfo.coalesce(first.headCommit, second.headCommit),
Strings.coalesce(first.pullRequestNumber, second.pullRequestNumber));
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PullRequestInfo that = (PullRequestInfo) o;
return Objects.equals(baseBranch, that.baseBranch)
&& Objects.equals(baseBranchSha, that.baseBranchSha)
&& Objects.equals(baseBranchHeadSha, that.baseBranchHeadSha)
&& Objects.equals(headCommit, that.headCommit)
&& Objects.equals(pullRequestNumber, that.pullRequestNumber);
}
@Override
public int hashCode() {
return Objects.hash(baseBranch, baseBranchSha, headCommit, pullRequestNumber);
}
@Override
public String toString() {
return "PR{"
+ "baseBranch='"
+ baseBranch
+ '\''
+ ", baseSHA='"
+ baseBranchSha
+ '\''
+ ", baseHeadSHA='"
+ baseBranchHeadSha
+ '\''
+ ", headCommit='"
+ headCommit
+ '\''
+ ", prNumber='"
+ pullRequestNumber
+ '\''
+ '}';
}
}