use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class ImpersonationIT method testVoteOnBehalfOfWithComment.
private void testVoteOnBehalfOfWithComment() throws Exception {
allowCodeReviewOnBehalfOf();
PushOneCommit.Result r = createChange();
ReviewInput in = new ReviewInput();
in.onBehalfOf = user.id().toString();
in.label("Code-Review", 1);
CommentInput ci = new CommentInput();
ci.path = Patch.COMMIT_MSG;
ci.side = Side.REVISION;
ci.line = 1;
ci.message = "message";
in.comments = ImmutableMap.of(ci.path, ImmutableList.of(ci));
gApi.changes().id(r.getChangeId()).current().review(in);
PatchSetApproval psa = Iterables.getOnlyElement(r.getChange().approvals().values());
assertThat(psa.patchSetId().get()).isEqualTo(1);
assertThat(psa.label()).isEqualTo("Code-Review");
assertThat(psa.accountId()).isEqualTo(user.id());
assertThat(psa.value()).isEqualTo(1);
assertThat(psa.realAccountId()).isEqualTo(admin.id());
ChangeData cd = r.getChange();
HumanComment c = Iterables.getOnlyElement(commentsUtil.publishedHumanCommentsByChange(cd.notes()));
assertThat(c.message).isEqualTo(ci.message);
assertThat(c.author.getId()).isEqualTo(user.id());
assertThat(c.getRealAuthor().getId()).isEqualTo(admin.id());
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class RebaseUtil method findBaseRevision.
/**
* Find the commit onto which a patch set should be rebased.
*
* <p>This is defined as the latest patch set of the change corresponding to this commit's parent,
* or the destination branch tip in the case where the parent's change is merged.
*
* @param patchSet patch set for which the new base commit should be found.
* @param destBranch the destination branch.
* @param git the repository.
* @param rw the RevWalk.
* @return the commit onto which the patch set should be rebased.
* @throws RestApiException if rebase is not possible.
* @throws IOException if accessing the repository fails.
*/
public ObjectId findBaseRevision(PatchSet patchSet, BranchNameKey destBranch, Repository git, RevWalk rw) throws RestApiException, IOException {
ObjectId baseId = null;
RevCommit commit = rw.parseCommit(patchSet.commitId());
if (commit.getParentCount() > 1) {
throw new UnprocessableEntityException("Cannot rebase a change with multiple parents.");
} else if (commit.getParentCount() == 0) {
throw new UnprocessableEntityException("Cannot rebase a change without any parents (is this the initial commit?).");
}
ObjectId parentId = commit.getParent(0);
CHANGES: for (ChangeData cd : queryProvider.get().byBranchCommit(destBranch, parentId.name())) {
for (PatchSet depPatchSet : cd.patchSets()) {
if (!depPatchSet.commitId().equals(parentId)) {
continue;
}
Change depChange = cd.change();
if (depChange.isAbandoned()) {
throw new ResourceConflictException("Cannot rebase a change with an abandoned parent: " + depChange.getKey());
}
if (depChange.isNew()) {
if (depPatchSet.id().equals(depChange.currentPatchSetId())) {
throw new ResourceConflictException("Change is already based on the latest patch set of the dependent change.");
}
baseId = cd.currentPatchSet().commitId();
}
break CHANGES;
}
}
if (baseId == null) {
// We are dependent on a merged PatchSet or have no PatchSet
// dependencies at all.
Ref destRef = git.getRefDatabase().exactRef(destBranch.branch());
if (destRef == null) {
throw new UnprocessableEntityException("The destination branch does not exist: " + destBranch.branch());
}
baseId = destRef.getObjectId();
if (baseId.equals(parentId)) {
throw new ResourceConflictException("Change is already up to date.");
}
}
return baseId;
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class PluginDefinedAttributesFactories method tryCreate.
private static void tryCreate(Collection<ChangeData> cds, BeanProvider beanProvider, String plugin, ChangePluginDefinedInfoFactory infoFactory, ImmutableListMultimap.Builder<Change.Id, PluginDefinedInfo> pluginInfosByChangeBuilder) {
try {
infoFactory.createPluginDefinedInfos(cds, beanProvider, plugin).forEach((id, pdi) -> {
if (pdi != null) {
pdi.name = plugin;
pluginInfosByChangeBuilder.put(id, pdi);
}
});
} catch (RuntimeException ex) {
/* Propagate runtime exceptions as structured API data types so that queries don't fail. */
logger.atWarning().atMostEvery(1, MINUTES).withCause(ex).log("error populating attribute on changes from plugin %s", plugin);
PluginDefinedInfo errorInfo = new PluginDefinedInfo();
errorInfo.name = plugin;
errorInfo.message = "Something went wrong in plugin: " + plugin;
cds.forEach(cd -> pluginInfosByChangeBuilder.put(cd.getId(), errorInfo));
}
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class PrologRuleEvaluator method runSubmitFilters.
private Term runSubmitFilters(Term results, PrologEnvironment env, String filterRuleLocatorName, String filterRuleWrapperName) throws RuleEvalException {
PrologEnvironment childEnv = env;
ChangeData cd = env.get(StoredValues.CHANGE_DATA);
ProjectState projectState = env.get(StoredValues.PROJECT_STATE);
for (ProjectState parentState : projectState.parents()) {
PrologEnvironment parentEnv;
try {
parentEnv = envFactory.create(rulesCache.loadMachine(parentState.getNameKey(), parentState.getConfig().getRulesId().orElse(null)));
} catch (CompileException err) {
throw new RuleEvalException("Cannot consult rules.pl for " + parentState.getName(), err);
}
parentEnv.copyStoredValues(childEnv);
Term filterRule = parentEnv.once("gerrit", filterRuleLocatorName, new VariableTerm());
try {
Term[] template = parentEnv.once("gerrit", filterRuleWrapperName, filterRule, results, new VariableTerm());
results = template[2];
} catch (ReductionLimitException err) {
throw new RuleEvalException(String.format("%s on change %d of %s", err.getMessage(), cd.getId().get(), parentState.getName()));
} catch (RuntimeException err) {
throw new RuleEvalException(String.format("Exception calling %s on change %d of %s", filterRule, cd.getId().get(), parentState.getName()), err);
}
childEnv = parentEnv;
}
return results;
}
use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.
the class PermissionBackendIT method changeDataFromIndex_canCheckReviewerState.
@Test
public void changeDataFromIndex_canCheckReviewerState() throws Exception {
Change.Id changeId = createChange().getChange().getId();
gApi.changes().id(changeId.get()).setPrivate(true);
gApi.changes().id(changeId.get()).addReviewer(user.email());
ChangeData changeData = Iterables.getOnlyElement(queryProvider.get().byLegacyChangeId(changeId));
boolean reviewerCanSee = pb.absentUser(user.id()).change(changeData).test(ChangePermission.READ);
assertThat(reviewerCanSee).isTrue();
}
Aggregations