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