ChangeReportFormatter: Convert Input to use AutoValue.Builder
Change-Id: I5e1a4550701a9eaad2bbfdb9e7183a21dfda7cec Signed-off-by: David Pursehouse <dpursehouse@collab.net> Helped-by: Patrick Hiesel <hiesel@google.com>
This commit is contained in:
@@ -14,48 +14,55 @@
|
||||
|
||||
package com.google.gerrit.server.git;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
|
||||
public interface ChangeReportFormatter {
|
||||
public static class Input {
|
||||
private final Change change;
|
||||
private String subject;
|
||||
private Boolean draft;
|
||||
private Boolean edit;
|
||||
@AutoValue
|
||||
public abstract static class Input {
|
||||
public abstract Change change();
|
||||
|
||||
public Input(Change change) {
|
||||
this.change = change;
|
||||
@Nullable
|
||||
public abstract String subject();
|
||||
|
||||
@Nullable
|
||||
public abstract Boolean isDraft();
|
||||
|
||||
@Nullable
|
||||
public abstract Boolean isEdit();
|
||||
|
||||
public static Builder builder() {
|
||||
return new AutoValue_ChangeReportFormatter_Input.Builder();
|
||||
}
|
||||
|
||||
public Input setDraft(boolean draft) {
|
||||
this.draft = draft;
|
||||
return this;
|
||||
}
|
||||
@AutoValue.Builder
|
||||
public abstract static class Builder {
|
||||
public abstract Builder setChange(Change val);
|
||||
|
||||
public Input setEdit(boolean edit) {
|
||||
this.edit = edit;
|
||||
return this;
|
||||
}
|
||||
public abstract Builder setSubject(String val);
|
||||
|
||||
public Input setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
return this;
|
||||
}
|
||||
public abstract Builder setIsDraft(Boolean val);
|
||||
|
||||
public Change getChange() {
|
||||
return change;
|
||||
}
|
||||
public abstract Builder setIsEdit(Boolean val);
|
||||
|
||||
public String getSubject() {
|
||||
return subject == null ? change.getSubject() : subject;
|
||||
}
|
||||
abstract Change change();
|
||||
|
||||
public boolean isDraft() {
|
||||
return draft == null ? Change.Status.DRAFT == change.getStatus() : draft;
|
||||
}
|
||||
abstract String subject();
|
||||
|
||||
public boolean isEdit() {
|
||||
return edit == null ? false : edit;
|
||||
abstract Boolean isDraft();
|
||||
|
||||
abstract Boolean isEdit();
|
||||
|
||||
abstract Input autoBuild();
|
||||
|
||||
public Input build() {
|
||||
setChange(change());
|
||||
setSubject(subject() == null ? change().getSubject() : subject());
|
||||
setIsDraft(isDraft() == null ? Change.Status.DRAFT == change().getStatus() : isDraft());
|
||||
setIsEdit(isEdit() == null ? false : isEdit());
|
||||
return autoBuild();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -39,16 +39,16 @@ public class DefaultChangeReportFormatter implements ChangeReportFormatter {
|
||||
@Override
|
||||
public String changeClosed(ChangeReportFormatter.Input input) {
|
||||
return String.format(
|
||||
"change %s closed", ChangeUtil.formatChangeUrl(canonicalWebUrl, input.getChange()));
|
||||
"change %s closed", ChangeUtil.formatChangeUrl(canonicalWebUrl, input.change()));
|
||||
}
|
||||
|
||||
private String formatChangeUrl(String url, Input input) {
|
||||
StringBuilder m =
|
||||
new StringBuilder()
|
||||
.append(" ")
|
||||
.append(ChangeUtil.formatChangeUrl(url, input.getChange()))
|
||||
.append(ChangeUtil.formatChangeUrl(url, input.change()))
|
||||
.append(" ")
|
||||
.append(ChangeUtil.cropSubject(input.getSubject()));
|
||||
.append(ChangeUtil.cropSubject(input.subject()));
|
||||
if (input.isDraft()) {
|
||||
m.append(" [DRAFT]");
|
||||
}
|
||||
|
@@ -687,7 +687,9 @@ public class ReceiveCommits {
|
||||
addMessage("");
|
||||
addMessage("New Changes:");
|
||||
for (CreateRequest c : created) {
|
||||
addMessage(changeFormatter.newChange(new ChangeReportFormatter.Input(c.change)));
|
||||
addMessage(
|
||||
changeFormatter.newChange(
|
||||
ChangeReportFormatter.Input.builder().setChange(c.change).build()));
|
||||
}
|
||||
addMessage("");
|
||||
}
|
||||
@@ -718,10 +720,12 @@ public class ReceiveCommits {
|
||||
}
|
||||
|
||||
ChangeReportFormatter.Input input =
|
||||
new ChangeReportFormatter.Input(u.notes.getChange())
|
||||
ChangeReportFormatter.Input.builder()
|
||||
.setChange(u.notes.getChange())
|
||||
.setSubject(subject)
|
||||
.setDraft(u.replaceOp != null && u.replaceOp.getPatchSet().isDraft())
|
||||
.setEdit(edit);
|
||||
.setIsDraft(u.replaceOp != null && u.replaceOp.getPatchSet().isDraft())
|
||||
.setIsEdit(edit)
|
||||
.build();
|
||||
addMessage(changeFormatter.changeUpdated(input));
|
||||
}
|
||||
addMessage("");
|
||||
@@ -1677,7 +1681,10 @@ public class ReceiveCommits {
|
||||
private boolean requestReplace(
|
||||
ReceiveCommand cmd, boolean checkMergedInto, Change change, RevCommit newCommit) {
|
||||
if (change.getStatus().isClosed()) {
|
||||
reject(cmd, changeFormatter.changeClosed(new ChangeReportFormatter.Input(change)));
|
||||
reject(
|
||||
cmd,
|
||||
changeFormatter.changeClosed(
|
||||
ChangeReportFormatter.Input.builder().setChange(change).build()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user