Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/maven/io.jenkins.tools.bom-bom-…
Browse files Browse the repository at this point in the history
…2.263.x-21
  • Loading branch information
bitwiseman authored Jan 26, 2021
2 parents 71305c6 + 674b6d7 commit e49c3df
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@
* @since 2.2.0
*/
public class BranchDiscoveryTrait extends SCMSourceTrait {
/**
* None strategy.
*/
public static final int NONE = 0;
/**
* Exclude branches that are also filed as PRs.
*/
public static final int EXCLUDE_PRS = 1;
/**
* Only branches that are also filed as PRs.
*/
public static final int ONLY_PRS = 2;
/**
* All branches.
*/
public static final int ALL_BRANCHES = 3;

/**
* The strategy encoded as a bit-field.
*/
Expand All @@ -74,7 +91,7 @@ public BranchDiscoveryTrait(int strategyId) {
* @param buildBranchWithPr build branches that are also PRs.
*/
public BranchDiscoveryTrait(boolean buildBranch, boolean buildBranchWithPr) {
this.strategyId = (buildBranch ? 1 : 0) + (buildBranchWithPr ? 2 : 0);
this.strategyId = (buildBranch ? EXCLUDE_PRS : NONE) + (buildBranchWithPr ? ONLY_PRS : NONE);
}

/**
Expand All @@ -93,7 +110,7 @@ public int getStrategyId() {
*/
@Restricted(NoExternalUse.class)
public boolean isBuildBranch() {
return (strategyId & 1) != 0;
return (strategyId & EXCLUDE_PRS) != NONE;
}

/**
Expand All @@ -103,7 +120,7 @@ public boolean isBuildBranch() {
*/
@Restricted(NoExternalUse.class)
public boolean isBuildBranchesWithPR() {
return (strategyId & 2) != 0;
return (strategyId & ONLY_PRS) != NONE;
}

/**
Expand All @@ -115,15 +132,15 @@ protected void decorateContext(SCMSourceContext<?, ?> context) {
ctx.wantBranches(true);
ctx.withAuthority(new BranchSCMHeadAuthority());
switch (strategyId) {
case 1:
case BranchDiscoveryTrait.EXCLUDE_PRS:
ctx.wantOriginPRs(true);
ctx.withFilter(new ExcludeOriginPRBranchesSCMHeadFilter());
break;
case 2:
case BranchDiscoveryTrait.ONLY_PRS:
ctx.wantOriginPRs(true);
ctx.withFilter(new OnlyOriginPRBranchesSCMHeadFilter());
break;
case 3:
case BranchDiscoveryTrait.ALL_BRANCHES:
default:
// 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
// to filter
Expand Down Expand Up @@ -181,9 +198,9 @@ public Class<? extends SCMSource> getSourceClass() {
@SuppressWarnings("unused") // stapler
public ListBoxModel doFillStrategyIdItems() {
ListBoxModel result = new ListBoxModel();
result.add(Messages.BranchDiscoveryTrait_excludePRs(), "1");
result.add(Messages.BranchDiscoveryTrait_onlyPRs(), "2");
result.add(Messages.BranchDiscoveryTrait_allBranches(), "3");
result.add(Messages.BranchDiscoveryTrait_excludePRs(), String.valueOf(EXCLUDE_PRS));
result.add(Messages.BranchDiscoveryTrait_onlyPRs(), String.valueOf(ONLY_PRS));
result.add(Messages.BranchDiscoveryTrait_allBranches(), String.valueOf(ALL_BRANCHES));
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@
* @since 2.2.0
*/
public class ForkPullRequestDiscoveryTrait extends SCMSourceTrait {
/**
* None strategy.
*/
public static final int NONE = 0;
/**
* Merging the pull request with the current target branch revision.
*/
public static final int MERGE = 1;
/**
* The current pull request revision.
*/
public static final int HEAD = 2;
/**
* Both the current pull request revision and the pull request merged with the current target branch revision.
*/
public static final int HEAD_AND_MERGE = 3;
/**
* The strategy encoded as a bit-field.
*/
Expand Down Expand Up @@ -87,8 +103,8 @@ public ForkPullRequestDiscoveryTrait(int strategyId,
*/
public ForkPullRequestDiscoveryTrait(@NonNull Set<ChangeRequestCheckoutStrategy> strategies,
@NonNull SCMHeadAuthority<? super GitHubSCMSourceRequest, ? extends ChangeRequestSCMHead2, ? extends SCMRevision> trust) {
this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? 1 : 0)
+ (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? 2 : 0), trust);
this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? MERGE : NONE)
+ (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? HEAD : NONE), trust);
}

