Skip to content

Commit e49c3df

Browse files
authored
Merge branch 'master' into dependabot/maven/io.jenkins.tools.bom-bom-2.263.x-21
2 parents 71305c6 + 674b6d7 commit e49c3df

File tree

5 files changed

+77
-27
lines changed

5 files changed

+77
-27
lines changed

src/main/java/org/jenkinsci/plugins/github_branch_source/BranchDiscoveryTrait.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@
5252
* @since 2.2.0
5353
*/
5454
public class BranchDiscoveryTrait extends SCMSourceTrait {
55+
/**
56+
* None strategy.
57+
*/
58+
public static final int NONE = 0;
59+
/**
60+
* Exclude branches that are also filed as PRs.
61+
*/
62+
public static final int EXCLUDE_PRS = 1;
63+
/**
64+
* Only branches that are also filed as PRs.
65+
*/
66+
public static final int ONLY_PRS = 2;
67+
/**
68+
* All branches.
69+
*/
70+
public static final int ALL_BRANCHES = 3;
71+
5572
/**
5673
* The strategy encoded as a bit-field.
5774
*/
@@ -74,7 +91,7 @@ public BranchDiscoveryTrait(int strategyId) {
7491
* @param buildBranchWithPr build branches that are also PRs.
7592
*/
7693
public BranchDiscoveryTrait(boolean buildBranch, boolean buildBranchWithPr) {
77-
this.strategyId = (buildBranch ? 1 : 0) + (buildBranchWithPr ? 2 : 0);
94+
this.strategyId = (buildBranch ? EXCLUDE_PRS : NONE) + (buildBranchWithPr ? ONLY_PRS : NONE);
7895
}
7996

8097
/**
@@ -93,7 +110,7 @@ public int getStrategyId() {
93110
*/
94111
@Restricted(NoExternalUse.class)
95112
public boolean isBuildBranch() {
96-
return (strategyId & 1) != 0;
113+
return (strategyId & EXCLUDE_PRS) != NONE;
97114
}
98115

99116
/**
@@ -103,7 +120,7 @@ public boolean isBuildBranch() {
103120
*/
104121
@Restricted(NoExternalUse.class)
105122
public boolean isBuildBranchesWithPR() {
106-
return (strategyId & 2) != 0;
123+
return (strategyId & ONLY_PRS) != NONE;
107124
}
108125

109126
/**
@@ -115,15 +132,15 @@ protected void decorateContext(SCMSourceContext<?, ?> context) {
115132
ctx.wantBranches(true);
116133
ctx.withAuthority(new BranchSCMHeadAuthority());
117134
switch (strategyId) {
118-
case 1:
135+
case BranchDiscoveryTrait.EXCLUDE_PRS:
119136
ctx.wantOriginPRs(true);
120137
ctx.withFilter(new ExcludeOriginPRBranchesSCMHeadFilter());
121138
break;
122-
case 2:
139+
case BranchDiscoveryTrait.ONLY_PRS:
123140
ctx.wantOriginPRs(true);
124141
ctx.withFilter(new OnlyOriginPRBranchesSCMHeadFilter());
125142
break;
126-
case 3:
143+
case BranchDiscoveryTrait.ALL_BRANCHES:
127144
default:
128145
// we don't care if it is a PR or not, we're taking them all, no need to ask for PRs and no need
129146
// to filter
@@ -181,9 +198,9 @@ public Class<? extends SCMSource> getSourceClass() {
181198
@SuppressWarnings("unused") // stapler
182199
public ListBoxModel doFillStrategyIdItems() {
183200
ListBoxModel result = new ListBoxModel();
184-
result.add(Messages.BranchDiscoveryTrait_excludePRs(), "1");
185-
result.add(Messages.BranchDiscoveryTrait_onlyPRs(), "2");
186-
result.add(Messages.BranchDiscoveryTrait_allBranches(), "3");
201+
result.add(Messages.BranchDiscoveryTrait_excludePRs(), String.valueOf(EXCLUDE_PRS));
202+
result.add(Messages.BranchDiscoveryTrait_onlyPRs(), String.valueOf(ONLY_PRS));
203+
result.add(Messages.BranchDiscoveryTrait_allBranches(), String.valueOf(ALL_BRANCHES));
187204
return result;
188205
}
189206
}

src/main/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@
5656
* @since 2.2.0
5757
*/
5858
public class ForkPullRequestDiscoveryTrait extends SCMSourceTrait {
59+
/**
60+
* None strategy.
61+
*/
62+
public static final int NONE = 0;
63+
/**
64+
* Merging the pull request with the current target branch revision.
65+
*/
66+
public static final int MERGE = 1;
67+
/**
68+
* The current pull request revision.
69+
*/
70+
public static final int HEAD = 2;
71+
/**
72+
* Both the current pull request revision and the pull request merged with the current target branch revision.
73+
*/
74+
public static final int HEAD_AND_MERGE = 3;
5975
/**
6076
* The strategy encoded as a bit-field.
6177
*/
@@ -87,8 +103,8 @@ public ForkPullRequestDiscoveryTrait(int strategyId,
87103
*/
88104
public ForkPullRequestDiscoveryTrait(@NonNull Set<ChangeRequestCheckoutStrategy> strategies,
89105
@NonNull SCMHeadAuthority<? super GitHubSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision> trust) {
90-
this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? 1 : 0)
91-
+ (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? 2 : 0), trust);
106+
this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? MERGE : NONE)
107+
+ (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? HEAD : NONE), trust);
92108
}
93109

