| 1 | package edu.ucsb.cs156.frontiers.jobs; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.Course; | |
| 4 | import edu.ucsb.cs156.frontiers.entities.TeamMember; | |
| 5 | import edu.ucsb.cs156.frontiers.enums.TeamStatus; | |
| 6 | import edu.ucsb.cs156.frontiers.repositories.TeamMemberRepository; | |
| 7 | import edu.ucsb.cs156.frontiers.services.GithubTeamService; | |
| 8 | import edu.ucsb.cs156.frontiers.services.jobs.JobContext; | |
| 9 | import edu.ucsb.cs156.frontiers.services.jobs.JobContextConsumer; | |
| 10 | import lombok.Builder; | |
| 11 | ||
| 12 | @Builder | |
| 13 | public class AddTeamMemberToGithubJob implements JobContextConsumer { | |
| 14 | String memberGithubLogin; | |
| 15 | Integer githubTeamId; | |
| 16 | Long teamMemberId; | |
| 17 | Course course; | |
| 18 | GithubTeamService githubTeamService; | |
| 19 | TeamMemberRepository teamMemberRepository; | |
| 20 | ||
| 21 | @Override | |
| 22 | public void accept(JobContext ctx) throws Exception { | |
| 23 | ctx.log( | |
| 24 | "Starting add team member to GitHub job for team ID " | |
| 25 | + githubTeamId | |
| 26 | + " member " | |
| 27 | + memberGithubLogin); | |
| 28 | ||
| 29 |
1
1. accept : negated conditional → KILLED |
if (githubTeamId == null) { |
| 30 | ctx.log("ERROR: Team has no GitHub team ID"); | |
| 31 | return; | |
| 32 | } | |
| 33 | ||
| 34 |
1
1. accept : negated conditional → KILLED |
if (memberGithubLogin == null) { |
| 35 | ctx.log("ERROR: Team member has no GitHub login"); | |
| 36 | return; | |
| 37 | } | |
| 38 | ||
| 39 |
2
1. accept : negated conditional → KILLED 2. accept : negated conditional → KILLED |
if (course.getOrgName() == null || course.getInstallationId() == null) { |
| 40 | ctx.log("ERROR: Course has no linked GitHub organization"); | |
| 41 | return; | |
| 42 | } | |
| 43 | ||
| 44 | Integer orgId = null; | |
| 45 | try { | |
| 46 | orgId = githubTeamService.getOrgId(course.getOrgName(), course); | |
| 47 | ||
| 48 | } catch (Exception e) { | |
| 49 | ctx.log( | |
| 50 | "ERROR: Failed to get organization ID for org: " | |
| 51 | + course.getOrgName() | |
| 52 | + " - " | |
| 53 | + e.getMessage()); | |
| 54 | return; | |
| 55 | } | |
| 56 | ||
| 57 | try { | |
| 58 | TeamStatus newStatus = | |
| 59 | githubTeamService.addMemberToGithubTeam( | |
| 60 | memberGithubLogin, githubTeamId, "member", course, orgId); | |
| 61 | ctx.log( | |
| 62 | "Successfully added " + memberGithubLogin + " to Github team with status: " + newStatus); | |
| 63 | ||
| 64 | TeamMember teamMember = teamMemberRepository.findById(teamMemberId).orElse(null); | |
| 65 |
1
1. accept : negated conditional → KILLED |
if (teamMember != null) { |
| 66 |
1
1. accept : removed call to edu/ucsb/cs156/frontiers/entities/TeamMember::setTeamStatus → KILLED |
teamMember.setTeamStatus(newStatus); |
| 67 | teamMemberRepository.save(teamMember); | |
| 68 | ctx.log("Updated team member status in database"); | |
| 69 | } else { | |
| 70 | ctx.log("ERROR: Could not find team member in database with ID: " + teamMemberId); | |
| 71 | } | |
| 72 | } catch (Exception e) { | |
| 73 | ctx.log("ERROR: Failed to add user to GitHub team: " + e.getMessage()); | |
| 74 | } | |
| 75 | ||
| 76 | ctx.log("Done"); | |
| 77 | } | |
| 78 | } | |
Mutations | ||
| 29 |
1.1 |
|
| 34 |
1.1 |
|
| 39 |
1.1 2.2 |
|
| 65 |
1.1 |
|
| 66 |
1.1 |