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
  /**
73
   * Return default branch name for a given repository.
74
   *
75
   * @param courseId the id of the course whose installation is being used for credentails
76
   * @param owner the owner of the repository
77
   * @param repo the name of the repository
78
   * @return the default branch name
79
   */
80
  @Operation(summary = "Get commits")
81
  @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)")
82
  @GetMapping("commits")
83
  public String getCommits(
84
      @Parameter Long courseId,
85
      @Parameter String owner,
86
      @Parameter String repo,
87
      @Parameter String branch,
88
      @Parameter Integer first,
89
      @RequestParam(name = "after", required = false) @Parameter String after)
90
      throws Exception {
91
    log.info(
92
        "getCommits called with courseId: {}, owner: {}, repo: {}, branch: {}, first: {}, after: {} ",
93
        courseId,
94
        owner,
95
        repo,
96
        branch,
97
        first,
98
        after);
99
    Course course =
100
        courseRepository
101
            .findById(courseId)
102 1 1. lambda$getCommits$1 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::lambda$getCommits$1 → KILLED
            .orElseThrow(() -> new EntityNotFoundException(Course.class, courseId));
103
104
    log.info("Found course: {}", course);
105
106
    log.info("Current user is authorized to access course: {}", course.getId());
107
108
    String result = this.githubGraphQLService.getCommits(course, owner, repo, branch, first, after);
109
110
    log.info("Result from getCommits: {}", result);
111
112 1 1. getCommits : replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getCommits → KILLED
    return result;
113
  }
114
}

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

102

1.1
Location : lambda$getCommits$1
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$1 → KILLED

112

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