94110
/**
@@ -108,11 +124,11 @@ public int getStrategyId() {
108124
@NonNull
109125
public Set<ChangeRequestCheckoutStrategy> getStrategies() {
110126
switch (strategyId) {
111-
case 1:
127+
case ForkPullRequestDiscoveryTrait.MERGE:
112128
return EnumSet.of(ChangeRequestCheckoutStrategy.MERGE);
113-
case 2:
129+
case ForkPullRequestDiscoveryTrait.HEAD:
114130
return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD);
115-
case 3:
131+
case ForkPullRequestDiscoveryTrait.HEAD_AND_MERGE:
116132
return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD, ChangeRequestCheckoutStrategy.MERGE);
117133
default:
118134
return EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
@@ -190,9 +206,9 @@ public Class<? extends SCMSource> getSourceClass() {
190206
@SuppressWarnings("unused") // stapler
191207
public ListBoxModel doFillStrategyIdItems() {
192208
ListBoxModel result = new ListBoxModel();
193-
result.add(Messages.ForkPullRequestDiscoveryTrait_mergeOnly(), "1");
194-
result.add(Messages.ForkPullRequestDiscoveryTrait_headOnly(), "2");
195-
result.add(Messages.ForkPullRequestDiscoveryTrait_headAndMerge(), "3");
209+
result.add(Messages.ForkPullRequestDiscoveryTrait_mergeOnly(), String.valueOf(MERGE));
210+
result.add(Messages.ForkPullRequestDiscoveryTrait_headOnly(), String.valueOf(HEAD));
211+
result.add(Messages.ForkPullRequestDiscoveryTrait_headAndMerge(), String.valueOf(HEAD_AND_MERGE));
196212
return result;
197213
}
198214

src/main/java/org/jenkinsci/plugins/github_branch_source/OriginPullRequestDiscoveryTrait.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@
5454
* @since 2.2.0
5555
*/
5656
public class OriginPullRequestDiscoveryTrait extends SCMSourceTrait {
57+
/**
58+
* None strategy.
59+
*/
60+
public static final int NONE = 0;
61+
/**
62+
* Merging the pull request with the current target branch revision.
63+
*/
64+
public static final int MERGE = 1;
65+
/**
66+
* The current pull request revision.
67+
*/
68+
public static final int HEAD = 2;
69+
/**
70+
* Both the current pull request revision and the pull request merged with the current target branch revision.
71+
*/
72+
public static final int HEAD_AND_MERGE = 3;
73+
5774
/**
5875
* The strategy encoded as a bit-field.
5976
*/
@@ -75,8 +92,8 @@ public OriginPullRequestDiscoveryTrait(int strategyId) {
7592
* @param strategies the {@link ChangeRequestCheckoutStrategy} instances.
7693
*/
7794
public OriginPullRequestDiscoveryTrait(Set<ChangeRequestCheckoutStrategy> strategies) {
78-
this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? 1 : 0)
79-
+ (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? 2 : 0));
95+
this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? MERGE : NONE)
96+
+ (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? HEAD : NONE));
8097
}
8198

8299
/**
@@ -96,11 +113,11 @@ public int getStrategyId() {
96113
@NonNull
97114
public Set<ChangeRequestCheckoutStrategy> getStrategies() {
98115
switch (strategyId) {
99-
case 1:
116+
case OriginPullRequestDiscoveryTrait.MERGE:
100117
return EnumSet.of(ChangeRequestCheckoutStrategy.MERGE);
101-
case 2:
118+
case OriginPullRequestDiscoveryTrait.HEAD:
102119
return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD);
103-
case 3:
120+
case OriginPullRequestDiscoveryTrait.HEAD_AND_MERGE:
104121
return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD, ChangeRequestCheckoutStrategy.MERGE);
105122
default:
106123
return EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
@@ -168,9 +185,9 @@ public Class<? extends SCMSource> getSourceClass() {
168185
@SuppressWarnings("unused") // stapler
169186
public ListBoxModel doFillStrategyIdItems() {
170187
ListBoxModel result = new ListBoxModel();
171-
result.add(Messages.ForkPullRequestDiscoveryTrait_mergeOnly(), "1");
172-
result.add(Messages.ForkPullRequestDiscoveryTrait_headOnly(), "2");
173-
result.add(Messages.ForkPullRequestDiscoveryTrait_headAndMerge(), "3");
188+
result.add(Messages.ForkPullRequestDiscoveryTrait_mergeOnly(), String.valueOf(MERGE));
189+
result.add(Messages.ForkPullRequestDiscoveryTrait_headOnly(), String.valueOf(HEAD));
190+
result.add(Messages.ForkPullRequestDiscoveryTrait_headAndMerge(), String.valueOf(HEAD_AND_MERGE));
174191
return result;
175192
}
176193
}

src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ public void given__instance__when__setTraits_empty__then__traitsEmpty() {
16411641
@Test
16421642
public void given__instance__when__setTraits__then__traitsSet() {
16431643
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
1644-
instance.setTraits(Arrays.asList(new BranchDiscoveryTrait(1),
1644+
instance.setTraits(Arrays.asList(new BranchDiscoveryTrait(BranchDiscoveryTrait.EXCLUDE_PRS),
16451645
new SSHCheckoutTrait(null)));
16461646
assertThat(instance.getTraits(),
16471647
containsInAnyOrder(

src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceTraitsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ public void given__legacyCode__when__setBuildOriginBranch__then__traitsMaintaine
540540
@Test
541541
public void given__instance__when__setTraits__then__traitsSet() {
542542
GitHubSCMSource instance = new GitHubSCMSource("testing", "test-repo");
543-
instance.setTraits(Arrays.asList(new BranchDiscoveryTrait(1),
543+
instance.setTraits(Arrays.asList(new BranchDiscoveryTrait(BranchDiscoveryTrait.EXCLUDE_PRS),
544544
new SSHCheckoutTrait("value")));
545545
assertThat(instance.getTraits(),
546546
containsInAnyOrder(

0 commit comments

Comments
 (0)