| 1 | package edu.ucsb.cs156.frontiers.jobs; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.Course; | |
| 4 | import edu.ucsb.cs156.frontiers.entities.RosterStudent; | |
| 5 | import edu.ucsb.cs156.frontiers.entities.Team; | |
| 6 | import edu.ucsb.cs156.frontiers.entities.TeamMember; | |
| 7 | import edu.ucsb.cs156.frontiers.enums.TeamStatus; | |
| 8 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 9 | import edu.ucsb.cs156.frontiers.repositories.TeamMemberRepository; | |
| 10 | import edu.ucsb.cs156.frontiers.repositories.TeamRepository; | |
| 11 | import edu.ucsb.cs156.frontiers.services.GithubTeamService; | |
| 12 | import edu.ucsb.cs156.frontiers.services.GithubTeamService.GithubTeamInfo; | |
| 13 | import edu.ucsb.cs156.jobs.services.JobContext; | |
| 14 | import edu.ucsb.cs156.jobs.services.JobContextConsumer; | |
| 15 | import java.util.Objects; | |
| 16 | import java.util.Optional; | |
| 17 | import lombok.Builder; | |
| 18 | ||
| 19 | @Builder | |
| 20 | public class PushTeamsToGithubJob implements JobContextConsumer { | |
| 21 | Long courseId; | |
| 22 | CourseRepository courseRepository; | |
| 23 | TeamRepository teamRepository; | |
| 24 | TeamMemberRepository teamMemberRepository; | |
| 25 | GithubTeamService githubTeamService; | |
| 26 | ||
| 27 | @Override | |
| 28 | public String getScopeType() { | |
| 29 |
1
1. getScopeType : replaced return value with "" for edu/ucsb/cs156/frontiers/jobs/PushTeamsToGithubJob::getScopeType → KILLED |
return "course"; |
| 30 | } | |
| 31 | ||
| 32 | @Override | |
| 33 | public Long getScopeId() { | |
| 34 |
1
1. getScopeId : replaced Long return value with 0L for edu/ucsb/cs156/frontiers/jobs/PushTeamsToGithubJob::getScopeId → KILLED |
return courseId; |
| 35 | } | |
| 36 | ||
| 37 | @Override | |
| 38 | public void accept(JobContext ctx) throws Exception { | |
| 39 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Starting push teams to GitHub job for course ID: " + courseId); |
| 40 | ||
| 41 | // Get the course | |
| 42 | Optional<Course> courseOpt = courseRepository.findById(courseId); | |
| 43 |
1
1. accept : negated conditional → KILLED |
if (courseOpt.isEmpty()) { |
| 44 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("ERROR: Course with ID " + courseId + " not found"); |
| 45 | return; | |
| 46 | } | |
| 47 | Course course = courseOpt.get(); | |
| 48 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Processing course: " + course.getCourseName() + " (org: " + course.getOrgName() + ")"); |
| 49 | ||
| 50 |
2
1. accept : negated conditional → KILLED 2. accept : negated conditional → KILLED |
if (course.getOrgName() == null || course.getInstallationId() == null) { |
| 51 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("ERROR: Course has no linked GitHub organization"); |
| 52 | return; | |
| 53 | } | |
| 54 | ||
| 55 | // Get the organization id | |
| 56 | ||
| 57 | Integer orgId = null; | |
| 58 | try { | |
| 59 | orgId = githubTeamService.getOrgId(course.getOrgName(), course); | |
| 60 | } catch (Exception e) { | |
| 61 | throw new IllegalStateException( | |
| 62 | "Failed to get organization ID for org: " + course.getOrgName() + " - " + e.getMessage(), | |
| 63 | e); | |
| 64 | } | |
| 65 | ||
| 66 | // Get all teams for this course | |
| 67 | Iterable<Team> teams = teamRepository.findByCourseId(courseId); | |
| 68 | ||
| 69 | // First pass: Create teams on GitHub and update githubTeamId | |
| 70 | for (Team team : teams) { | |
| 71 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Processing team: " + team.getName()); |
| 72 | try { | |
| 73 | GithubTeamInfo githubTeamInfo = githubTeamService.createOrGetTeamInfo(team, course); | |
| 74 |
1
1. accept : negated conditional → KILLED |
if (!githubTeamInfo.id().equals(team.getGithubTeamId()) |
| 75 |
1
1. accept : negated conditional → KILLED |
|| !Objects.equals(githubTeamInfo.slug(), team.getGithubTeamSlug())) { |
| 76 |
1
1. accept : removed call to edu/ucsb/cs156/frontiers/entities/Team::setGithubTeamId → KILLED |
team.setGithubTeamId(githubTeamInfo.id()); |
| 77 |
1
1. accept : removed call to edu/ucsb/cs156/frontiers/entities/Team::setGithubTeamSlug → KILLED |
team.setGithubTeamSlug(githubTeamInfo.slug()); |
| 78 | teamRepository.save(team); | |
| 79 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log( |
| 80 | "Updated team '" + team.getName() + "' with GitHub team ID: " + githubTeamInfo.id()); | |
| 81 | } else { | |
| 82 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log( |
| 83 | "Team '" | |
| 84 | + team.getName() | |
| 85 | + "' already has correct GitHub team ID: " | |
| 86 | + githubTeamInfo.id()); | |
| 87 | } | |
| 88 | } catch (Exception e) { | |
| 89 | ctx.log("ERROR: Failed to create/get team '" + team.getName() + "': " + e.getMessage()); | |
| 90 | } | |
| 91 | } | |
| 92 | ||
| 93 | // Second pass: Process team members | |
| 94 | for (Team team : teams) { | |
| 95 |
1
1. accept : negated conditional → KILLED |
if (team.getGithubTeamId() == null) { |
| 96 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Skipping team members for '" + team.getName() + "' - no GitHub team ID"); |
| 97 | continue; | |
| 98 | } | |
| 99 | ||
| 100 |
1
1. accept : negated conditional → KILLED |
if (Boolean.TRUE.equals(team.getIsStaffTeam())) { |
| 101 |
1
1. accept : removed call to edu/ucsb/cs156/frontiers/jobs/StaffTeamGithubSync::addStaffMembers → KILLED |
StaffTeamGithubSync.addStaffMembers(ctx, course, team, orgId, githubTeamService); |
| 102 | continue; | |
| 103 | } | |
| 104 | ||
| 105 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Processing members for team: " + team.getName()); |
| 106 | for (TeamMember teamMember : team.getTeamMembers()) { | |
| 107 | RosterStudent student = teamMember.getRosterStudent(); | |
| 108 |
1
1. accept : negated conditional → KILLED |
if (student.getGithubLogin() == null) { |
| 109 | // Update status to NO_GITHUB_ID | |
| 110 |
1
1. accept : removed call to edu/ucsb/cs156/frontiers/entities/TeamMember::setTeamStatus → KILLED |
teamMember.setTeamStatus(TeamStatus.NO_GITHUB_ID); |
| 111 | teamMemberRepository.save(teamMember); | |
| 112 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log( |
| 113 | "Student " + student.getEmail() + " has no GitHub login - marked as NO_GITHUB_ID"); | |
| 114 | continue; | |
| 115 | } | |
| 116 | ||
| 117 | try { | |
| 118 | // Check current status | |
| 119 | TeamStatus currentStatus = | |
| 120 | githubTeamService.getTeamMembershipStatus( | |
| 121 | student.getGithubLogin(), team.getGithubTeamId(), course, orgId); | |
| 122 | ||
| 123 |
2
1. accept : negated conditional → KILLED 2. accept : negated conditional → KILLED |
if (currentStatus == TeamStatus.TEAM_MEMBER |
| 124 | || currentStatus == TeamStatus.TEAM_MAINTAINER) { | |
| 125 | // Already a member, just update the status | |
| 126 |
1
1. accept : removed call to edu/ucsb/cs156/frontiers/entities/TeamMember::setTeamStatus → KILLED |
teamMember.setTeamStatus(currentStatus); |
| 127 | teamMemberRepository.save(teamMember); | |
| 128 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log( |
| 129 | "Student " + student.getGithubLogin() + " already has status: " + currentStatus); | |
| 130 | } else { | |
| 131 | // Add as member | |
| 132 | TeamStatus newStatus = | |
| 133 | githubTeamService.addMemberToGithubTeam( | |
| 134 | student.getGithubLogin(), team.getGithubTeamId(), "member", course, orgId); | |
| 135 |
1
1. accept : removed call to edu/ucsb/cs156/frontiers/entities/TeamMember::setTeamStatus → KILLED |
teamMember.setTeamStatus(newStatus); |
| 136 | teamMemberRepository.save(teamMember); | |
| 137 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log( |
| 138 | "Added student " + student.getGithubLogin() + " to team with status: " + newStatus); | |
| 139 | } | |
| 140 | } catch (Exception e) { | |
| 141 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log( |
| 142 | "ERROR: Failed to process team member " | |
| 143 | + student.getGithubLogin() | |
| 144 | + " for team '" | |
| 145 | + team.getName() | |
| 146 | + "': " | |
| 147 | + e.getMessage()); | |
| 148 |
1
1. accept : removed call to edu/ucsb/cs156/frontiers/entities/TeamMember::setTeamStatus → KILLED |
teamMember.setTeamStatus(TeamStatus.NOT_ORG_MEMBER); |
| 149 | teamMemberRepository.save(teamMember); | |
| 150 | } | |
| 151 | } | |
| 152 | } | |
| 153 | ||
| 154 |
1
1. accept : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Completed push teams to GitHub job for course ID: " + courseId); |
| 155 | } | |
| 156 | } | |
Mutations | ||
| 29 |
1.1 |
|
| 34 |
1.1 |
|
| 39 |
1.1 |
|
| 43 |
1.1 |
|
| 44 |
1.1 |
|
| 48 |
1.1 |
|
| 50 |
1.1 2.2 |
|
| 51 |
1.1 |
|
| 71 |
1.1 |
|
| 74 |
1.1 |
|
| 75 |
1.1 |
|
| 76 |
1.1 |
|
| 77 |
1.1 |
|
| 79 |
1.1 |
|
| 82 |
1.1 |
|
| 95 |
1.1 |
|
| 96 |
1.1 |
|
| 100 |
1.1 |
|
| 101 |
1.1 |
|
| 105 |
1.1 |
|
| 108 |
1.1 |
|
| 110 |
1.1 |
|
| 112 |
1.1 |
|
| 123 |
1.1 2.2 |
|
| 126 |
1.1 |
|
| 128 |
1.1 |
|
| 135 |
1.1 |
|
| 137 |
1.1 |
|
| 141 |
1.1 |
|
| 148 |
1.1 |
|
| 154 |
1.1 |