Skip to content

Commit

Permalink
Extract methods for reused actions in CodeAnalysisJob
Browse files Browse the repository at this point in the history
  • Loading branch information
dabico committed Jan 8, 2024
1 parent dcba848 commit e6d5301
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions src/main/java/ch/usi/si/seart/job/CodeAnalysisJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,37 +135,43 @@ private void gatherCodeMetricsFor(@NotNull GitRepo gitRepo) {
gitRepo.setLastAnalyzed();
gitRepoService.createOrUpdate(gitRepo);
} catch (RepositoryLockedException ignored) {
log.info("Locking: {} [{}]", name, id);
gitRepo.setIsLocked(true);
gitRepo.setLastAnalyzed();
gitRepoService.createOrUpdate(gitRepo);
lock(gitRepo);
} catch (RepositoryDisabledException ignored) {
log.info("Disabling: {} [{}]", name, id);
gitRepo.setIsDisabled(true);
gitRepo.setLastAnalyzed();
gitRepoService.createOrUpdate(gitRepo);
disable(gitRepo);
} catch (RepositoryNotFoundException ignored) {
log.info("Deleting: {} [{}]", name, id);
gitRepoService.deleteRepoById(id);
delete(gitRepo);
} catch (InvalidUsernameException ex) {
switch (gitHubRestConnector.pingRepository(name)) {
case NOT_FOUND:
log.info("Deleting: {} [{}]", name, id);
gitRepoService.deleteRepoById(id);
return;
case FORBIDDEN, UNAVAILABLE_FOR_LEGAL_REASONS:
log.info("Disabling: {} [{}]", name, id);
gitRepo.setIsDisabled(true);
gitRepo.setLastAnalyzed();
gitRepoService.createOrUpdate(gitRepo);
return;
default:
log.error("Failed: {} [{}] ({})", name, id, ex.getClass().getSimpleName());
log.debug("", ex);
case NOT_FOUND -> delete(gitRepo);
case FORBIDDEN, UNAVAILABLE_FOR_LEGAL_REASONS -> disable(gitRepo);
default -> noop(gitRepo, ex);
}
} catch (StaticCodeAnalysisException | GitException ex) {
log.error("Failed: {} [{}] ({})", name, id, ex.getClass().getSimpleName());
log.debug("", ex);
noop(gitRepo, ex);
}
}

private void delete(GitRepo gitRepo) {
log.info("Deleting: {} [{}]", gitRepo.getName(), gitRepo.getId());
gitRepoService.deleteRepoById(gitRepo.getId());
}

private void lock(GitRepo gitRepo) {
log.info("Locking: {} [{}]", gitRepo.getName(), gitRepo.getId());
gitRepo.setIsLocked(true);
gitRepo.setLastAnalyzed();
gitRepoService.createOrUpdate(gitRepo);
}

private void disable(GitRepo gitRepo) {
log.info("Disabling: {} [{}]", gitRepo.getName(), gitRepo.getId());
gitRepo.setIsDisabled(true);
gitRepo.setLastAnalyzed();
gitRepoService.createOrUpdate(gitRepo);
}

private void noop(GitRepo gitRepo, Exception ex) {
log.error("Failed: {} [{}] ({})", gitRepo.getName(), gitRepo.getId(), ex.getClass().getSimpleName());
log.debug("", ex);
}
}

0 comments on commit e6d5301

Please sign in to comment.