| 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.RepositoryCreationOption; | |
| 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.CreateStudentOrStaffRepositoriesJob; | |
| 10 | import edu.ucsb.cs156.frontiers.jobs.CreateTeamRepositoriesJob; | |
| 11 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 12 | import edu.ucsb.cs156.frontiers.services.RepositoryService; | |
| 13 | import edu.ucsb.cs156.frontiers.services.jobs.JobService; | |
| 14 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 15 | import java.util.Optional; | |
| 16 | import org.springframework.beans.factory.annotation.Autowired; | |
| 17 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 19 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestParam; | |
| 21 | import org.springframework.web.bind.annotation.RestController; | |
| 22 | ||
| 23 | @Tag(name = "Repository Controller") | |
| 24 | @RestController | |
| 25 | @RequestMapping("/api/repos") | |
| 26 | public class RepositoryController extends ApiController { | |
| 27 | ||
| 28 | @Autowired RepositoryService repositoryService; | |
| 29 | ||
| 30 | @Autowired JobService jobService; | |
| 31 | ||
| 32 | @Autowired CourseRepository courseRepository; | |
| 33 | ||
| 34 | /** | |
| 35 | * Fires a job that creates a repo for every RosterStudent with a linked user with a GitHub | |
| 36 | * account. | |
| 37 | * | |
| 38 | * @param courseId ID of course to create repos for | |
| 39 | * @param repoPrefix each repo created will begin with this prefix, followed by a dash and the | |
| 40 | * student's GitHub username | |
| 41 | * @param isPrivate determines whether the repository being created is private | |
| 42 | * @return the {@link edu.ucsb.cs156.frontiers.entities.Job Job} started to create the repos. | |
| 43 | */ | |
| 44 | @PostMapping("/createRepos") | |
| 45 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 46 | public Job createRepos( | |
| 47 | @RequestParam Long courseId, | |
| 48 | @RequestParam String repoPrefix, | |
| 49 | @RequestParam Optional<Boolean> isPrivate, | |
| 50 | @RequestParam RepositoryPermissions permissions, | |
| 51 | @RequestParam(required = false, defaultValue = "STUDENTS_ONLY") | |
| 52 | RepositoryCreationOption creationOption) { | |
| 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 | CreateStudentOrStaffRepositoriesJob job = | |
| 61 | CreateStudentOrStaffRepositoriesJob.builder() | |
| 62 | .repositoryPrefix(repoPrefix) | |
| 63 | .isPrivate(isPrivate.orElse(false)) | |
| 64 | .repositoryService(repositoryService) | |
| 65 | .course(course) | |
| 66 | .permissions(permissions) | |
| 67 | .creationOption(creationOption) | |
| 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 | ||
| 73 | /** | |
| 74 | * Fires a job that creates team repos shared by all TeamMembers of each Team in a Course . | |
| 75 | * | |
| 76 | * @param courseId ID of course to create team repos for | |
| 77 | * @param repoPrefix each team repo created will begin with this prefix, followed by a dash and | |
| 78 | * the team's name | |
| 79 | * @param isPrivate determines whether the repository being created is private | |
| 80 | * @return the {@link edu.ucsb.cs156.frontiers.entities.Job Job} started to create the repos. | |
| 81 | */ | |
| 82 | @PostMapping("/createTeamRepos") | |
| 83 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 84 | public Job createTeamRepos( | |
| 85 | @RequestParam Long courseId, | |
| 86 | @RequestParam String repoPrefix, | |
| 87 | @RequestParam Optional<Boolean> isPrivate, | |
| 88 | @RequestParam RepositoryPermissions permissions) { | |
| 89 | Course course = | |
| 90 | courseRepository | |
| 91 | .findById(courseId) | |
| 92 |
1
1. lambda$createTeamRepos$1 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RepositoryController::lambda$createTeamRepos$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 93 |
2
1. createTeamRepos : negated conditional → KILLED 2. createTeamRepos : negated conditional → KILLED |
if (course.getOrgName() == null || course.getInstallationId() == null) { |
| 94 | throw new NoLinkedOrganizationException(course.getCourseName()); | |
| 95 | } else { | |
| 96 | CreateTeamRepositoriesJob job = | |
| 97 | CreateTeamRepositoriesJob.builder() | |
| 98 | .repositoryPrefix(repoPrefix) | |
| 99 | .isPrivate(isPrivate.orElse(false)) | |
| 100 | .repositoryService(repositoryService) | |
| 101 | .course(course) | |
| 102 | .permissions(permissions) | |
| 103 | .build(); | |
| 104 |
1
1. createTeamRepos : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RepositoryController::createTeamRepos → KILLED |
return jobService.runAsJob(job); |
| 105 | } | |
| 106 | } | |
| 107 | } | |
Mutations | ||
| 56 |
1.1 |
|
| 57 |
1.1 2.2 |
|
| 69 |
1.1 |
|
| 92 |
1.1 |
|
| 93 |
1.1 2.2 |
|
| 104 |
1.1 |