use of com.google.gerrit.extensions.common.ProblemInfo in project gerrit by GerritCodeReview.
the class ConsistencyCheckerIT method problem.
private static ProblemInfo problem(String message, ProblemInfo.Status status, String outcome) {
ProblemInfo p = problem(message);
p.status = checkNotNull(status);
p.outcome = checkNotNull(outcome);
return p;
}
use of com.google.gerrit.extensions.common.ProblemInfo in project gerrit by GerritCodeReview.
the class ConsistencyCheckerIT method problem.
private static ProblemInfo problem(String message) {
ProblemInfo p = new ProblemInfo();
p.message = message;
return p;
}
use of com.google.gerrit.extensions.common.ProblemInfo in project gerrit by GerritCodeReview.
the class ConsistencyChecker method problem.
private ProblemInfo problem(String msg) {
ProblemInfo p = new ProblemInfo();
p.message = checkNotNull(msg);
problems.add(p);
return p;
}
use of com.google.gerrit.extensions.common.ProblemInfo in project gerrit by GerritCodeReview.
the class ConsistencyChecker method checkPatchSets.
private boolean checkPatchSets() {
List<PatchSet> all;
try {
// Iterate in descending order.
all = PS_ID_ORDER.sortedCopy(psUtil.byChange(db.get(), ctl.getNotes()));
} catch (OrmException e) {
return error("Failed to look up patch sets", e);
}
patchSetsBySha = MultimapBuilder.hashKeys(all.size()).treeSetValues(PS_ID_ORDER).build();
Map<String, Ref> refs;
try {
refs = repo.getRefDatabase().exactRef(all.stream().map(ps -> ps.getId().toRefName()).toArray(String[]::new));
} catch (IOException e) {
error("error reading refs", e);
refs = Collections.emptyMap();
}
List<DeletePatchSetFromDbOp> deletePatchSetOps = new ArrayList<>();
for (PatchSet ps : all) {
// Check revision format.
int psNum = ps.getId().get();
String refName = ps.getId().toRefName();
ObjectId objId = parseObjectId(ps.getRevision().get(), "patch set " + psNum);
if (objId == null) {
continue;
}
patchSetsBySha.put(objId, ps);
// Check ref existence.
ProblemInfo refProblem = null;
Ref ref = refs.get(refName);
if (ref == null) {
refProblem = problem("Ref missing: " + refName);
} else if (!objId.equals(ref.getObjectId())) {
String actual = ref.getObjectId() != null ? ref.getObjectId().name() : "null";
refProblem = problem(String.format("Expected %s to point to %s, found %s", ref.getName(), objId.name(), actual));
}
// Check object existence.
RevCommit psCommit = parseCommit(objId, String.format("patch set %d", psNum));
if (psCommit == null) {
if (fix != null && fix.deletePatchSetIfCommitMissing) {
deletePatchSetOps.add(new DeletePatchSetFromDbOp(lastProblem(), ps.getId()));
}
continue;
} else if (refProblem != null && fix != null) {
fixPatchSetRef(refProblem, ps);
}
if (ps.getId().equals(change().currentPatchSetId())) {
currPsCommit = psCommit;
}
}
// Delete any bad patch sets found above, in a single update.
deletePatchSets(deletePatchSetOps);
// Check for duplicates.
for (Map.Entry<ObjectId, Collection<PatchSet>> e : patchSetsBySha.asMap().entrySet()) {
if (e.getValue().size() > 1) {
problem(String.format("Multiple patch sets pointing to %s: %s", e.getKey().name(), Collections2.transform(e.getValue(), PatchSet::getPatchSetId)));
}
}
return currPs != null && currPsCommit != null;
}
use of com.google.gerrit.extensions.common.ProblemInfo in project gerrit by GerritCodeReview.
the class ChangeJson method toChangeInfo.
private ChangeInfo toChangeInfo(ChangeData cd, Optional<PatchSet.Id> limitToPsId) throws PatchListNotAvailableException, GpgException, OrmException, IOException, PermissionBackendException {
ChangeInfo out = new ChangeInfo();
CurrentUser user = userProvider.get();
ChangeControl ctl = cd.changeControl().forUser(user);
if (has(CHECK)) {
out.problems = checkerProvider.get().check(ctl, fix).problems();
// If any problems were fixed, the ChangeData needs to be reloaded.
for (ProblemInfo p : out.problems) {
if (p.status == ProblemInfo.Status.FIXED) {
cd = changeDataFactory.create(cd.db(), cd.project(), cd.getId());
break;
}
}
}
PermissionBackend.ForChange perm = permissionBackend.user(user).database(db).change(cd);
Change in = cd.change();
out.project = in.getProject().get();
out.branch = in.getDest().getShortName();
out.topic = in.getTopic();
if (indexes.getSearchIndex().getSchema().hasField(ChangeField.ASSIGNEE)) {
if (in.getAssignee() != null) {
out.assignee = accountLoader.get(in.getAssignee());
}
}
out.hashtags = cd.hashtags();
out.changeId = in.getKey().get();
if (in.getStatus().isOpen()) {
SubmitTypeRecord str = cd.submitTypeRecord();
if (str.isOk()) {
out.submitType = str.type;
}
out.mergeable = cd.isMergeable();
if (has(SUBMITTABLE)) {
out.submittable = submittable(cd);
}
}
Optional<ChangedLines> changedLines = cd.changedLines();
if (changedLines.isPresent()) {
out.insertions = changedLines.get().insertions;
out.deletions = changedLines.get().deletions;
}
out.isPrivate = in.isPrivate() ? true : null;
out.workInProgress = in.isWorkInProgress() ? true : null;
out.subject = in.getSubject();
out.status = in.getStatus().asChangeStatus();
out.owner = accountLoader.get(in.getOwner());
out.created = in.getCreatedOn();
out.updated = in.getLastUpdatedOn();
out._number = in.getId().get();
out.unresolvedCommentCount = cd.unresolvedCommentCount();
if (user.isIdentifiedUser()) {
Collection<String> stars = cd.stars(user.getAccountId());
out.starred = stars.contains(StarredChangesUtil.DEFAULT_LABEL) ? true : null;
out.muted = stars.contains(StarredChangesUtil.MUTE_LABEL + "/" + cd.currentPatchSet().getPatchSetId()) ? true : null;
if (!stars.isEmpty()) {
out.stars = stars;
}
}
if (in.getStatus().isOpen() && has(REVIEWED) && user.isIdentifiedUser()) {
Account.Id accountId = user.getAccountId();
if (out.muted != null) {
out.reviewed = true;
} else {
out.reviewed = cd.reviewedBy().contains(accountId) ? true : null;
}
}
out.labels = labelsFor(perm, ctl, cd, has(LABELS), has(DETAILED_LABELS));
out.submitted = getSubmittedOn(cd);
out.plugins = pluginDefinedAttributesFactory != null ? pluginDefinedAttributesFactory.create(cd) : null;
if (out.labels != null && has(DETAILED_LABELS)) {
// list permitted labels, since users can't vote on those patch sets.
if (user.isIdentifiedUser() && (!limitToPsId.isPresent() || limitToPsId.get().equals(in.currentPatchSetId()))) {
out.permittedLabels = cd.change().getStatus() != Change.Status.ABANDONED ? permittedLabels(perm, cd) : ImmutableMap.of();
}
out.reviewers = new HashMap<>();
for (ReviewerStateInternal state : ReviewerStateInternal.values()) {
if (state == ReviewerStateInternal.REMOVED) {
continue;
}
Collection<AccountInfo> reviewers = toAccountInfo(cd.reviewers().byState(state));
reviewers.addAll(toAccountInfoByEmail(cd.reviewersByEmail().byState(state)));
if (!reviewers.isEmpty()) {
out.reviewers.put(state.asReviewerState(), reviewers);
}
}
out.removableReviewers = removableReviewers(ctl, out);
}
if (has(REVIEWER_UPDATES)) {
out.reviewerUpdates = reviewerUpdates(cd);
}
boolean needMessages = has(MESSAGES);
boolean needRevisions = has(ALL_REVISIONS) || has(CURRENT_REVISION) || limitToPsId.isPresent();
Map<PatchSet.Id, PatchSet> src;
if (needMessages || needRevisions) {
src = loadPatchSets(cd, limitToPsId);
} else {
src = null;
}
if (needMessages) {
out.messages = messages(ctl, cd, src);
}
finish(out);
// it will be passed to ActionVisitors as-is.
if (needRevisions) {
out.revisions = revisions(ctl, cd, src, out);
if (out.revisions != null) {
for (Map.Entry<String, RevisionInfo> entry : out.revisions.entrySet()) {
if (entry.getValue().isCurrent) {
out.currentRevision = entry.getKey();
break;
}
}
}
}
if (has(CURRENT_ACTIONS) || has(CHANGE_ACTIONS)) {
actionJson.addChangeActions(out, ctl);
}
return out;
}
Aggregations