Merge "Plugin API: Add factory methods for frequently used review operations"

This commit is contained in:
Shawn Pearce 2014-01-29 20:18:57 +00:00 committed by Gerrit Code Review
commit c792114e50
4 changed files with 34 additions and 34 deletions

View File

@ -109,7 +109,7 @@ public class ChangeIT extends AbstractDaemonTest {
gApi.changes()
.id("p~master~" + r.getChangeId())
.revision(r.getCommit().name())
.review(approve());
.review(ReviewInput.approve());
gApi.changes()
.id("p~master~" + r.getChangeId())
.revision(r.getCommit().name())
@ -146,10 +146,4 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit push = pushFactory.create(db, admin.getIdent());
return push.to(git, "refs/for/master");
}
private static ReviewInput approve() {
return new ReviewInput()
.message("Looks good!")
.label("Code-Review", 2);
}
}

View File

@ -86,7 +86,7 @@ public class RevisionIT extends AbstractDaemonTest {
gApi.changes()
.id("p~master~" + r.getChangeId())
.revision(r.getCommit().name())
.review(approve());
.review(ReviewInput.approve());
}
@Test
@ -96,7 +96,7 @@ public class RevisionIT extends AbstractDaemonTest {
gApi.changes()
.id(r.getChangeId())
.current()
.review(approve());
.review(ReviewInput.approve());
}
@Test
@ -106,13 +106,13 @@ public class RevisionIT extends AbstractDaemonTest {
gApi.changes()
.id(r.getChangeId())
.revision(1)
.review(approve());
.review(ReviewInput.approve());
r = updateChange(r, "new content");
gApi.changes()
.id(r.getChangeId())
.revision(2)
.review(approve());
.review(ReviewInput.approve());
}
@Test
@ -122,7 +122,7 @@ public class RevisionIT extends AbstractDaemonTest {
gApi.changes()
.id("p~master~" + r.getChangeId())
.current()
.review(approve());
.review(ReviewInput.approve());
gApi.changes()
.id("p~master~" + r.getChangeId())
.current()
@ -155,7 +155,7 @@ public class RevisionIT extends AbstractDaemonTest {
.revision(r.getCommit().name())
.cherryPick(in);
cApi.current()
.review(approve());
.review(ReviewInput.approve());
cApi.current()
.submit();
}
@ -179,10 +179,4 @@ public class RevisionIT extends AbstractDaemonTest {
PushOneCommit push = pushFactory.create(db, admin.getIdent());
return push.to(git, "refs/drafts/master");
}
private static ReviewInput approve() {
return new ReviewInput()
.message("Looks good!")
.label("Code-Review", 2);
}
}

View File

