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,68 +14,72 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.git;
|
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;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
|
|
||||||
public interface ChangeReportFormatter {
|
public interface ChangeReportFormatter {
|
||||||
public static class Input {
|
@AutoValue
|
||||||
private final Change change;
|
public abstract static class Input {
|
||||||
private String subject;
|
public abstract Change change();
|
||||||
private Boolean draft;
|
|
||||||
private Boolean edit;
|
|
||||||
private Boolean isPrivate;
|
|
||||||
private Boolean wip;
|
|
||||||
|
|
||||||
public Input(Change change) {
|
@Nullable
|
||||||
this.change = change;
|
public abstract String subject();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isDraft();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isEdit();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isPrivate();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public abstract Boolean isWorkInProgress();
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new AutoValue_ChangeReportFormatter_Input.Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Input setPrivate(boolean isPrivate) {
|
@AutoValue.Builder
|
||||||
this.isPrivate = isPrivate;
|
public abstract static class Builder {
|
||||||
return this;
|
public abstract Builder setChange(Change val);
|
||||||
}
|
|
||||||
|
|
||||||
public Input setDraft(boolean draft) {
|
public abstract Builder setSubject(String val);
|
||||||
this.draft = draft;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Input setEdit(boolean edit) {
|
public abstract Builder setIsDraft(Boolean val);
|
||||||
this.edit = edit;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Input setWorkInProgress(boolean wip) {
|
public abstract Builder setIsEdit(Boolean val);
|
||||||
this.wip = wip;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Input setSubject(String subject) {
|
public abstract Builder setIsPrivate(Boolean val);
|
||||||
this.subject = subject;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Change getChange() {
|
public abstract Builder setIsWorkInProgress(Boolean val);
|
||||||
return change;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSubject() {
|
abstract Change change();
|
||||||
return subject == null ? change.getSubject() : subject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDraft() {
|
abstract String subject();
|
||||||
return draft == null ? Change.Status.DRAFT == change.getStatus() : draft;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEdit() {
|
abstract Boolean isDraft();
|
||||||
return edit == null ? false : edit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPrivate() {
|
abstract Boolean isEdit();
|
||||||
return isPrivate == null ? change.isPrivate() : isPrivate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isWorkInProgress() {
|
abstract Boolean isPrivate();
|
||||||
return wip == null ? change.isWorkInProgress() : wip;
|
|
||||||
|
abstract Boolean isWorkInProgress();
|
||||||
|
|
||||||
|
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());
|
||||||
|
setIsPrivate(isPrivate() == null ? change().isPrivate() : isPrivate());
|
||||||
|
setIsWorkInProgress(
|
||||||
|
isWorkInProgress() == null ? change().isWorkInProgress() : isWorkInProgress());
|
||||||
|
return autoBuild();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,16 +39,16 @@ public class DefaultChangeReportFormatter implements ChangeReportFormatter {
|
|||||||
@Override
|
@Override
|
||||||
public String changeClosed(ChangeReportFormatter.Input input) {
|
public String changeClosed(ChangeReportFormatter.Input input) {
|
||||||
return String.format(
|
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) {
|
private String formatChangeUrl(String url, Input input) {
|
||||||
StringBuilder m =
|
StringBuilder m =
|
||||||
new StringBuilder()
|
new StringBuilder()
|
||||||
.append(" ")
|
.append(" ")
|
||||||
.append(ChangeUtil.formatChangeUrl(url, input.getChange()))
|
.append(ChangeUtil.formatChangeUrl(url, input.change()))
|
||||||
.append(" ")
|
.append(" ")
|
||||||
.append(ChangeUtil.cropSubject(input.getSubject()));
|
.append(ChangeUtil.cropSubject(input.subject()));
|
||||||
if (input.isDraft()) {
|
if (input.isDraft()) {
|
||||||
m.append(" [DRAFT]");
|
m.append(" [DRAFT]");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -605,7 +605,9 @@ class ReceiveCommits {
|
|||||||
addMessage("");
|
addMessage("");
|
||||||
addMessage("New Changes:");
|
addMessage("New Changes:");
|
||||||
for (CreateRequest c : created) {
|
for (CreateRequest c : created) {
|
||||||
addMessage(changeFormatter.newChange(new ChangeReportFormatter.Input(c.change)));
|
addMessage(
|
||||||
|
changeFormatter.newChange(
|
||||||
|
ChangeReportFormatter.Input.builder().setChange(c.change).build()));
|
||||||
}
|
}
|
||||||
addMessage("");
|
addMessage("");
|
||||||
}
|
}
|
||||||
@@ -657,12 +659,14 @@ class ReceiveCommits {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ChangeReportFormatter.Input input =
|
ChangeReportFormatter.Input input =
|
||||||
new ChangeReportFormatter.Input(u.notes.getChange())
|
ChangeReportFormatter.Input.builder()
|
||||||
|
.setChange(u.notes.getChange())
|
||||||
.setSubject(subject)
|
.setSubject(subject)
|
||||||
.setDraft(u.replaceOp != null && u.replaceOp.getPatchSet().isDraft())
|
.setIsDraft(u.replaceOp != null && u.replaceOp.getPatchSet().isDraft())
|
||||||
.setEdit(edit)
|
.setIsEdit(edit)
|
||||||
.setPrivate(isPrivate)
|
.setIsPrivate(isPrivate)
|
||||||
.setWorkInProgress(wip);
|
.setIsWorkInProgress(wip)
|
||||||
|
.build();
|
||||||
addMessage(changeFormatter.changeUpdated(input));
|
addMessage(changeFormatter.changeUpdated(input));
|
||||||
}
|
}
|
||||||
addMessage("");
|
addMessage("");
|
||||||
@@ -1678,7 +1682,10 @@ class ReceiveCommits {
|
|||||||
private boolean requestReplace(
|
private boolean requestReplace(
|
||||||
ReceiveCommand cmd, boolean checkMergedInto, Change change, RevCommit newCommit) {
|
ReceiveCommand cmd, boolean checkMergedInto, Change change, RevCommit newCommit) {
|
||||||
if (change.getStatus().isClosed()) {
|
if (change.getStatus().isClosed()) {
|
||||||
reject(cmd, changeFormatter.changeClosed(new ChangeReportFormatter.Input(change)));
|
reject(
|
||||||
|
cmd,
|
||||||
|
changeFormatter.changeClosed(
|
||||||
|
ChangeReportFormatter.Input.builder().setChange(change).build()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user