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.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 OrganizationLinkerService organizationLinkerService;
27
  private final CourseRepository courseRepository;
28
  private final JobService jobService;
29
30
  public GithubGraphQLController(
31
      @Autowired GithubGraphQLService gitHubGraphQLService,
32
      @Autowired OrganizationLinkerService organizationLinkerService,
33
      @Autowired CourseRepository courseRepository,
34
      JobService jobService) {
35
    this.githubGraphQLService = gitHubGraphQLService;
36
    this.organizationLinkerService = organizationLinkerService;
37
    this.courseRepository = courseRepository;
38
    this.jobService = jobService;
39
  }
40
41
  /**
42
   * Return default branch name for a given repository.
43
   *
44
   * @param courseId the id of the course whose installation is being used for credentails
45
   * @param owner the owner of the repository
46
   * @param repo the name of the repository
47
   * @return the default branch name
48
   */
49
  @Operation(summary = "Get default branch name")
50
  @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)")
51
  @GetMapping("defaultBranchName")
52
  public String getDefaultBranchName(
53
      @Parameter Long courseId, @Parameter String owner, @Parameter String repo) throws Exception {
54
    log.info(
55
        "getDefaultBranchName called with courseId: {}, owner: {}, repo: {}",
56
        courseId,
57
        owner,
58
        repo);
59
    Course course =
60
        courseRepository
61
            .findById(courseId)
62 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));
63
64
    log.info("Found course: {}", course);
65
66
    log.info("Current user is authorized to access course: {}", course.getId());
67
68
    String result = this.githubGraphQLService.getDefaultBranchName(course, owner, repo);
69
70
    log.info("Result from getDefaultBranchName: {}", result);
71
72 1 1. getDefaultBranchName : replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getDefaultBranchName → KILLED
    return result;
73
  }
74
75
  /**
76
   * Return default base permission for the GitHub organization associated with a course.
77
   *
78
   * @param courseId the id of the course whose installation is being used for credentials
79
   * @return the default base permission
80
   */
81
  @Operation(summary = "Get default base permission")
82
  @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)")
83
  @GetMapping("defaultbasepermission")
84
  public String getDefaultBasePermission(@Parameter Long courseId) throws Exception {
85
    log.info("getDefaultBasePermission called with courseId: {}", courseId);
86
87
    Course course =
88
        courseRepository
89
            .findById(courseId)
90 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));
91
92
    log.info("Found course: {}", course);
93
94
    log.info("Current user is authorized to access course: {}", course.getId());
95
96
    String result = this.githubGraphQLService.getDefaultBasePermission(course, course.getOrgName());
97
98
    log.info("Result from getDefaultBasePermission: {}", result);
99
100 1 1. getDefaultBasePermission : replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getDefaultBasePermission → KILLED
    return result;
101
  }
102
103
  /**
104
   * Return commits for a given repository.
105
   *
106
   * @param courseId the id of the course whose installation is being used for credentails
107
   * @param owner the owner of the repository
108
   * @param repo the name of the repository
109
   * @param branch the branch name
110
   * @param first the number of commits to fetch
111
   * @param after pagination cursor
112
   * @return commits as JSON
113
   */
114
  @Operation(summary = "Get commits")
115
  @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)")
116
  @GetMapping("commits")
117
  public String getCommits(
118
      @Parameter Long courseId,
119
      @Parameter String owner,
120
      @Parameter String repo,
121
      @Parameter String branch,
122
      @Parameter Integer first,
123
      @Parameter String after)
124
      throws Exception {
125
    log.info(
126
        "getCommits called with courseId: {}, owner: {}, repo: {}, branch: {}, first: {}, after: {} ",
127
        courseId,
128
        owner,
129
        repo,
130
        branch,
131
        first,
132
        after);
133
    Course course =
134
        courseRepository
135
            .findById(courseId)
136 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));
137
138
    log.info("Found course: {}", course);
139
140
    log.info("Current user is authorized to access course: {}", course.getId());
141
142
    String result = this.githubGraphQLService.getCommits(course, owner, repo, branch, first, after);
143
144
    log.info("Result from getCommits: {}", result);
145
146 1 1. getCommits : replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getCommits → KILLED
    return result;
147
  }
148
}

Mutations

62

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

72

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

90

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

100

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

136

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

146

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