| 1 | package edu.ucsb.cs156.frontiers.jobs; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.Course; | |
| 4 | import edu.ucsb.cs156.frontiers.entities.CourseStaff; | |
| 5 | import edu.ucsb.cs156.frontiers.entities.Team; | |
| 6 | import edu.ucsb.cs156.frontiers.enums.TeamStatus; | |
| 7 | import edu.ucsb.cs156.frontiers.services.GithubTeamService; | |
| 8 | import edu.ucsb.cs156.jobs.services.JobContext; | |
| 9 | import java.util.List; | |
| 10 | ||
| 11 | /** | |
| 12 | * Puts the course staff on the GitHub team of a staff team (see {@link Team#getIsStaffTeam()}). | |
| 13 | * Shared by the jobs that push teams to GitHub, so that a staff team is handled the same way | |
| 14 | * whether it was just created or is being pushed with all of the other teams. | |
| 15 | */ | |
| 16 | public final class StaffTeamGithubSync { | |
| 17 | ||
| 18 | private StaffTeamGithubSync() {} | |
| 19 | ||
| 20 | /** | |
| 21 | * Adds every member of the course staff who has a GitHub login to the team's GitHub team, as a | |
| 22 | * member, unless they are already on it. A staff member without a GitHub login, and a staff | |
| 23 | * member GitHub refuses, are logged and skipped; nothing is stored in Frontiers, since staff | |
| 24 | * members have no team member records. | |
| 25 | * | |
| 26 | * @param ctx the job context, for logging | |
| 27 | * @param course the course; its staff are the members of the team | |
| 28 | * @param team the staff team, which must already have a GitHub team id | |
| 29 | * @param orgId the GitHub id of the course's organization | |
| 30 | * @param githubTeamService the service that talks to GitHub | |
| 31 | */ | |
| 32 | public static void addStaffMembers( | |
| 33 | JobContext ctx, | |
| 34 | Course course, | |
| 35 | Team team, | |
| 36 | Integer orgId, | |
| 37 | GithubTeamService githubTeamService) { | |
| 38 |
1
1. addStaffMembers : negated conditional → KILLED |
List<CourseStaff> staff = course.getCourseStaff() == null ? List.of() : course.getCourseStaff(); |
| 39 |
1
1. addStaffMembers : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log( |
| 40 | "Processing staff members for staff team: " | |
| 41 | + team.getName() | |
| 42 | + " (" | |
| 43 | + staff.size() | |
| 44 | + " staff member(s))"); | |
| 45 | for (CourseStaff member : staff) { | |
| 46 | String login = member.getGithubLogin(); | |
| 47 |
1
1. addStaffMembers : negated conditional → KILLED |
if (login == null) { |
| 48 |
1
1. addStaffMembers : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Staff member " + member.getEmail() + " has no GitHub login - skipped"); |
| 49 | continue; | |
| 50 | } | |
| 51 | try { | |
| 52 | TeamStatus currentStatus = | |
| 53 | githubTeamService.getTeamMembershipStatus(login, team.getGithubTeamId(), course, orgId); | |
| 54 |
2
1. addStaffMembers : negated conditional → KILLED 2. addStaffMembers : negated conditional → KILLED |
if (currentStatus == TeamStatus.TEAM_MEMBER |
| 55 | || currentStatus == TeamStatus.TEAM_MAINTAINER) { | |
| 56 |
1
1. addStaffMembers : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Staff member " + login + " already has status: " + currentStatus); |
| 57 | } else { | |
| 58 | TeamStatus newStatus = | |
| 59 | githubTeamService.addMemberToGithubTeam( | |
| 60 | login, team.getGithubTeamId(), "member", course, orgId); | |
| 61 |
1
1. addStaffMembers : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log("Added staff member " + login + " to team with status: " + newStatus); |
| 62 | } | |
| 63 | } catch (Exception e) { | |
| 64 |
1
1. addStaffMembers : removed call to edu/ucsb/cs156/jobs/services/JobContext::log → KILLED |
ctx.log( |
| 65 | "ERROR: Failed to process staff member " | |
| 66 | + login | |
| 67 | + " for team '" | |
| 68 | + team.getName() | |
| 69 | + "': " | |
| 70 | + e.getMessage()); | |
| 71 | } | |
| 72 | } | |
| 73 | } | |
| 74 | } | |
Mutations | ||
| 38 |
1.1 |
|
| 39 |
1.1 |
|
| 47 |
1.1 |
|
| 48 |
1.1 |
|
| 54 |
1.1 2.2 |
|
| 56 |
1.1 |
|
| 61 |
1.1 |
|
| 64 |
1.1 |