use of com.amazonaws.gurureviewercli.exceptions.GuruCliException in project aws-codeguru-cli by aws.
the class GitAdapter method tryGetMetaData.
@Nonnull
protected static GitMetaData tryGetMetaData(final Configuration config, final Path gitDir) {
if (!gitDir.toFile().isDirectory()) {
throw new GuruCliException(ErrorCodes.GIT_INVALID_DIR);
}
val builder = new FileRepositoryBuilder();
try (val repository = builder.setGitDir(gitDir.toFile()).findGitDir().build()) {
val userName = repository.getConfig().getString("user", null, "email");
val urlString = repository.getConfig().getString("remote", "origin", "url");
val branchName = repository.getBranch();
if (branchName == null) {
throw new GuruCliException(ErrorCodes.GIT_BRANCH_MISSING);
}
val metadata = GitMetaData.builder().currentBranch(branchName).userName(userName).repoRoot(gitDir.getParent()).remoteUrl(urlString).build();
metadata.setVersionedFiles(getChangedFiles(repository));
config.setVersionedFiles(metadata.getVersionedFiles());
if (config.getBeforeCommit() == null || config.getAfterCommit() == null) {
// ask if commits should be inferred or if the entire repo should be scanned.
Log.warn("CodeGuru will perform a full repository analysis if you do not provide a commit range.");
Log.warn("For pricing details see: https://aws.amazon.com/codeguru/pricing/");
val doPackageScan = !config.isInteractiveMode() || config.getTextIO().newBooleanInputReader().withTrueInput("y").withFalseInput("n").read("Do you want to perform a full repository analysis?");
if (doPackageScan) {
return metadata;
} else {
throw new GuruCliException(ErrorCodes.USER_ABORT, "Use --commit-range to set a commit range");
}
}
validateCommits(config, repository);
metadata.setBeforeCommit(config.getBeforeCommit());
metadata.setAfterCommit(config.getAfterCommit());
return metadata;
} catch (IOException | GitAPIException e) {
throw new GuruCliException(ErrorCodes.GIT_INVALID_DIR, "Cannot read " + gitDir, e);
}
}
use of com.amazonaws.gurureviewercli.exceptions.GuruCliException in project aws-codeguru-cli by aws.
the class GitAdapterTest method test_getGitMetaData_notARepo.
@Test
public void test_getGitMetaData_notARepo() {
val repo = RESOURCE_ROOT.resolve("fresh-repo-without-remote");
GuruCliException ret = Assertions.assertThrows(GuruCliException.class, () -> GitAdapter.tryGetMetaData(configWithoutCommits(repo), repo.resolve("notgit")));
Assertions.assertEquals(ErrorCodes.GIT_INVALID_DIR, ret.getErrorCode());
}
use of com.amazonaws.gurureviewercli.exceptions.GuruCliException in project aws-codeguru-cli by aws.
the class GitAdapterTest method test_getGitMetaData_oneCommit_packageScanAbort.
@Test
public void test_getGitMetaData_oneCommit_packageScanAbort() {
val repo = RESOURCE_ROOT.resolve("one-commit");
val mockTerminal = new MockTextTerminal();
mockTerminal.getInputs().add("n");
val config = Configuration.builder().textIO(new TextIO(mockTerminal)).interactiveMode(true).build();
GuruCliException ret = Assertions.assertThrows(GuruCliException.class, () -> GitAdapter.tryGetMetaData(config, repo.resolve("git")));
Assertions.assertEquals(ErrorCodes.USER_ABORT, ret.getErrorCode());
}
Aggregations