| 1 | package edu.ucsb.cs156.frontiers.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.Course; | |
| 4 | import edu.ucsb.cs156.frontiers.entities.Job; | |
| 5 | import edu.ucsb.cs156.frontiers.enums.RepositoryPermissions; | |
| 6 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
| 7 | import edu.ucsb.cs156.frontiers.errors.NoLinkedOrganizationException; | |
| 8 | import edu.ucsb.cs156.frontiers.jobs.CreateStudentRepositoriesJob; | |
| 9 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 10 | import edu.ucsb.cs156.frontiers.services.RepositoryService; | |
| 11 | import edu.ucsb.cs156.frontiers.services.jobs.JobService; | |
| 12 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 13 | import java.util.Optional; | |
| 14 | import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.web.bind.annotation.PostMapping; | |
| 17 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 18 | import org.springframework.web.bind.annotation.RequestParam; | |
| 19 | import org.springframework.web.bind.annotation.RestController; | |
| 20 | ||
| 21 | @Tag(name = "Repository Controller") | |
| 22 | @RestController | |
| 23 | @RequestMapping("/api/repos") | |
| 24 | public class RepositoryController extends ApiController { | |
| 25 | ||
| 26 | @Autowired RepositoryService repositoryService; | |
| 27 | ||
| 28 | @Autowired JobService jobService; | |
| 29 | ||
| 30 | @Autowired CourseRepository courseRepository; | |
| 31 | ||
| 32 | /** | |
| 33 | * Fires a job that creates a repo for every RosterStudent with a linked user with a GitHub | |
| 34 | * account. | |
| 35 | * | |
| 36 | * @param courseId ID of course to create repos for | |
| 37 | * @param repoPrefix each repo created will begin with this prefix, followed by a dash and the | |
| 38 | * student's GitHub username | |
| 39 | * @param isPrivate determines whether the repository being created is private | |
| 40 | * @return the {@link edu.ucsb.cs156.frontiers.entities.Job Job} started to create the repos. | |
| 41 | */ | |
| 42 | @PostMapping("/createRepos") | |
| 43 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 44 | public Job createRepos( | |
| 45 | @RequestParam Long courseId, | |
| 46 | @RequestParam String repoPrefix, | |
| 47 | @RequestParam Optional<Boolean> isPrivate, | |
| 48 | @RequestParam RepositoryPermissions permissions) { | |
| 49 | Course course = | |
| 50 | courseRepository | |
| 51 | .findById(courseId) | |
| 52 |
1
1. lambda$createRepos$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RepositoryController::lambda$createRepos$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 53 |
2
1. createRepos : negated conditional → KILLED 2. createRepos : negated conditional → KILLED |
if (course.getOrgName() == null || course.getInstallationId() == null) { |
| 54 | throw new NoLinkedOrganizationException(course.getCourseName()); | |
| 55 | } else { | |
| 56 | CreateStudentRepositoriesJob job = | |
| 57 | CreateStudentRepositoriesJob.builder() | |
| 58 | .repositoryPrefix(repoPrefix) | |
| 59 | .isPrivate(isPrivate.orElse(false)) | |
| 60 | .repositoryService(repositoryService) | |
| 61 | .course(course) | |
| 62 | .permissions(permissions) | |
| 63 | .build(); | |
| 64 |
1
1. createRepos : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RepositoryController::createRepos → KILLED |
return jobService.runAsJob(job); |
| 65 | } | |
| 66 | } | |
| 67 | } | |
Mutations | ||
| 52 |
1.1 |
|
| 53 |
1.1 2.2 |
|
| 64 |
1.1 |