RepositoryService { public InputStream getFile(Build build, String filePath) { Repo repo = new Repo(build.getProject().getName(), build.getRepository(), build.getRef()); REPOS.computeIfAbsent(repo, key -> checkoutRepository(key)); Path path = REPOS.get(repo); synchronized (path) { checkoutRevision(path, build.getRef(), build.getSha()); Path file = path.resolve(filePath); try { if (Files.exists(file)) { return Files.newInputStream(file); } else { return null; } } catch (IOException ex) { throw Throwables.propagate(ex); } } }  @PreDestroy void cleanup(); String getLastMessage(Project project, String sha); String getLastSha(Project project); void checkoutRepository(Project project); InputStream getFile(Build build, String filePath);  }
@Test public void shouldCloneRepository() throws IOException { InputStream file = service.getFile(new Build.Builder() .withProject(new Project.Builder() .withName("dick-the-deployer/dick") .build()) .withRepository("https: .withRef("master") .withSha("74ab161c6b4df731ded57dd434c8df120d140832") .build(), ".dick.yml"); String content = StreamUtils.copyToString(file, Charsets.UTF_8); assertThat(content).isNotNull().contains("foo: bar"); }