Skip to content

Commit c3c2f14

Browse files
committed
Check for an entire link rather than just a jira key
1 parent 0cd79a4 commit c3c2f14

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/main/java/org/hibernate/infra/bot/EditPullRequestBodyAddIssueLinks.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,20 @@ else if ( issueKeys.size() > repositoryConfig.jira.getIssueLinksLimit() ) {
108108

109109
private String constructLinksSection(Set<String> issueKeys, String body) {
110110
final String lowerCaseBody = body.toLowerCase( Locale.ROOT );
111-
final List<String> keys = new ArrayList<>( issueKeys.size() );
111+
final List<String> links = new ArrayList<>( issueKeys.size() );
112112
for ( String key : issueKeys ) {
113113
// Add links for issue keys that are not already found in the original PR body
114-
if ( !lowerCaseBody.contains( key.toLowerCase( Locale.ROOT ) ) ) {
115-
keys.add( key );
114+
String link = String.format( Locale.ROOT, LINK_TEMPLATE, key );
115+
if ( !lowerCaseBody.contains( link.toLowerCase( Locale.ROOT ) ) ) {
116+
links.add( link );
116117
}
117118
}
118119

119-
if ( keys.isEmpty() ) {
120+
if ( links.isEmpty() ) {
120121
return null;
121122
}
122123

123-
// Try to pre-size the StringBuilder with the correct capacity
124-
final int linkSize = LINK_TEMPLATE.length() + keys.get( 0 ).length() + 1;
125-
final StringBuilder sb = new StringBuilder( linkSize * keys.size() );
126-
for ( final String key : keys ) {
127-
sb.append( String.format( LINK_TEMPLATE, key ) ).append( '\n' );
128-
}
129-
return START_MARKER + "\n" + EDITOR_WARNING + sb + END_MARKER;
124+
return String.format( Locale.ROOT, "%s\n%s%s\n%s", START_MARKER, EDITOR_WARNING, String.join( "\n", links ), END_MARKER );
130125
}
131126

132127
private static String removeLinksSection(String originalBody, int startIndex, int endIndex) {

0 commit comments

Comments
 (0)