Move change formatting methods into DefaultChangeReportFormatter
This will allow custom implementations to override the URL while maintaining the rest of the layout. Also move ChangeUtil#cropSubject to its only caller in DefaultChangeReportFormatter. Change-Id: Ib09b706399b1029328c4207daeb545cf62a9d1d0
This commit is contained in:
@@ -37,17 +37,9 @@ public class ChangeUtil {
|
|||||||
private static final Random UUID_RANDOM = new SecureRandom();
|
private static final Random UUID_RANDOM = new SecureRandom();
|
||||||
private static final BaseEncoding UUID_ENCODING = BaseEncoding.base16().lowerCase();
|
private static final BaseEncoding UUID_ENCODING = BaseEncoding.base16().lowerCase();
|
||||||
|
|
||||||
private static final int SUBJECT_MAX_LENGTH = 80;
|
|
||||||
private static final String SUBJECT_CROP_APPENDIX = "...";
|
|
||||||
private static final int SUBJECT_CROP_RANGE = 10;
|
|
||||||
|
|
||||||
public static final Ordering<PatchSet> PS_ID_ORDER =
|
public static final Ordering<PatchSet> PS_ID_ORDER =
|
||||||
Ordering.from(comparingInt(PatchSet::getPatchSetId));
|
Ordering.from(comparingInt(PatchSet::getPatchSetId));
|
||||||
|
|
||||||
public static String formatChangeUrl(String canonicalWebUrl, Change change) {
|
|
||||||
return canonicalWebUrl + "c/" + change.getProject().get() + "/+/" + change.getChangeId();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return a new unique identifier for change message entities. */
|
/** @return a new unique identifier for change message entities. */
|
||||||
public static String messageUuid() {
|
public static String messageUuid() {
|
||||||
byte[] buf = new byte[8];
|
byte[] buf = new byte[8];
|
||||||
@@ -123,21 +115,6 @@ public class ChangeUtil {
|
|||||||
id);
|
id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String cropSubject(String subject) {
|
|
||||||
if (subject.length() > SUBJECT_MAX_LENGTH) {
|
|
||||||
int maxLength = SUBJECT_MAX_LENGTH - SUBJECT_CROP_APPENDIX.length();
|
|
||||||
for (int cropPosition = maxLength;
|
|
||||||
cropPosition > maxLength - SUBJECT_CROP_RANGE;
|
|
||||||
cropPosition--) {
|
|
||||||
if (Character.isWhitespace(subject.charAt(cropPosition - 1))) {
|
|
||||||
return subject.substring(0, cropPosition) + SUBJECT_CROP_APPENDIX;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return subject.substring(0, maxLength) + SUBJECT_CROP_APPENDIX;
|
|
||||||
}
|
|
||||||
return subject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String status(Change c) {
|
public static String status(Change c) {
|
||||||
return c != null ? c.getStatus().name().toLowerCase() : "deleted";
|
return c != null ? c.getStatus().name().toLowerCase() : "deleted";
|
||||||
}
|
}
|
||||||
|
@@ -14,12 +14,16 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.git;
|
package com.google.gerrit.server.git;
|
||||||
|
|
||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/** Print a change description for use in git command-line progress. */
|
/** Print a change description for use in git command-line progress. */
|
||||||
public class DefaultChangeReportFormatter implements ChangeReportFormatter {
|
public class DefaultChangeReportFormatter implements ChangeReportFormatter {
|
||||||
|
private static final int SUBJECT_MAX_LENGTH = 80;
|
||||||
|
private static final String SUBJECT_CROP_APPENDIX = "...";
|
||||||
|
private static final int SUBJECT_CROP_RANGE = 10;
|
||||||
|
|
||||||
private final String canonicalWebUrl;
|
private final String canonicalWebUrl;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -37,19 +41,37 @@ public class DefaultChangeReportFormatter implements ChangeReportFormatter {
|
|||||||
return formatChangeUrl(canonicalWebUrl, input);
|
return formatChangeUrl(canonicalWebUrl, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static String formatChangeUrl(String canonicalWebUrl, Change change) {
|
||||||
public String changeClosed(ChangeReportFormatter.Input input) {
|
return canonicalWebUrl + "c/" + change.getProject().get() + "/+/" + change.getChangeId();
|
||||||
return String.format(
|
|
||||||
"change %s closed", ChangeUtil.formatChangeUrl(canonicalWebUrl, input.change()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatChangeUrl(String url, Input input) {
|
@Override
|
||||||
|
public String changeClosed(ChangeReportFormatter.Input input) {
|
||||||
|
return String.format("change %s closed", formatChangeUrl(canonicalWebUrl, input.change()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String cropSubject(String subject) {
|
||||||
|
if (subject.length() > SUBJECT_MAX_LENGTH) {
|
||||||
|
int maxLength = SUBJECT_MAX_LENGTH - SUBJECT_CROP_APPENDIX.length();
|
||||||
|
for (int cropPosition = maxLength;
|
||||||
|
cropPosition > maxLength - SUBJECT_CROP_RANGE;
|
||||||
|
cropPosition--) {
|
||||||
|
if (Character.isWhitespace(subject.charAt(cropPosition - 1))) {
|
||||||
|
return subject.substring(0, cropPosition) + SUBJECT_CROP_APPENDIX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return subject.substring(0, maxLength) + SUBJECT_CROP_APPENDIX;
|
||||||
|
}
|
||||||
|
return subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String formatChangeUrl(String url, Input input) {
|
||||||
StringBuilder m =
|
StringBuilder m =
|
||||||
new StringBuilder()
|
new StringBuilder()
|
||||||
.append(" ")
|
.append(" ")
|
||||||
.append(ChangeUtil.formatChangeUrl(url, input.change()))
|
.append(formatChangeUrl(url, input.change()))
|
||||||
.append(" ")
|
.append(" ")
|
||||||
.append(ChangeUtil.cropSubject(input.subject()));
|
.append(cropSubject(input.subject()));
|
||||||
if (input.isEdit()) {
|
if (input.isEdit()) {
|
||||||
m.append(" [EDIT]");
|
m.append(" [EDIT]");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user