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

Mutations

63

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

73

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

84

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

88

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

121

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

131

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_Admin()]
replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getCommits → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0