use of de.tum.in.www1.artemis.domain.Repository in project ArTEMiS by ls1intum.
the class RepositoryResource method getStatus.
/**
* GET /repository/{id}: Get the "clean" status of the repository. Clean = No uncommitted changes.
*
* @param id Participation ID
* @param request
* @param authentication
* @return
* @throws IOException
* @throws GitAPIException
*/
@GetMapping(value = "/repository/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RepositoryStatusDTO> getStatus(@PathVariable Long id, HttpServletRequest request, AbstractAuthenticationToken authentication) throws IOException, GitAPIException {
log.debug("REST request to get clean status for Repository for Participation : {}", id);
Participation participation = participationService.findOne(id);
if (!userHasPermissions(participation))
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
if (!Optional.ofNullable(participation).isPresent()) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
Repository repository = gitService.get().getOrCheckoutRepository(participation);
RepositoryStatusDTO status = new RepositoryStatusDTO();
status.isClean = gitService.get().isClean(repository);
if (status.isClean) {
gitService.get().pull(repository);
}
return new ResponseEntity<>(status, HttpStatus.OK);
}
use of de.tum.in.www1.artemis.domain.Repository in project ArTEMiS by ls1intum.
the class GitServiceIntTest method testCommitAndPush.
@Test
public void testCommitAndPush() throws IOException, GitAPIException {
Participation participation = new Participation();
participation.setRepositoryUrl(remoteTestRepo);
Repository repo = gitService.getOrCheckoutRepository(participation);
Ref oldHead = repo.findRef("HEAD");
gitService.commitAndPush(repo, "test commit");
Ref head = repo.findRef("HEAD");
assertThat(head).isNotEqualTo(oldHead);
RevWalk walk = new RevWalk(repo);
RevCommit commit = walk.parseCommit(head.getObjectId());
assertThat(commit.getFullMessage()).isEqualTo("test commit");
// get remote ref
Git git = new Git(repo);
Collection<Ref> refs = git.lsRemote().setHeads(true).call();
Ref remoteHead = refs.iterator().next();
assertThat(head.getObjectId()).isEqualTo(remoteHead.getObjectId());
gitService.deleteLocalRepository(repo);
}
use of de.tum.in.www1.artemis.domain.Repository in project ArTEMiS by ls1intum.
the class GitServiceIntTest method testGetOrCheckoutRepositoryForNewRepo.
@Test
public void testGetOrCheckoutRepositoryForNewRepo() throws IOException, GitAPIException {
Participation participation = new Participation();
participation.setRepositoryUrl(remoteTestRepo);
Repository repo = gitService.getOrCheckoutRepository(participation);
assertThat(repo.getBranch()).isEqualTo("master");
assertThat(repo.getDirectory()).exists();
gitService.deleteLocalRepository(repo);
}
use of de.tum.in.www1.artemis.domain.Repository in project ArTEMiS by ls1intum.
the class GitServiceIntTest method testPull.
@Test
public void testPull() throws IOException, GitAPIException {
Participation participation = new Participation();
participation.setRepositoryUrl(remoteTestRepo);
Repository repo = gitService.getOrCheckoutRepository(participation);
Ref oldHead = repo.findRef("HEAD");
// commit
File tempDir = Files.createTempDir();
Git git = Git.cloneRepository().setURI(remoteTestRepo).setCredentialsProvider(new UsernamePasswordCredentialsProvider(GIT_USER, GIT_PASSWORD)).setDirectory(tempDir).call();
git.commit().setMessage("a commit").setAllowEmpty(true).call();
git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(GIT_USER, GIT_PASSWORD)).call();
// pull
PullResult pullResult = gitService.pull(repo);
Ref newHead = repo.findRef("HEAD");
assertThat(oldHead).isNotEqualTo(newHead);
RevWalk walk = new RevWalk(repo);
RevCommit commit = walk.parseCommit(newHead.getObjectId());
assertThat(commit.getFullMessage()).isEqualTo("a commit");
FileUtils.deleteDirectory(tempDir);
}
Aggregations