Merge branch 'stable-2.15' into stable-2.16

* stable-2.15:
  Fix support for deleting branches (if you have can_delete)
  FileApi: Add a method to set a file's "reviewed" flag

Change-Id: I72b3ece539223452a8cd446825d20eacbb82f153
This commit is contained in:
David Pursehouse
2019-01-22 13:17:39 +09:00
3 changed files with 48 additions and 1 deletions

View File

@@ -39,6 +39,9 @@ public interface FileApi {
*/
DiffRequest diffRequest() throws RestApiException;
/** Set the file reviewed or not reviewed */
void setReviewed(boolean reviewed) throws RestApiException;
abstract class DiffRequest {
private String base;
private Integer context;
@@ -123,5 +126,10 @@ public interface FileApi {
public DiffRequest diffRequest() throws RestApiException {
throw new NotImplementedException();
}
@Override
public void setReviewed(boolean reviewed) throws RestApiException {
throw new NotImplementedException();
}
}
}

View File

@@ -18,11 +18,13 @@ import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.FileApi;
import com.google.gerrit.extensions.common.DiffInfo;
import com.google.gerrit.extensions.common.Input;
import com.google.gerrit.extensions.restapi.BinaryResult;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.change.FileResource;
import com.google.gerrit.server.restapi.change.GetContent;
import com.google.gerrit.server.restapi.change.GetDiff;
import com.google.gerrit.server.restapi.change.Reviewed;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@@ -33,12 +35,21 @@ class FileApiImpl implements FileApi {
private final GetContent getContent;
private final GetDiff getDiff;
private final Reviewed.PutReviewed putReviewed;
private final Reviewed.DeleteReviewed deleteReviewed;
private final FileResource file;
@Inject
FileApiImpl(GetContent getContent, GetDiff getDiff, @Assisted FileResource file) {
FileApiImpl(
GetContent getContent,
GetDiff getDiff,
Reviewed.PutReviewed putReviewed,
Reviewed.DeleteReviewed deleteReviewed,
@Assisted FileResource file) {
this.getContent = getContent;
this.getDiff = getDiff;
this.putReviewed = putReviewed;
this.deleteReviewed = deleteReviewed;
this.file = file;
}
@@ -88,6 +99,19 @@ class FileApiImpl implements FileApi {
};
}
@Override
public void setReviewed(boolean reviewed) throws RestApiException {
try {
if (reviewed) {
putReviewed.apply(file, new Input());
} else {
deleteReviewed.apply(file, new Input());
}
} catch (Exception e) {
throw asRestApiException(String.format("Cannot set %sreviewed", reviewed ? "" : "un"), e);
}
}
private DiffInfo get(DiffRequest r) throws RestApiException {
if (r.getBase() != null) {
getDiff.setBase(r.getBase());

View File

@@ -959,6 +959,21 @@ public class RevisionIT extends AbstractDaemonTest {
assertThat(gApi.changes().id(r.getChangeId()).current().reviewed()).isEmpty();
}
@Test
public void setUnsetReviewedFlagByFileApi() throws Exception {
PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo);
PushOneCommit.Result r = push.to("refs/for/master");
gApi.changes().id(r.getChangeId()).current().file(PushOneCommit.FILE_NAME).setReviewed(true);
assertThat(Iterables.getOnlyElement(gApi.changes().id(r.getChangeId()).current().reviewed()))
.isEqualTo(PushOneCommit.FILE_NAME);
gApi.changes().id(r.getChangeId()).current().file(PushOneCommit.FILE_NAME).setReviewed(false);
assertThat(gApi.changes().id(r.getChangeId()).current().reviewed()).isEmpty();
}
@Test
public void mergeable() throws Exception {
ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();