Search in sources :

Example 1 with RepositoryStatusDTO

use of de.tum.in.www1.artemis.web.rest.dto.RepositoryStatusDTO 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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RepositoryStatusDTO(de.tum.in.www1.artemis.web.rest.dto.RepositoryStatusDTO)

Aggregations

RepositoryStatusDTO (de.tum.in.www1.artemis.web.rest.dto.RepositoryStatusDTO)1 ResponseEntity (org.springframework.http.ResponseEntity)1