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.387.x-2163.v2d916d90c305
  • Loading branch information
jglick committed Jun 26, 2023
2 parents 42a6ac0 + 5d691a8 commit 241758d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.66</version>
<version>4.68</version>
<relativePath/>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package jenkins.branch;

import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Objects;
import jenkins.scm.api.metadata.ObjectMetadataAction;
import org.jvnet.localizer.Localizable;

Expand All @@ -42,7 +43,7 @@ public enum MultiBranchProjectDisplayNamingStrategy {
OBJECT_DISPLAY_NAME(true, Messages._MultiBranchProjectDisplayNamingTrait_DisplayName()) {
@Override
public String generateName(@NonNull final String rawName, final String displayName) {
return displayName;
return isBlank(displayName) ? rawName : displayName;
}
},
/**
Expand All @@ -51,7 +52,15 @@ public String generateName(@NonNull final String rawName, final String displayNa
RAW_AND_OBJECT_DISPLAY_NAME(true, Messages._MultiBranchProjectDisplayNamingTrait_RawAndDisplayName()) {
@Override
public String generateName(@NonNull final String rawName, final String displayName) {
return isBlank(displayName) ? rawName : format("%s: %s", rawName, displayName);
if (isBlank(displayName)) {
return rawName;
}

if (Objects.equals(rawName, displayName)) {
return rawName;
}

return format("%s - %s", rawName, displayName);
}
},
;
Expand All @@ -67,6 +76,7 @@ public String generateName(@NonNull final String rawName, final String displayNa
public boolean needsObjectDisplayName() {
return needsObjectDisplayName;
}

public String getDisplayName() {
return displayName.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jenkins/branch/RateLimitBranchProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public CauseOfBlockage canRun(Queue.Item item) {
return null;
}
for (Queue.Item i : items) {
if (i.getId() < item.getId()) {
if (i.getInQueueSince() < item.getInQueueSince()) {
LOGGER.log(Level.FINE, "{0} with queue id {1} blocked by queue id {2} was first",
new Object[]{
job.getFullName(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
<div>
The different strategies:
<ul>
<li>
<strong>Object display name:</strong>
<span>Uses the branch source plugin's display name for the PR instead of the raw name</span>
</li>
<li>
<strong>Raw and object display name:</strong>
<span>Joins the raw name and the branch source plugin's display name</span>
</li>
</ul>
The different strategies:
<ul>
<li>
<p>
<strong>Job display name with fallback to name:</strong>
<br>
Uses the branch source plugin's display name for the PR instead of the raw name
<br>
Value for configuration-as-code: <code>OBJECT_DISPLAY_NAME</code>
</p>
</li>
<li>
<p>
<strong>Name and, if available, display name:</strong>
<br>
Joins the raw name and the branch source plugin's display name
<br>
Value for configuration-as-code: <code>RAW_AND_OBJECT_DISPLAY_NAME</code>
</p>
</li>
</ul>
</div>
19 changes: 15 additions & 4 deletions src/test/java/jenkins/branch/ProjectNamingStrategyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import integration.harness.BasicDummyStepBranchProperty;
import integration.harness.BasicMultiBranchProject;
import jenkins.model.Jenkins;
import jenkins.scm.api.SCMSource;
import jenkins.scm.impl.mock.MockSCMController;
import jenkins.scm.impl.mock.MockSCMDiscoverBranches;
import jenkins.scm.impl.mock.MockSCMDiscoverChangeRequests;
import jenkins.scm.impl.mock.MockSCMSource;
import org.junit.ClassRule;
Expand Down Expand Up @@ -42,12 +42,13 @@ public void testObjectNameStrategy() throws Exception {

public void testNamingStrategy(final MultiBranchProjectDisplayNamingStrategy namingStrategy) throws Exception {
final Jenkins jenkinsInstance = r.jenkins;
final String mainBranch = "master";
final String projectName = String.format("Project_%s", namingStrategy.name());

try (final MockSCMController mockScm = MockSCMController.create()) {
mockScm.createRepository(REPO_NAME);

final Integer crNumber = mockScm.openChangeRequest(REPO_NAME, "master");
final Integer crNumber = mockScm.openChangeRequest(REPO_NAME, mainBranch);
final String crName = String.format("CR-%s", crNumber);
final String crTitle = String.format("Change request #%s", crNumber);

Expand All @@ -58,6 +59,7 @@ public void testNamingStrategy(final MultiBranchProjectDisplayNamingStrategy nam
final MockSCMSource scmSource = new MockSCMSource(
mockScm,
REPO_NAME,
new MockSCMDiscoverBranches(),
new MockSCMDiscoverChangeRequests(),
new MultiBranchProjectDisplayNamingTrait(namingStrategy)
);
Expand All @@ -67,14 +69,23 @@ public void testNamingStrategy(final MultiBranchProjectDisplayNamingStrategy nam
project.getSourcesList().add(source);
r.configRoundtrip(project);

final FreeStyleProject branchProject = jenkinsInstance.getItemByFullName(
String.format("%s/%s", projectName, mainBranch),
FreeStyleProject.class
);

final String expectedBranchProjectName = namingStrategy.generateName(mainBranch, "");
assertNotNull(branchProject, "No job was created for the main branch");
assertEquals(expectedBranchProjectName, branchProject.getDisplayName(), "The job name doesn't match the naming strategy");

final FreeStyleProject crProject = jenkinsInstance.getItemByFullName(
String.format("%s/%s", projectName, crName),
FreeStyleProject.class
);

final String expectedName = namingStrategy.generateName(crName, crTitle);
final String expectedCrProjectName = namingStrategy.generateName(crName, crTitle);
assertNotNull(crProject, "No job was created for the pull request");
assertEquals(expectedName, crProject.getDisplayName(), "The job name doesn't match the naming strategy");
assertEquals(expectedCrProjectName, crProject.getDisplayName(), "The job name doesn't match the naming strategy");
}
}
}
5 changes: 5 additions & 0 deletions src/test/java/jenkins/branch/RateLimitBranchPropertyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.Collections;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.scm.impl.mock.MockSCMController;
import jenkins.scm.impl.mock.MockSCMDiscoverBranches;
Expand All @@ -51,6 +52,7 @@
import org.junit.ClassRule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.LoggerRule;
import org.jvnet.hudson.test.TestExtension;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -84,6 +86,9 @@ public class RateLimitBranchPropertyTest {
*/
@ClassRule
public static JenkinsRule r = new JenkinsRule();

@ClassRule
public static LoggerRule loggerRule = new LoggerRule().record(RateLimitBranchProperty.class, Level.FINE);
/**
* Our logger.
*/
Expand Down

0 comments on commit 241758d

Please sign in to comment.