RepositoryController.java

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.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 every RosterStudent with a linked user with a GitHub
35
   * account.
36
   *
37
   * @param courseId ID of course to create repos for
38
   * @param repoPrefix each repo created will begin with this prefix, followed by a dash and the
39
   *     student's GitHub username
40
   * @param isPrivate determines whether the repository being created is private
41
   * @return the {@link edu.ucsb.cs156.frontiers.entities.Job Job} started to create the repos.
42
   */
43
  @PostMapping("/createRepos")
44
  @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)")
45
  public Job createRepos(
46
      @RequestParam Long courseId,
47
      @RequestParam String repoPrefix,
48
      @RequestParam Optional<Boolean> isPrivate,
49
      @RequestParam RepositoryPermissions permissions,
50
      @RequestParam(required = false, defaultValue = "STUDENTS_ONLY")
51
          RepositoryCreationOption creationOption) {
52
    Course course =
53
        courseRepository
54
            .findById(courseId)
55 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));
56 2 1. createRepos : negated conditional → KILLED
2. createRepos : negated conditional → KILLED
    if (course.getOrgName() == null || course.getInstallationId() == null) {
57
      throw new NoLinkedOrganizationException(course.getCourseName());
58
    } else {
59
      CreateStudentOrStaffRepositoriesJob job =
60
          CreateStudentOrStaffRepositoriesJob.builder()
61
              .repositoryPrefix(repoPrefix)
62
              .isPrivate(isPrivate.orElse(false))
63
              .repositoryService(repositoryService)
64
              .course(course)
65
              .permissions(permissions)
66
              .creationOption(creationOption)
67
              .build();
68 1 1. createRepos : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RepositoryController::createRepos → KILLED
      return jobService.runAsJob(job);
69
    }
70
  }
71
}

Mutations

55

1.1
Location : lambda$createRepos$0
Killed by : edu.ucsb.cs156.frontiers.controllers.RepositoryControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.RepositoryControllerTests]/[method:notFound()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RepositoryController::lambda$createRepos$0 → KILLED

56

1.1
Location : createRepos
Killed by : edu.ucsb.cs156.frontiers.controllers.RepositoryControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.RepositoryControllerTests]/[method:just_no_install_id()]
negated conditional → KILLED

2.2
Location : createRepos
Killed by : edu.ucsb.cs156.frontiers.controllers.RepositoryControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.RepositoryControllerTests]/[method:job_actually_fires_with_instructor()]
negated conditional → KILLED

68

1.1
Location : createRepos
Killed by : edu.ucsb.cs156.frontiers.controllers.RepositoryControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.RepositoryControllerTests]/[method:job_actually_fires_with_instructor()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/RepositoryController::createRepos → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0