Revision API: Add method to get patch
Patch is returned as BinaryResult. Change-Id: Ia92f00d7332d0f6d91744ffbcc6098824bdedd58
This commit is contained in:
committed by
David Pursehouse
parent
b009b5b4b9
commit
453a66ce9d
@@ -47,6 +47,23 @@ public class PushOneCommit {
|
|||||||
public static final String SUBJECT = "test commit";
|
public static final String SUBJECT = "test commit";
|
||||||
public static final String FILE_NAME = "a.txt";
|
public static final String FILE_NAME = "a.txt";
|
||||||
public static final String FILE_CONTENT = "some content";
|
public static final String FILE_CONTENT = "some content";
|
||||||
|
public static final String PATCH =
|
||||||
|
"From %s Mon Sep 17 00:00:00 2001\n" +
|
||||||
|
"From: Administrator <admin@example.com>\n" +
|
||||||
|
"Date: %s\n" +
|
||||||
|
"Subject: [PATCH] test commit\n" +
|
||||||
|
"\n" +
|
||||||
|
"Change-Id: %s\n" +
|
||||||
|
"---\n" +
|
||||||
|
"\n" +
|
||||||
|
"diff --git a/a.txt b/a.txt\n" +
|
||||||
|
"new file mode 100644\n" +
|
||||||
|
"index 0000000..f0eec86\n" +
|
||||||
|
"--- /dev/null\n" +
|
||||||
|
"+++ b/a.txt\n" +
|
||||||
|
"@@ -0,0 +1 @@\n" +
|
||||||
|
"+some content\n" +
|
||||||
|
"\\ No newline at end of file\n";
|
||||||
|
|
||||||
public interface Factory {
|
public interface Factory {
|
||||||
PushOneCommit create(
|
PushOneCommit create(
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package com.google.gerrit.acceptance.api.revision;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.gerrit.acceptance.PushOneCommit.FILE_CONTENT;
|
import static com.google.gerrit.acceptance.PushOneCommit.FILE_CONTENT;
|
||||||
import static com.google.gerrit.acceptance.PushOneCommit.FILE_NAME;
|
import static com.google.gerrit.acceptance.PushOneCommit.FILE_NAME;
|
||||||
|
import static com.google.gerrit.acceptance.PushOneCommit.PATCH;
|
||||||
import static org.eclipse.jgit.lib.Constants.HEAD;
|
import static org.eclipse.jgit.lib.Constants.HEAD;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
@@ -40,6 +41,7 @@ import com.google.gerrit.extensions.common.ChangeMessageInfo;
|
|||||||
import com.google.gerrit.extensions.common.CommentInfo;
|
import com.google.gerrit.extensions.common.CommentInfo;
|
||||||
import com.google.gerrit.extensions.common.DiffInfo;
|
import com.google.gerrit.extensions.common.DiffInfo;
|
||||||
import com.google.gerrit.extensions.common.MergeableInfo;
|
import com.google.gerrit.extensions.common.MergeableInfo;
|
||||||
|
import com.google.gerrit.extensions.common.RevisionInfo;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.BinaryResult;
|
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||||
@@ -52,6 +54,8 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -540,6 +544,25 @@ public class RevisionIT extends AbstractDaemonTest {
|
|||||||
.isEqualTo(in.message);
|
.isEqualTo(in.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void patch() throws Exception {
|
||||||
|
PushOneCommit.Result r = createChange();
|
||||||
|
ChangeApi changeApi = gApi.changes()
|
||||||
|
.id(r.getChangeId());
|
||||||
|
BinaryResult bin = changeApi
|
||||||
|
.revision(r.getCommit().name())
|
||||||
|
.patch();
|
||||||
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
|
bin.writeTo(os);
|
||||||
|
String res = new String(os.toByteArray(), StandardCharsets.UTF_8);
|
||||||
|
DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
|
||||||
|
ChangeInfo change = changeApi.get();
|
||||||
|
RevisionInfo rev = change.revisions.get(change.currentRevision);
|
||||||
|
String date = dateFormat.format(rev.commit.author.date);
|
||||||
|
assertThat(res).isEqualTo(
|
||||||
|
String.format(PATCH, r.getCommitId().name(), date, r.getChangeId()));
|
||||||
|
}
|
||||||
|
|
||||||
private void merge(PushOneCommit.Result r) throws Exception {
|
private void merge(PushOneCommit.Result r) throws Exception {
|
||||||
revision(r).review(ReviewInput.approve());
|
revision(r).review(ReviewInput.approve());
|
||||||
revision(r).submit();
|
revision(r).submit();
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import com.google.gerrit.extensions.common.ActionInfo;
|
|||||||
import com.google.gerrit.extensions.common.CommentInfo;
|
import com.google.gerrit.extensions.common.CommentInfo;
|
||||||
import com.google.gerrit.extensions.common.FileInfo;
|
import com.google.gerrit.extensions.common.FileInfo;
|
||||||
import com.google.gerrit.extensions.common.MergeableInfo;
|
import com.google.gerrit.extensions.common.MergeableInfo;
|
||||||
|
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||||
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
|
|
||||||
@@ -57,6 +58,11 @@ public interface RevisionApi {
|
|||||||
|
|
||||||
CommentApi comment(String id) throws RestApiException;
|
CommentApi comment(String id) throws RestApiException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns patch of revision.
|
||||||
|
*/
|
||||||
|
BinaryResult patch() throws RestApiException;
|
||||||
|
|
||||||
Map<String, ActionInfo> actions() throws RestApiException;
|
Map<String, ActionInfo> actions() throws RestApiException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,6 +185,11 @@ public interface RevisionApi {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BinaryResult patch() throws RestApiException {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, ActionInfo> actions() throws RestApiException {
|
public Map<String, ActionInfo> actions() throws RestApiException {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import com.google.gerrit.extensions.common.ActionInfo;
|
|||||||
import com.google.gerrit.extensions.common.CommentInfo;
|
import com.google.gerrit.extensions.common.CommentInfo;
|
||||||
import com.google.gerrit.extensions.common.FileInfo;
|
import com.google.gerrit.extensions.common.FileInfo;
|
||||||
import com.google.gerrit.extensions.common.MergeableInfo;
|
import com.google.gerrit.extensions.common.MergeableInfo;
|
||||||
|
import com.google.gerrit.extensions.restapi.BinaryResult;
|
||||||
import com.google.gerrit.extensions.restapi.IdString;
|
import com.google.gerrit.extensions.restapi.IdString;
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||||
@@ -41,6 +42,7 @@ import com.google.gerrit.server.change.DeleteDraftPatchSet;
|
|||||||
import com.google.gerrit.server.change.DraftComments;
|
import com.google.gerrit.server.change.DraftComments;
|
||||||
import com.google.gerrit.server.change.FileResource;
|
import com.google.gerrit.server.change.FileResource;
|
||||||
import com.google.gerrit.server.change.Files;
|
import com.google.gerrit.server.change.Files;
|
||||||
|
import com.google.gerrit.server.change.GetPatch;
|
||||||
import com.google.gerrit.server.change.GetRevisionActions;
|
import com.google.gerrit.server.change.GetRevisionActions;
|
||||||
import com.google.gerrit.server.change.ListRevisionComments;
|
import com.google.gerrit.server.change.ListRevisionComments;
|
||||||
import com.google.gerrit.server.change.ListRevisionDrafts;
|
import com.google.gerrit.server.change.ListRevisionDrafts;
|
||||||
@@ -79,6 +81,7 @@ class RevisionApiImpl implements RevisionApi {
|
|||||||
private final RevisionResource revision;
|
private final RevisionResource revision;
|
||||||
private final Provider<Files> files;
|
private final Provider<Files> files;
|
||||||
private final Provider<Files.ListFiles> listFiles;
|
private final Provider<Files.ListFiles> listFiles;
|
||||||
|
private final Provider<GetPatch> getPatch;
|
||||||
private final Provider<PostReview> review;
|
private final Provider<PostReview> review;
|
||||||
private final Provider<Mergeable> mergeable;
|
private final Provider<Mergeable> mergeable;
|
||||||
private final FileApiImpl.Factory fileApi;
|
private final FileApiImpl.Factory fileApi;
|
||||||
@@ -103,6 +106,7 @@ class RevisionApiImpl implements RevisionApi {
|
|||||||
Reviewed.DeleteReviewed deleteReviewed,
|
Reviewed.DeleteReviewed deleteReviewed,
|
||||||
Provider<Files> files,
|
Provider<Files> files,
|
||||||
Provider<Files.ListFiles> listFiles,
|
Provider<Files.ListFiles> listFiles,
|
||||||
|
Provider<GetPatch> getPatch,
|
||||||
Provider<PostReview> review,
|
Provider<PostReview> review,
|
||||||
Provider<Mergeable> mergeable,
|
Provider<Mergeable> mergeable,
|
||||||
FileApiImpl.Factory fileApi,
|
FileApiImpl.Factory fileApi,
|
||||||
@@ -127,6 +131,7 @@ class RevisionApiImpl implements RevisionApi {
|
|||||||
this.putReviewed = putReviewed;
|
this.putReviewed = putReviewed;
|
||||||
this.deleteReviewed = deleteReviewed;
|
this.deleteReviewed = deleteReviewed;
|
||||||
this.listFiles = listFiles;
|
this.listFiles = listFiles;
|
||||||
|
this.getPatch = getPatch;
|
||||||
this.mergeable = mergeable;
|
this.mergeable = mergeable;
|
||||||
this.fileApi = fileApi;
|
this.fileApi = fileApi;
|
||||||
this.listComments = listComments;
|
this.listComments = listComments;
|
||||||
@@ -356,6 +361,15 @@ class RevisionApiImpl implements RevisionApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BinaryResult patch() throws RestApiException {
|
||||||
|
try {
|
||||||
|
return getPatch.get().apply(revision);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RestApiException("Cannot get patch", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, ActionInfo> actions() throws RestApiException {
|
public Map<String, ActionInfo> actions() throws RestApiException {
|
||||||
return revisionActions.apply(revision).value();
|
return revisionActions.apply(revision).value();
|
||||||
|
|||||||
Reference in New Issue
Block a user