GithubGraphQLController.java

1
package edu.ucsb.cs156.frontiers.controllers;
2
3
import edu.ucsb.cs156.frontiers.entities.Course;
4
import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.frontiers.repositories.CourseRepository;
6
import edu.ucsb.cs156.frontiers.services.GithubGraphQLService;
7
import edu.ucsb.cs156.frontiers.services.jobs.JobService;
8
import io.swagger.v3.oas.annotations.Operation;
9
import io.swagger.v3.oas.annotations.Parameter;
10
import io.swagger.v3.oas.annotations.tags.Tag;
11
import lombok.extern.slf4j.Slf4j;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.security.access.prepost.PreAuthorize;
14
import org.springframework.web.bind.annotation.GetMapping;
15
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestParam;
17
import org.springframework.web.bind.annotation.RestController;
18
19
@Tag(name = "GithubGraphQL")
20
@RequestMapping("/api/github/graphql/")
21
@RestController
22
@Slf4j
23
public class GithubGraphQLController extends ApiController {
24
25
  private final GithubGraphQLService githubGraphQLService;
26
  private final CourseRepository courseRepository;
27
  private final JobService jobService;
28
29
  public GithubGraphQLController(
30
      @Autowired GithubGraphQLService gitHubGraphQLService,
31
      @Autowired CourseRepository courseRepository,
32
      JobService jobService) {
33
    this.githubGraphQLService = gitHubGraphQLService;
34
    this.courseRepository = courseRepository;
35
    this.jobService = jobService;
36
  }
37
38
  /**
39
   * Return default branch name for a given repository.
40
   *
41
   * @param courseId the id of the course whose installation is being used for credentails
42
   * @param owner the owner of the repository
43
   * @param repo the name of the repository
44
   * @return the default branch name
45
   */
46
  @Operation(summary = "Get default branch name")
47
  @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)")
48
  @GetMapping("defaultBranchName")
49
  public String getDefaultBranchName(
50
      @Parameter Long courseId, @Parameter String owner, @Parameter String repo) throws Exception {
51
    log.info(
52
        "getDefaultBranchName called with courseId: {}, owner: {}, repo: {}",
53
        courseId,
54
        owner,
55
        repo);
56
    Course course =
57
        courseRepository
58
            .findById(courseId)
59 1 1. lambda$getDefaultBranchName$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::lambda$getDefaultBranchName$0 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(Course.class, courseId));
60
61
    log.info("Found course: {}", course);
62
63
    log.info("Current user is authorized to access course: {}", course.getId());
64
65
    String result = this.githubGraphQLService.getDefaultBranchName(course, owner, repo);
66
67
    log.info("Result from getDefaultBranchName: {}", result);
68
69 1 1. getDefaultBranchName : replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getDefaultBranchName → KILLED
    return result;
70
  }
71
72
  @Operation(summary = "Get default base permission for course organization")
73
  @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)")
74
  @GetMapping("defaultbasepermission")
75
  public String getDefaultBasePermission(@RequestParam @Parameter Long courseId) throws Exception {
76
    log.info("getDefaultBasePermission called with courseId: {}", courseId);
77
    Course course =
78
        courseRepository
79
            .findById(courseId)
80 1 1. lambda$getDefaultBasePermission$1 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::lambda$getDefaultBasePermission$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(Course.class, courseId));
81
    log.info("Found course: {}", course);
82
    String result = this.githubGraphQLService.getDefaultBasePermission(course);
83
    log.info("Result from getDefaultBasePermission: {}", result);
84 1 1. getDefaultBasePermission : replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getDefaultBasePermission → KILLED
    return result;
85
  }
86
87
  /**
88
   * Return default branch name for a given repository.
89
   *
90
   * @param courseId the id of the course whose installation is being used for credentails
91
   * @param owner the owner of the repository
92
   * @param repo the name of the repository
93
   * @return the default branch name
94
   */
95
  @Operation(summary = "Get commits")
96
  @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)")
97
  @GetMapping("commits")
98
  public String getCommits(
99
      @Parameter Long courseId,
100
      @Parameter String owner,
101
      @Parameter String repo,
102
      @Parameter String branch,
103
      @Parameter Integer first,
104
      @RequestParam(name = "after", required = false) @Parameter String after)
105
      throws Exception {
106
    log.info(
107
        "getCommits called with courseId: {}, owner: {}, repo: {}, branch: {}, first: {}, after: {} ",
108
        courseId,
109
        owner,
110
        repo,
111
        branch,
112
        first,
113
        after);
114
    Course course =
115
        courseRepository
116
            .findById(courseId)
117 1 1. lambda$getCommits$2 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::lambda$getCommits$2 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(Course.class, courseId));
118
119
    log.info("Found course: {}", course);
120
121
    log.info("Current user is authorized to access course: {}", course.getId());
122
123
    String result = this.githubGraphQLService.getCommits(course, owner, repo, branch, first, after);
124
125
    log.info("Result from getCommits: {}", result);
126
127 1 1. getCommits : replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getCommits → KILLED
    return result;
128
  }
129
}

Mutations

59

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

69

1.1
Location : getDefaultBranchName
Killed by : edu.ucsb.cs156.frontiers.controllers.GithubGraphQLControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.GithubGraphQLControllerTests]/[method:test_getDefaultMainBranch_happyPath_Admin()]
replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getDefaultBranchName → KILLED

80

1.1
Location : lambda$getDefaultBasePermission$1
Killed by : edu.ucsb.cs156.frontiers.controllers.GithubGraphQLControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.GithubGraphQLControllerTests]/[method:test_getDefaultBasePermission_courseNotFound()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::lambda$getDefaultBasePermission$1 → KILLED

84

1.1
Location : getDefaultBasePermission
Killed by : edu.ucsb.cs156.frontiers.controllers.GithubGraphQLControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.GithubGraphQLControllerTests]/[method:test_getDefaultBasePermission_happyPath_Instructor()]
replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getDefaultBasePermission → KILLED

117

1.1
Location : lambda$getCommits$2
Killed by : edu.ucsb.cs156.frontiers.controllers.GithubGraphQLControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.GithubGraphQLControllerTests]/[method:test_getCommits_courseNotFound()]
replaced return value with null for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::lambda$getCommits$2 → KILLED

127

1.1
Location : getCommits
Killed by : edu.ucsb.cs156.frontiers.controllers.GithubGraphQLControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.controllers.GithubGraphQLControllerTests]/[method:test_getCommits_happyPath_instructor()]
replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getCommits → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0