| 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.RepositoryCreationTarget; | |
| 6 | import edu.ucsb.cs156.frontiers.enums.RepositoryPermissions; | |
| 7 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
| 8 | import edu.ucsb.cs156.frontiers.errors.NoLinkedOrganizationException; | |
| 9 | import edu.ucsb.cs156.frontiers.jobs.CreateStudentRepositoriesJob; | |
| 10 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 11 | import edu.ucsb.cs156.frontiers.services.RepositoryService; | |
| 12 | import edu.ucsb.cs156.frontiers.services.jobs.JobService; | |
| 13 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 14 | import java.util.Optional; | |
| 15 | import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 17 | import org.springframework.web.bind.annotation.PostMapping; | |
| 18 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 19 | import org.springframework.web.bind.annotation.RequestParam; | |
| 20 | import org.springframework.web.bind.annotation.RestController; | |
| 21 | ||
| 22 | @Tag(name = "Repository Controller") | |
| 23 | @RestController | |
| 24 | @RequestMapping("/api/repos") | |
| 25 | public class RepositoryController extends ApiController { | |
| 26 | ||
| 27 | @Autowired RepositoryService repositoryService; | |
| 28 | ||
| 29 | @Autowired JobService jobService; | |
| 30 | ||
| 31 | @Autowired CourseRepository courseRepository; | |
| 32 | ||
| 33 | /** | |
| 34 | * Fires a job that creates a repo for students and/or staff members with GitHub accounts. | |
| 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 | * GitHub username | |
| 39 | * @param isPrivate determines whether the repository being created is private | |
| 40 | * @param permissions the permissions level to grant to the repository collaborators | |
| 41 | * @param creationTarget determines who gets repositories: STUDENTS_ONLY (default), STAFF_ONLY, or | |
| 42 | * STUDENTS_AND_STAFF | |
| 43 | * @return the {@link edu.ucsb.cs156.frontiers.entities.Job Job} started to create the repos. | |
| 44 | */ | |
| 45 | @PostMapping("/createRepos") | |
| 46 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 47 | public Job createRepos( | |
| 48 | @RequestParam Long courseId, | |
| 49 | @RequestParam String repoPrefix, | |
| 50 | @RequestParam Optional<Boolean> isPrivate, | |
| 51 | @RequestParam RepositoryPermissions permissions, | |
| 52 | @RequestParam Optional<RepositoryCreationTarget> creationTarget) { | |
| 53 | Course course = | |
| 54 | courseRepository | |
| 55 | .findById(courseId) | |
| 56 |
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)); |
| 57 |
2
1. createRepos : negated conditional → KILLED 2. createRepos : negated conditional → KILLED |
if (course.getOrgName() == null || course.getInstallationId() == null) { |
| 58 | throw new NoLinkedOrganizationException(course.getCourseName()); | |
| 59 | } else { | |
| 60 | CreateStudentRepositoriesJob job = | |
| 61 | CreateStudentRepositoriesJob.builder() | |
| 62 | .repositoryPrefix(repoPrefix) | |
| 63 | .isPrivate(isPrivate.orElse(false)) | |
| 64 | .repositoryService(repositoryService) | |
| 65 | .course(course) | |
| 66 | .permissions(permissions) | |
| 67 | .creationTarget(creationTarget.orElse(RepositoryCreationTarget.STUDENTS_ONLY)) | |
| 68 | .build(); | |
| 69 |
1
1. createRepos : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RepositoryController::createRepos → KILLED |
return jobService.runAsJob(job); |
| 70 | } | |
| 71 | } | |
| 72 | } | |
Mutations | ||
| 56 |
1.1 |
|
| 57 |
1.1 2.2 |
|
| 69 |
1.1 |