use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class FilesInCommitIT method addCommit.
private ObjectId addCommit(ObjectId parentCommit, ImmutableMap<String, String> files) throws Exception {
testRepo.reset(parentCommit);
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, "Adjust files of repo", files);
PushOneCommit.Result result = push.to("refs/for/master");
return result.getCommit();
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class RestApiServletIT method xGerritUpdatedRefSetMultipleHeadersForSubmit.
@Test
public void xGerritUpdatedRefSetMultipleHeadersForSubmit() throws Exception {
Result change1 = createChange();
Result change2 = createChange();
String metaRef1 = RefNames.changeMetaRef(change1.getChange().getId());
String metaRef2 = RefNames.changeMetaRef(change2.getChange().getId());
gApi.changes().id(change1.getChangeId()).current().review(ReviewInput.approve());
gApi.changes().id(change2.getChangeId()).current().review(ReviewInput.approve());
Project.NameKey project = change1.getChange().project();
try (Repository repository = repoManager.openRepository(project)) {
ObjectId originalFirstMetaRefSha1 = getMetaRefSha1(change1);
ObjectId originalSecondMetaRefSha1 = getMetaRefSha1(change2);
ObjectId originalDestinationBranchSha1 = repository.resolve(change1.getChange().change().getDest().branch());
RestResponse response = adminRestSession.postWithHeaders("/changes/" + change2.getChangeId() + "/submit", /* content = */
null, X_GERRIT_UPDATED_REF_ENABLED_HEADER);
response.assertOK();
ObjectId firstMetaRefSha1 = getMetaRefSha1(change1);
ObjectId secondMetaRefSha1 = getMetaRefSha1(change2);
List<String> headers = response.getHeaders(X_GERRIT_UPDATED_REF);
String branch = change1.getChange().change().getDest().branch();
String branchSha1 = repository.getRefDatabase().exactRef(change1.getChange().change().getDest().branch()).getObjectId().name();
// During submit, all relevant meta refs of the latest patchset are updated + the destination
// branch/es.
assertThat(headers).containsExactly(String.format("%s~%s~%s~%s", Url.encode(project.get()), Url.encode(metaRef1), originalFirstMetaRefSha1.getName(), firstMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project.get()), Url.encode(metaRef2), originalSecondMetaRefSha1.getName(), secondMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project.get()), Url.encode(branch), originalDestinationBranchSha1.getName(), branchSha1));
}
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class RestApiServletIT method xGerritUpdatedRefDeleted.
@Test
public void xGerritUpdatedRefDeleted() throws Exception {
Result change = createChange();
String project = change.getChange().project().get();
String metaRef = RefNames.changeMetaRef(change.getChange().getId());
String patchSetRef = RefNames.patchSetRef(change.getPatchSetId());
ObjectId originalMetaRefSha1 = getMetaRefSha1(change);
ObjectId originalchangeRefSha1 = change.getCommit().getId();
RestResponse response = adminRestSession.deleteWithHeaders("/changes/" + change.getChangeId(), X_GERRIT_UPDATED_REF_ENABLED_HEADER);
response.assertNoContent();
List<String> headers = response.getHeaders(X_GERRIT_UPDATED_REF);
// The change was deleted, so the refs were deleted which means they are ObjectId.zeroId().
assertThat(headers).containsExactly(String.format("%s~%s~%s~%s", Url.encode(project), Url.encode(metaRef), originalMetaRefSha1.getName(), ObjectId.zeroId().getName()), String.format("%s~%s~%s~%s", Url.encode(project), Url.encode(patchSetRef), originalchangeRefSha1.getName(), ObjectId.zeroId().getName()));
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class RestApiServletIT method xGerritUpdatedRefWithProjectNameContainingTilde.
@Test
public void xGerritUpdatedRefWithProjectNameContainingTilde() throws Exception {
Project.NameKey project = createProjectOverAPI("~~pr~oje~ct~~~~", null, true, null);
Result change = createChange(cloneProject(project, admin));
String metaRef = RefNames.changeMetaRef(change.getChange().getId());
String patchSetRef = RefNames.patchSetRef(change.getPatchSetId());
ObjectId originalMetaRefSha1 = getMetaRefSha1(change);
ObjectId originalchangeRefSha1 = change.getCommit().getId();
RestResponse response = adminRestSession.deleteWithHeaders("/changes/" + change.getChangeId(), X_GERRIT_UPDATED_REF_ENABLED_HEADER);
response.assertNoContent();
List<String> headers = response.getHeaders(X_GERRIT_UPDATED_REF);
// The change was deleted, so the refs were deleted which means they are ObjectId.zeroId().
assertThat(headers).containsExactly(String.format("%s~%s~%s~%s", Url.encode(project.get()), Url.encode(metaRef), originalMetaRefSha1.getName(), ObjectId.zeroId().getName()), String.format("%s~%s~%s~%s", Url.encode(project.get()), Url.encode(patchSetRef), originalchangeRefSha1.getName(), ObjectId.zeroId().getName()));
// Ensures ~ gets encoded to %7E.
assertThat(Url.encode(project.get())).endsWith("%7E%7Epr%7Eoje%7Ect%7E%7E%7E%7E");
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class CorsIT method originsOnForbidden.
@Test
public void originsOnForbidden() throws Exception {
Result change = createChange();
// Make change private to hide it
gApi.changes().id(change.getChangeId()).setPrivate(true, "now private");
String url = "/changes/" + change.getChangeId() + "/detail";
check(url, true, "http://example.com", anonymousRestSession, 404);
check(url, false, "http://friendsly", anonymousRestSession, 404);
}
Aggregations