| 1 | package edu.ucsb.cs156.frontiers.jobs; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.Course; | |
| 4 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 5 | import edu.ucsb.cs156.frontiers.services.RepositoryService; | |
| 6 | import edu.ucsb.cs156.frontiers.services.jobs.JobContext; | |
| 7 | import edu.ucsb.cs156.frontiers.services.jobs.JobContextConsumer; | |
| 8 | import java.util.List; | |
| 9 | import java.util.Optional; | |
| 10 | import lombok.Builder; | |
| 11 | ||
| 12 | @Builder | |
| 13 | public class DeleteReposJob implements JobContextConsumer { | |
| 14 | Long courseId; | |
| 15 | String prefix; | |
| 16 | CourseRepository courseRepository; | |
| 17 | RepositoryService repositoryService; | |
| 18 | ||
| 19 | @Builder.Default long sleepMillis = 100L; | |
| 20 | ||
| 21 | @Override | |
| 22 | public Course getCourse() { | |
| 23 |
2
1. getCourse : negated conditional → KILLED 2. getCourse : negated conditional → KILLED |
if (courseId == null || courseRepository == null) { |
| 24 | return null; | |
| 25 | } | |
| 26 |
1
1. getCourse : replaced return value with null for edu/ucsb/cs156/frontiers/jobs/DeleteReposJob::getCourse → KILLED |
return courseRepository.findById(courseId).orElse(null); |
| 27 | } | |
| 28 | ||
| 29 | @Override | |
| 30 | public void accept(JobContext ctx) throws Exception { | |
| 31 | Optional<Course> courseOpt = courseRepository.findById(courseId); | |
| 32 |
1
1. accept : negated conditional → KILLED |
if (courseOpt.isEmpty()) { |
| 33 | ctx.log("ERROR: Course with ID " + courseId + " not found"); | |
| 34 | return; | |
| 35 | } | |
| 36 | ||
| 37 | Course course = courseOpt.get(); | |
| 38 |
2
1. accept : negated conditional → KILLED 2. accept : negated conditional → KILLED |
if (course.getOrgName() == null || course.getInstallationId() == null) { |
| 39 | ctx.log("ERROR: Course has no linked GitHub organization"); | |
| 40 | return; | |
| 41 | } | |
| 42 | ||
| 43 | List<String> repos = repositoryService.getRepositoryNamesWithPrefix(course, prefix); | |
| 44 | ctx.log(repos.size() + " repos found with prefix " + prefix); | |
| 45 | ||
| 46 | int reposDeleted = 0; | |
| 47 | int reposRetained = 0; | |
| 48 | int repoErrors = 0; | |
| 49 | ||
| 50 | for (String repoName : repos) { | |
| 51 | try { | |
| 52 |
1
1. accept : negated conditional → KILLED |
if (repositoryService.repositoryHasCommits(course, repoName)) { |
| 53 |
1
1. accept : Changed increment from 1 to -1 → KILLED |
reposRetained++; |
| 54 | ctx.log("Repo " + repoName + " not deleted; commits exist."); | |
| 55 | } else { | |
| 56 |
1
1. accept : removed call to edu/ucsb/cs156/frontiers/services/RepositoryService::deleteRepository → KILLED |
repositoryService.deleteRepository(course, repoName); |
| 57 |
1
1. accept : Changed increment from 1 to -1 → KILLED |
reposDeleted++; |
| 58 | } | |
| 59 | } catch (Exception e) { | |
| 60 |
1
1. accept : Changed increment from 1 to -1 → KILLED |
repoErrors++; |
| 61 | ctx.log("ERROR deleting repo " + repoName + ": " + e.getMessage()); | |
| 62 | } | |
| 63 | ||
| 64 |
2
1. accept : negated conditional → KILLED 2. accept : changed conditional boundary → KILLED |
if (sleepMillis >= 1) { |
| 65 |
1
1. accept : removed call to java/lang/Thread::sleep → KILLED |
Thread.sleep(sleepMillis); |
| 66 | } | |
| 67 | } | |
| 68 | ||
| 69 | ctx.log(reposDeleted + " repos deleted"); | |
| 70 | ctx.log(reposRetained + " repos retained"); | |
| 71 | ctx.log(repoErrors + " errors"); | |
| 72 | } | |
| 73 | } | |
Mutations | ||
| 23 |
1.1 2.2 |
|
| 26 |
1.1 |
|
| 32 |
1.1 |
|
| 38 |
1.1 2.2 |
|
| 52 |
1.1 |
|
| 53 |
1.1 |
|
| 56 |
1.1 |
|
| 57 |
1.1 |
|
| 60 |
1.1 |
|
| 64 |
1.1 2.2 |
|
| 65 |
1.1 |