/**
Expand All @@ -108,11 +124,11 @@ public int getStrategyId() {
@NonNull
public Set<ChangeRequestCheckoutStrategy> getStrategies() {
switch (strategyId) {
case 1:
case ForkPullRequestDiscoveryTrait.MERGE:
return EnumSet.of(ChangeRequestCheckoutStrategy.MERGE);
case 2:
case ForkPullRequestDiscoveryTrait.HEAD:
return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD);
case 3:
case ForkPullRequestDiscoveryTrait.HEAD_AND_MERGE:
return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD, ChangeRequestCheckoutStrategy.MERGE);
default:
return EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
Expand Down Expand Up @@ -190,9 +206,9 @@ public Class<? extends SCMSource> getSourceClass() {
@SuppressWarnings("unused") // stapler
public ListBoxModel doFillStrategyIdItems() {
ListBoxModel result = new ListBoxModel();
result.add(Messages.ForkPullRequestDiscoveryTrait_mergeOnly(), "1");
result.add(Messages.ForkPullRequestDiscoveryTrait_headOnly(), "2");
result.add(Messages.ForkPullRequestDiscoveryTrait_headAndMerge(), "3");
result.add(Messages.ForkPullRequestDiscoveryTrait_mergeOnly(), String.valueOf(MERGE));
result.add(Messages.ForkPullRequestDiscoveryTrait_headOnly(), String.valueOf(HEAD));
result.add(Messages.ForkPullRequestDiscoveryTrait_headAndMerge(), String.valueOf(HEAD_AND_MERGE));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@
* @since 2.2.0
*/
public class OriginPullRequestDiscoveryTrait extends SCMSourceTrait {
/**
* None strategy.
*/
public static final int NONE = 0;
/**
* Merging the pull request with the current target branch revision.
*/
public static final int MERGE = 1;
/**
* The current pull request revision.
*/
public static final int HEAD = 2;
/**
* Both the current pull request revision and the pull request merged with the current target branch revision.
*/
public static final int HEAD_AND_MERGE = 3;

/**
* The strategy encoded as a bit-field.
*/
Expand All @@ -75,8 +92,8 @@ public OriginPullRequestDiscoveryTrait(int strategyId) {
* @param strategies the {@link ChangeRequestCheckoutStrategy} instances.
*/
public OriginPullRequestDiscoveryTrait(Set<ChangeRequestCheckoutStrategy> strategies) {
this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? 1 : 0)
+ (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? 2 : 0));
this((strategies.contains(ChangeRequestCheckoutStrategy.MERGE) ? MERGE : NONE)
+ (strategies.contains(ChangeRequestCheckoutStrategy.HEAD) ? HEAD : NONE));
}

/**
Expand All @@ -96,11 +113,11 @@ public int getStrategyId() {
@NonNull
public Set<ChangeRequestCheckoutStrategy> getStrategies() {
switch (strategyId) {
case 1:
case OriginPullRequestDiscoveryTrait.MERGE:
return EnumSet.of(ChangeRequestCheckoutStrategy.MERGE);
case 2:
case OriginPullRequestDiscoveryTrait.HEAD:
return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD);
case 3:
case OriginPullRequestDiscoveryTrait.HEAD_AND_MERGE:
return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD, ChangeRequestCheckoutStrategy.MERGE);
default:
return EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
Expand Down Expand Up @@ -168,9 +185,9 @@ public Class<? extends SCMSource> getSourceClass() {
@SuppressWarnings("unused") // stapler
public ListBoxModel doFillStrategyIdItems() {
ListBoxModel result = new ListBoxModel();
result.add(Messages.ForkPullRequestDiscoveryTrait_mergeOnly(), "1");
result.add(Messages.ForkPullRequestDiscoveryTrait_headOnly(), "2");
result.add(Messages.ForkPullRequestDiscoveryTrait_headAndMerge(), "3");
result.add(Messages.ForkPullRequestDiscoveryTrait_mergeOnly(), String.valueOf(MERGE));
result.add(Messages.ForkPullRequestDiscoveryTrait_headOnly(), String.valueOf(HEAD));
result.add(Messages.ForkPullRequestDiscoveryTrait_headAndMerge(), String.valueOf(HEAD_AND_MERGE));
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ public void given__instance__when__setTraits_empty__then__traitsEmpty() {
@Test
public void given__instance__when__setTraits__then__traitsSet() {
GitHubSCMNavigator instance = new GitHubSCMNavigator("test");
instance.setTraits(Arrays.asList(new BranchDiscoveryTrait(1),
instance.setTraits(Arrays.asList(new BranchDiscoveryTrait(BranchDiscoveryTrait.EXCLUDE_PRS),
new SSHCheckoutTrait(null)));
assertThat(instance.getTraits(),
containsInAnyOrder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public void given__legacyCode__when__setBuildOriginBranch__then__traitsMaintaine
@Test
public void given__instance__when__setTraits__then__traitsSet() {
GitHubSCMSource instance = new GitHubSCMSource("testing", "test-repo");
instance.setTraits(Arrays.asList(new BranchDiscoveryTrait(1),
instance.setTraits(Arrays.asList(new BranchDiscoveryTrait(BranchDiscoveryTrait.EXCLUDE_PRS),
new SSHCheckoutTrait("value")));
assertThat(instance.getTraits(),
containsInAnyOrder(
Expand Down

0 comments on commit e49c3df

Please sign in to comment.