@ -133,7 +133,7 @@ public class LabelTypeIT extends AbstractDaemonTest {
PushOneCommit push = pushFactory.create(db, user.getIdent(),
subject, file, "first contents");
PushOneCommit.Result r = push.to(git, "refs/for/master");
review(r, -2);
revision(r).review(ReviewInput.reject());
assertApproval(r, -2);
push = pushFactory.create(db, user.getIdent(),
@ -152,7 +152,7 @@ public class LabelTypeIT extends AbstractDaemonTest {
PushOneCommit push = pushFactory.create(db, user.getIdent(),
subject, file, "first contents");
PushOneCommit.Result r = push.to(git, "refs/for/master");
review(r, -2);
revision(r).review(ReviewInput.reject());
assertApproval(r, -2);
push = pushFactory.create(db, user.getIdent(),
@ -169,7 +169,7 @@ public class LabelTypeIT extends AbstractDaemonTest {
PushOneCommit push = pushFactory.create(db, user.getIdent(),
subject, file, "first contents");
PushOneCommit.Result r = push.to(git, "refs/for/master");
review(r, 2);
revision(r).review(ReviewInput.approve());
assertApproval(r, 2);
push = pushFactory.create(db, user.getIdent(),
@ -188,7 +188,7 @@ public class LabelTypeIT extends AbstractDaemonTest {
PushOneCommit push = pushFactory.create(db, user.getIdent(),
subject, file, "first contents");
PushOneCommit.Result r = push.to(git, "refs/for/master");
review(r, 2);
revision(r).review(ReviewInput.approve());
assertApproval(r, 2);
push = pushFactory.create(db, user.getIdent(),
@ -208,7 +208,7 @@ public class LabelTypeIT extends AbstractDaemonTest {
PushOneCommit push = pushFactory.create(db, user.getIdent(),
subject, file, "first contents");
PushOneCommit.Result r = push.to(git, "refs/for/master");
review(r, 1);
revision(r).review(ReviewInput.recommend());
assertApproval(r, 1);
push = pushFactory.create(db, user.getIdent(),
@ -228,7 +228,7 @@ public class LabelTypeIT extends AbstractDaemonTest {
PushOneCommit push = pushFactory.create(db, user.getIdent(),
subject, file, "first contents");
PushOneCommit.Result r = push.to(git, "refs/for/master");
review(r, -1);
revision(r).review(ReviewInput.dislike());
assertApproval(r, -1);
push = pushFactory.create(db, user.getIdent(),
@ -245,7 +245,7 @@ public class LabelTypeIT extends AbstractDaemonTest {
PushOneCommit push = pushFactory.create(db, user.getIdent(),
"first subject", file, contents);
PushOneCommit.Result r = push.to(git, "refs/for/master");
review(r, 1);
revision(r).review(ReviewInput.recommend());
assertApproval(r, 1);
push = pushFactory.create(db, user.getIdent(),
@ -264,7 +264,7 @@ public class LabelTypeIT extends AbstractDaemonTest {
PushOneCommit push = pushFactory.create(db, user.getIdent(),
"first subject", file, contents);
PushOneCommit.Result r = push.to(git, "refs/for/master");
review(r, 1);
revision(r).review(ReviewInput.recommend());
assertApproval(r, 1);
push = pushFactory.create(db, user.getIdent(),
@ -291,7 +291,7 @@ public class LabelTypeIT extends AbstractDaemonTest {
git.checkout().setName(r1.getCommit().name()).call();
push = pushFactory.create(db, user.getIdent(), subject, file, contents);
PushOneCommit.Result r3 = push.to(git, "refs/for/master");
review(r3, 1);
revision(r3).review(ReviewInput.recommend());
assertApproval(r3, 1);
rebase(r3);
@ -318,7 +318,7 @@ public class LabelTypeIT extends AbstractDaemonTest {
git.checkout().setName(r1.getCommit().name()).call();
push = pushFactory.create(db, user.getIdent(), subject, file, contents);
PushOneCommit.Result r3 = push.to(git, "refs/for/master");
review(r3, 1);
revision(r3).review(ReviewInput.recommend());
assertApproval(r3, 1);
rebase(r3);
@ -347,12 +347,8 @@ public class LabelTypeIT extends AbstractDaemonTest {
.revision(r.getCommit().name());
}
private void review(PushOneCommit.Result r, int score) throws Exception {
revision(r).review(new ReviewInput().label("Code-Review", score));
}
private void merge(PushOneCommit.Result r) throws Exception {
review(r, 2);
revision(r).review(ReviewInput.approve());
revision(r).submit();
Repository repo = repoManager.openRepository(project);
try {

View File

@ -113,4 +113,20 @@ public class ReviewInput {
public ReviewInput label(String name) {
return label(name, (short) 1);
}
public static ReviewInput recommend() {
return new ReviewInput().label("Code-Review", 1);
}
public static ReviewInput dislike() {
return new ReviewInput().label("Code-Review", -1);
}
public static ReviewInput approve() {
return new ReviewInput().label("Code-Review", 2);
}
public static ReviewInput reject() {
return new ReviewInput().label("Code-Review", -2);
}
}