| 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 OrganizationLinkerService organizationLinkerService; | |
| 28 | private final CourseRepository courseRepository; | |
| 29 | private final JobService jobService; | |
| 30 | ||
| 31 | public GithubGraphQLController( | |
| 32 | @Autowired GithubGraphQLService gitHubGraphQLService, | |
| 33 | @Autowired OrganizationLinkerService organizationLinkerService, | |
| 34 | @Autowired CourseRepository courseRepository, | |
| 35 | JobService jobService) { | |
| 36 | this.githubGraphQLService = gitHubGraphQLService; | |
| 37 | this.organizationLinkerService = organizationLinkerService; | |
| 38 | this.courseRepository = courseRepository; | |
| 39 | this.jobService = jobService; | |
| 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 | /** | |
| 77 | * Return the default base repository permission for the course's linked GitHub organization. | |
| 78 | * | |
| 79 | * @param courseId the id of the course whose installation is being used for credentials | |
| 80 | * @return the organization's default repository permission (e.g. none, read) | |
| 81 | */ | |
| 82 | @Operation(summary = "Get default base repository permission for course organization") | |
| 83 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 84 | @GetMapping("defaultbasepermission") | |
| 85 | public String getDefaultBasePermission(@Parameter Long courseId) throws Exception { | |
| 86 | log.info("getDefaultBasePermission called with courseId: {}", courseId); | |
| 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 | String result = this.organizationLinkerService.getDefaultRepositoryPermission(course); | |
| 95 | ||
| 96 | log.info("Result from getDefaultRepositoryPermission: {}", result); | |
| 97 | ||
| 98 |
1
1. getDefaultBasePermission : replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getDefaultBasePermission → KILLED |
return result; |
| 99 | } | |
| 100 | ||
| 101 | /** | |
| 102 | * Return default branch name for a given repository. | |
| 103 | * | |
| 104 | * @param courseId the id of the course whose installation is being used for credentails | |
| 105 | * @param owner the owner of the repository | |
| 106 | * @param repo the name of the repository | |
| 107 | * @return the default branch name | |
| 108 | */ | |
| 109 | @Operation(summary = "Get commits") | |
| 110 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 111 | @GetMapping("commits") | |
| 112 | public String getCommits( | |
| 113 | @Parameter Long courseId, | |
| 114 | @Parameter String owner, | |
| 115 | @Parameter String repo, | |
| 116 | @Parameter String branch, | |
| 117 | @Parameter Integer first, | |
| 118 | @RequestParam(name = "after", required = false) @Parameter String after) | |
| 119 | throws Exception { | |
| 120 | log.info( | |
| 121 | "getCommits called with courseId: {}, owner: {}, repo: {}, branch: {}, first: {}, after: {} ", | |
| 122 | courseId, | |
| 123 | owner, | |
| 124 | repo, | |
| 125 | branch, | |
| 126 | first, | |
| 127 | after); | |
| 128 | Course course = | |
| 129 | courseRepository | |
| 130 | .findById(courseId) | |
| 131 |
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)); |
| 132 | ||
| 133 | log.info("Found course: {}", course); | |
| 134 | ||
| 135 | log.info("Current user is authorized to access course: {}", course.getId()); | |
| 136 | ||
| 137 | String result = this.githubGraphQLService.getCommits(course, owner, repo, branch, first, after); | |
| 138 | ||
| 139 | log.info("Result from getCommits: {}", result); | |
| 140 | ||
| 141 |
1
1. getCommits : replaced return value with "" for edu/ucsb/cs156/frontiers/controllers/GithubGraphQLController::getCommits → KILLED |
return result; |
| 142 | } | |
| 143 | } | |
Mutations | ||
| 63 |
1.1 |
|
| 73 |
1.1 |
|
| 90 |
1.1 |
|
| 98 |
1.1 |
|
| 131 |
1.1 |
|
| 141 |
1.1 |