use of com.google.gerrit.server.project.NoSuchChangeException in project gerrit by GerritCodeReview.
the class CherryPick method apply.
@Override
public Response<ChangeInfo> apply(RevisionResource rsrc, CherryPickInput input) throws IOException, UpdateException, RestApiException, PermissionBackendException, ConfigInvalidException, NoSuchProjectException {
input.parent = input.parent == null ? 1 : input.parent;
if (input.destination == null || input.destination.trim().isEmpty()) {
throw new BadRequestException("destination must be non-empty");
}
String refName = RefNames.fullName(input.destination);
contributorAgreements.check(rsrc.getProject(), rsrc.getUser());
permissionBackend.currentUser().project(rsrc.getChange().getProject()).ref(refName).check(RefPermission.CREATE_CHANGE);
projectCache.get(rsrc.getProject()).orElseThrow(illegalState(rsrc.getProject())).checkStatePermitsWrite();
try {
CherryPickChange.Result cherryPickResult = cherryPickChange.cherryPick(rsrc.getChange(), rsrc.getPatchSet(), input, BranchNameKey.create(rsrc.getProject(), refName));
ChangeInfo changeInfo = json.noOptions().format(rsrc.getProject(), cherryPickResult.changeId());
changeInfo.containsGitConflicts = !cherryPickResult.filesWithGitConflicts().isEmpty() ? true : null;
return Response.ok(changeInfo);
} catch (InvalidChangeOperationException e) {
throw new BadRequestException(e.getMessage());
} catch (NoSuchChangeException e) {
throw new ResourceConflictException(e.getMessage());
}
}
use of com.google.gerrit.server.project.NoSuchChangeException in project gerrit by GerritCodeReview.
the class EventBroker method isVisibleTo.
protected boolean isVisibleTo(Event event, CurrentUser user) throws PermissionBackendException {
if (event instanceof RefEvent) {
RefEvent refEvent = (RefEvent) event;
String ref = refEvent.getRefName();
if (PatchSet.isChangeRef(ref)) {
Change.Id cid = PatchSet.Id.fromRef(ref).changeId();
try {
Change change = notesFactory.createChecked(refEvent.getProjectNameKey(), cid).getChange();
return isVisibleTo(change, user);
} catch (NoSuchChangeException e) {
logger.atFine().log("Change %s cannot be found, falling back on ref visibility check", cid.get());
}
}
return isVisibleTo(refEvent.getBranchNameKey(), user);
} else if (event instanceof ProjectEvent) {
return isVisibleTo(((ProjectEvent) event).getProjectNameKey(), user);
}
return true;
}
use of com.google.gerrit.server.project.NoSuchChangeException in project gerrit by GerritCodeReview.
the class PatchScriptFactoryForAutoFix method createPatchScript.
private PatchScript createPatchScript() throws LargeObjectException, ResourceNotFoundException {
checkState(patchSet.id().get() != 0, "edit not supported for left side");
PatchScriptBuilder b = newBuilder();
try {
ObjectId baseId = patchSet.commitId();
return b.toPatchScript(git, baseId, fileName, fixReplacements);
} catch (ResourceConflictException e) {
logger.atSevere().withCause(e).log("AutoFix replacements is not valid");
throw new IllegalStateException("AutoFix replacements is not valid", e);
} catch (IOException e) {
logger.atSevere().withCause(e).log("File content unavailable");
throw new NoSuchChangeException(notes.getChangeId(), e);
} catch (org.eclipse.jgit.errors.LargeObjectException err) {
throw new LargeObjectException("File content is too large", err);
}
}
use of com.google.gerrit.server.project.NoSuchChangeException in project gerrit by GerritCodeReview.
the class Rebase method findBaseRev.
private ObjectId findBaseRev(Repository repo, RevWalk rw, RevisionResource rsrc, RebaseInput input) throws RestApiException, IOException, NoSuchChangeException, AuthException, PermissionBackendException {
BranchNameKey destRefKey = rsrc.getChange().getDest();
if (input == null || input.base == null) {
return rebaseUtil.findBaseRevision(rsrc.getPatchSet(), destRefKey, repo, rw);
}
Change change = rsrc.getChange();
String str = input.base.trim();
if (str.equals("")) {
// Remove existing dependency to other patch set.
Ref destRef = repo.exactRef(destRefKey.branch());
if (destRef == null) {
throw new ResourceConflictException("can't rebase onto tip of branch " + destRefKey.branch() + "; branch doesn't exist");
}
return destRef.getObjectId();
}
Base base;
try {
base = rebaseUtil.parseBase(rsrc, str);
if (base == null) {
throw new ResourceConflictException("base revision is missing from the destination branch: " + str);
}
} catch (NoSuchChangeException e) {
throw new UnprocessableEntityException(String.format("Base change not found: %s", input.base), e);
}
PatchSet.Id baseId = base.patchSet().id();
if (change.getId().equals(baseId.changeId())) {
throw new ResourceConflictException("cannot rebase change onto itself");
}
permissionBackend.user(rsrc.getUser()).change(base.notes()).check(ChangePermission.READ);
Change baseChange = base.notes().getChange();
if (!baseChange.getProject().equals(change.getProject())) {
throw new ResourceConflictException("base change is in wrong project: " + baseChange.getProject());
} else if (!baseChange.getDest().equals(change.getDest())) {
throw new ResourceConflictException("base change is targeting wrong branch: " + baseChange.getDest());
} else if (baseChange.isAbandoned()) {
throw new ResourceConflictException("base change is abandoned: " + baseChange.getKey());
} else if (isMergedInto(rw, rsrc.getPatchSet(), base.patchSet())) {
throw new ResourceConflictException("base change " + baseChange.getKey() + " is a descendant of the current change - recursion not allowed");
}
return base.patchSet().commitId();
}
use of com.google.gerrit.server.project.NoSuchChangeException in project gerrit by GerritCodeReview.
the class GetFixPreview method apply.
@Override
public Response<Map<String, DiffInfo>> apply(FixResource resource) throws PermissionBackendException, ResourceNotFoundException, ResourceConflictException, AuthException, IOException, InvalidChangeOperationException {
Map<String, DiffInfo> result = new HashMap<>();
PatchSet patchSet = resource.getRevisionResource().getPatchSet();
ChangeNotes notes = resource.getRevisionResource().getNotes();
Change change = notes.getChange();
ProjectState state = projectCache.get(change.getProject()).orElseThrow(illegalState(change.getProject()));
Map<String, List<FixReplacement>> fixReplacementsPerFilePath = resource.getFixReplacements().stream().collect(groupingBy(fixReplacement -> fixReplacement.path));
try {
try (Repository git = repoManager.openRepository(notes.getProjectName())) {
for (Map.Entry<String, List<FixReplacement>> entry : fixReplacementsPerFilePath.entrySet()) {
String fileName = entry.getKey();
DiffInfo diffInfo = getFixPreviewForSingleFile(git, patchSet, state, notes, fileName, ImmutableList.copyOf(entry.getValue()));
result.put(fileName, diffInfo);
}
}
} catch (NoSuchChangeException e) {
throw new ResourceNotFoundException(e.getMessage(), e);
} catch (LargeObjectException e) {
throw new ResourceConflictException(e.getMessage(), e);
}
return Response.ok(result);
}
Aggregations