Skip to content

Commit

Permalink
Another take on displaying titles
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Aug 28, 2024
1 parent 9de361d commit 315ce8d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 36 deletions.
25 changes: 0 additions & 25 deletions src/main/java/jenkins/branch/ItemColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,6 @@ public boolean isOrphaned(Object item) {
return false;
}

/**
* Gets the title of a job.
*
* @param job the job.
* @return the unescaped title for displaying in a table column.
*/
@SuppressWarnings("unused") // used via Jelly EL binding
public String getTitle(Object job) {
// Jelly will take care of quote and ampersand escaping for us
if (job instanceof Actionable) {
Actionable actionable = (Actionable) job;
ObjectMetadataAction action = actionable.getAction(ObjectMetadataAction.class);
if (action != null) {
String displayName = action.getObjectDisplayName();
if (StringUtils.isBlank(displayName) || displayName.equals(actionable.getDisplayName())) {
// if the display name is the same, then the description is more useful
String description = action.getObjectDescription();
return description != null ? description : displayName;
}
return displayName;
}
}
return null;
}

/**
* Our extension.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/jenkins/branch/MultiBranchProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -2139,7 +2139,7 @@ private String getProjectDisplayName(@NonNull P project, @NonNull String rawName

// Default to displaying the project's display name if a trait hasn't been provided
if (naming == null) {
naming = MultiBranchProjectDisplayNamingStrategy.OBJECT_DISPLAY_NAME;
naming = MultiBranchProjectDisplayNamingStrategy.RAW_AND_OBJECT_DISPLAY_NAME;
}

final ObjectMetadataAction action = naming.needsObjectDisplayName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ public String generateName(@NonNull final String rawName, final String displayNa
return rawName;
}

return format("%s - %s", rawName, displayName);
// The raw name provided here in the context of pull requests is the pull request ID
// We tidy up the ID so that they display consistently between SCMs
String cleanedUpBranchName = rawName;
if (cleanedUpBranchName.startsWith("MR-") || cleanedUpBranchName.startsWith("PR-")) {

Check warning on line 66 in src/main/java/jenkins/branch/MultiBranchProjectDisplayNamingStrategy.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 66 is only partially covered, 2 branches are missing
cleanedUpBranchName = "#" + cleanedUpBranchName.substring(3);

Check warning on line 67 in src/main/java/jenkins/branch/MultiBranchProjectDisplayNamingStrategy.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 67 is not covered by tests
}

return format("%s (%s)", displayName, cleanedUpBranchName);
}
},
;
Expand Down
10 changes: 1 addition & 9 deletions src/main/resources/jenkins/branch/ItemColumn/column.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@ THE SOFTWARE.
<d:taglib uri="local">
<d:tag name="link">
<a href="${jobBaseUrl}${job.shortUrl}" class='model-link jenkins-table__link'>
<j:choose>
<j:when test="${it.getTitle(job) == null or h.getRelativeDisplayNameFrom(job, itemGroup).equals(it.getTitle(job))}">
<l:breakable value="${h.getRelativeDisplayNameFrom(job, itemGroup)}"/>
</j:when>
<j:otherwise>
${it.getTitle(job)}
<span style="opacity: 0.75; margin-left: 0.625rem; white-space: nowrap;"><l:breakable value="${h.getRelativeDisplayNameFrom(job, itemGroup)}"/></span>
</j:otherwise>
</j:choose>
<l:breakable value="${h.getRelativeDisplayNameFrom(job, itemGroup)}"/>
</a>
</d:tag>
</d:taglib>
Expand Down

0 comments on commit 315ce8d

Please sign in to comment.