| 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.RepositoryService.GithubRepository; | |
| 7 | import edu.ucsb.cs156.jobs.services.JobContext; | |
| 8 | import edu.ucsb.cs156.jobs.services.JobContextConsumer; | |
| 9 | import java.util.List; | |
| 10 | import java.util.Optional; | |
| 11 | import lombok.Builder; | |
| 12 | ||
| 13 | @Builder | |
| 14 | public class DeleteRepoJob implements JobContextConsumer { | |
| 15 | Long courseId; | |
| 16 | String prefix; | |
| 17 | CourseRepository courseRepository; | |
| 18 | RepositoryService repositoryService; | |
| 19 | ||
| 20 | @Override | |
| 21 | public String getScopeType() { | |
| 22 |
1
1. getScopeType : replaced return value with "" for edu/ucsb/cs156/frontiers/jobs/DeleteRepoJob::getScopeType → KILLED |
return "course"; |
| 23 | } | |
| 24 | ||
| 25 | @Override | |
| 26 | public Long getScopeId() { | |
| 27 |
1
1. getScopeId : replaced Long return value with 0L for edu/ucsb/cs156/frontiers/jobs/DeleteRepoJob::getScopeId → KILLED |
return courseId; |
| 28 | } | |
| 29 | ||
| 30 | @Override | |
| 31 | public void accept(JobContext ctx) throws Exception { | |
| 32 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log(String.format("Starting delete repository job for course ID: %s", courseId)); |
| 33 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log(String.format("prefix=%s", prefix)); |
| 34 | ||
| 35 | Optional<Course> courseOpt = courseRepository.findById(courseId); | |
| 36 |
1
1. accept : negated conditional → KILLED |
if (courseOpt.isEmpty()) { |
| 37 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log(String.format("ERROR: Course with ID %s not found", courseId)); |
| 38 | return; | |
| 39 | } | |
| 40 | ||
| 41 | Course course = courseOpt.get(); | |
| 42 |
2
1. accept : negated conditional → KILLED 2. accept : negated conditional → KILLED |
if (course.getOrgName() == null || course.getInstallationId() == null) { |
| 43 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("ERROR: Course has no linked GitHub organization"); |
| 44 | return; | |
| 45 | } | |
| 46 | ||
| 47 | List<GithubRepository> repositories; | |
| 48 | int errors = 0; | |
| 49 | try { | |
| 50 | repositories = repositoryService.getRepositoriesMatchingPrefix(course, prefix); | |
| 51 | } catch (Exception e) { | |
| 52 | ctx.log(String.format("ERROR: Failed to list repositories: %s", e.getMessage())); | |
| 53 |
1
1. accept : Changed increment from 1 to -1 → KILLED |
errors++; |
| 54 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log(String.format("Summary: found=0, deleted=0, retained=0, errors=%d", errors)); |
| 55 | return; | |
| 56 | } | |
| 57 | ||
| 58 | int deleted = 0; | |
| 59 | int retained = 0; | |
| 60 | ||
| 61 | for (GithubRepository repository : repositories) { | |
| 62 | try { | |
| 63 | boolean deletedRepository = | |
| 64 | repositoryService.deleteRepositoryIfEmpty(course, repository.name()); | |
| 65 |
1
1. accept : negated conditional → KILLED |
if (deletedRepository) { |
| 66 |
1
1. accept : Changed increment from 1 to -1 → KILLED |
deleted++; |
| 67 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log(String.format("Deleted empty repository: %s", repository.name())); |
| 68 | } else { | |
| 69 |
1
1. accept : Changed increment from 1 to -1 → KILLED |
retained++; |
| 70 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log(String.format("Retained repository with commits: %s", repository.name())); |
| 71 | } | |
| 72 | } catch (Exception e) { | |
| 73 |
1
1. accept : Changed increment from 1 to -1 → KILLED |
errors++; |
| 74 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log( |
| 75 | String.format( | |
| 76 | "ERROR: Failed to delete/check repository %s: %s", | |
| 77 | repository.name(), e.getMessage())); | |
| 78 | } | |
| 79 | } | |
| 80 | ||
| 81 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log( |
| 82 | String.format( | |
| 83 | "Summary: found=%d, deleted=%d, retained=%d, errors=%d", | |
| 84 | repositories.size(), deleted, retained, errors)); | |
| 85 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Done"); |
| 86 | } | |
| 87 | } | |
Mutations | ||
| 22 |
1.1 |
|
| 27 |
1.1 |
|
| 32 |
1.1 |
|
| 33 |
1.1 |
|
| 36 |
1.1 |
|
| 37 |
1.1 |
|
| 42 |
1.1 2.2 |
|
| 43 |
1.1 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |
|
| 65 |
1.1 |
|
| 66 |
1.1 |
|
| 67 |
1.1 |
|
| 69 |
1.1 |
|
| 70 |
1.1 |
|
| 73 |
1.1 |
|
| 74 |
1.1 |
|
| 81 |
1.1 |
|
| 85 |
1.1 |