Skip to content

Commit

Permalink
Fix reading/writing voteSameTopic twice
Browse files Browse the repository at this point in the history
Use string builder instead of replace method to build a string pattern
  • Loading branch information
mobangjack committed Jun 6, 2021
1 parent c689bfc commit a5bbd63
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,6 @@ public void setValues(JSONObject formData) {
useRestApi = false;
}

voteSameTopic = formData.optBoolean("voteSameTopic", false);

replicationConfig = ReplicationConfig.createReplicationConfigFromJSON(formData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public GerritNotifier(IGerritHudsonTriggerConfig config, GerritCmdRunner cmdRunn
private void notifySameTopic(ChangeBasedEvent event, String command) {
Topic topic = event.getChange().getTopicObject();
if (topic != null) {
String pattern = "CHANGE,PATCHSET".replace("CHANGE", event.getChange().getNumber()).replace("PATCHSET",
event.getPatchSet().getNumber());
String pattern = new StringBuilder(event.getChange().getNumber()).append(',')
.append(event.getPatchSet().getNumber()).toString();

if (!command.contains(pattern)) {
logger.error("command {} has no pattern {}", command, pattern);
return;
Expand All @@ -102,8 +103,8 @@ private void notifySameTopic(ChangeBasedEvent event, String command) {
continue;
}
PatchSet patchSet = entry.getValue();
String substitution = "CHANGE,PATCHSET".replace("CHANGE", change.getNumber())
.replace("PATCHSET", patchSet.getNumber());
String substitution = new StringBuilder(change.getNumber()).append(',').append(patchSet.getNumber())
.toString();
String command2 = command.replace(pattern, substitution);
logger.trace("notifySameTopic: {} {} {}", topic, change, command2);
server.getCmdRunner().sendCommand(command2);
Expand Down

0 comments on commit a5bbd63

Please sign in to comment.