Skip to content

Commit

Permalink
Merge 56e4d9c into e9fd033
Browse files Browse the repository at this point in the history
  • Loading branch information
rladdusaw committed Sep 7, 2020
2 parents e9fd033 + 56e4d9c commit 5566c3a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 27 deletions.
75 changes: 50 additions & 25 deletions src/main/java/edu/tamu/app/service/manager/GitHubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHLabel;
import org.kohsuke.github.GHMilestone;
import org.kohsuke.github.GHMilestoneState;
import org.kohsuke.github.GHOrganization;
import org.kohsuke.github.GHProject;
import org.kohsuke.github.GHProject.ProjectStateFilter;
Expand Down Expand Up @@ -101,10 +105,11 @@ public List<Sprint> getActiveSprintsByScopeId(final String scopeId) throws Excep
List<GHProject> projects = repo.listProjects(ProjectStateFilter.OPEN).asList();
for (GHProject project : projects) {
String sprintId = String.valueOf(project.getId());
String name = project.getName();
String projectName = repo.getName();
List<Card> cards = getCards(project);
activeSprints.add(new Sprint(sprintId, name, projectName, cards));
Map<String, List<Card>> partitionedCards = getCards(project);
for (Entry<String, List<Card>> partition : partitionedCards.entrySet()) {
activeSprints.add(new Sprint(sprintId, partition.getKey(), projectName, partition.getValue()));
}
}
return activeSprints;
}
Expand All @@ -116,9 +121,12 @@ public List<Sprint> getAdditionalActiveSprints() throws Exception {
List<Sprint> sprints = new ArrayList<Sprint>();
for (GHProject project : projects) {
String sprintId = String.valueOf(project.getId());
String name = project.getName();
List<Card> cards = getCards(project);
sprints.add(new Sprint(sprintId, name, ORGANIZATION, cards));
Map<String, List<Card>> partitionedCards = getCards(project);
int count = 0;
for (Entry<String, List<Card>> partition : partitionedCards.entrySet()) {
sprints.add(new Sprint(sprintId + "-" + count, partition.getKey(), ORGANIZATION, partition.getValue()));
count++;
}
}
return sprints;
}
Expand Down Expand Up @@ -229,32 +237,49 @@ private boolean hasLabelByName(Collection<GHLabel> labels, String name) {
.isPresent();
}

private List<Card> getCards(GHProject project) throws IOException {
List<Card> cards = new ArrayList<Card>();
private Map<String, List<Card>> getCards(GHProject project) throws IOException {
Map<String, List<Card>> cardsByMilestone = new HashMap<>();
for (GHProjectColumn column : project.listColumns().asList()) {
List<GHProjectCard> projectCards = column.listCards().asList();
Map<Long, GHIssue> cardContents = new HashMap<>();
for (GHProjectCard card : projectCards) {
GHIssue content = card.getContent();
// If content is null the card is a note and shouldn't be included
if (content == null) {
continue;
cardContents.put(card.getId(), card.getContent());
}
Map<GHMilestone, List<GHProjectCard>> partitionedCards = projectCards.stream()
// Card without contents is a note
.filter(c -> cardContents.get(c.getId()) != null)
// Card without a milestone is not on the sprint
.filter(c -> cardContents.get(c.getId()).getMilestone() != null)
.collect(Collectors.groupingBy(c -> cardContents.get(c.getId()).getMilestone()));
for (Entry<GHMilestone, List<GHProjectCard>> partition : partitionedCards.entrySet()) {
List<Card> cards = new ArrayList<Card>();
for (GHProjectCard card : partition.getValue()) {
GHIssue content = cardContents.get(card.getId());
String id = String.valueOf(card.getId());
String name = content.getTitle();
String number = String.valueOf(content.getNumber());
String type = getCardType(content);
String description = content.getBody();
String status = card.getColumn().getName();
// TODO: Figure out how we want to handle sizes
String estimate = null;
List<Member> assignees = new ArrayList<Member>();
for (GHUser user : content.getAssignees()) {
assignees.add(getMember(user));
}
cards.add(new Card(id, number, mapCardType(type), name, description, mapStatus(status), mapEstimate(estimate), assignees));
}
String id = String.valueOf(card.getId());
String name = content.getTitle();
String number = String.valueOf(content.getNumber());
String type = getCardType(content);
String description = content.getBody();
String status = card.getColumn().getName();
// TODO: Figure out how we want to handle sizes
String estimate = null;
List<Member> assignees = new ArrayList<Member>();
for (GHUser user : content.getAssignees()) {
assignees.add(getMember(user));
if (partition.getKey().getState().equals(GHMilestoneState.OPEN)) {
String title = partition.getKey().getTitle();
if (cardsByMilestone.containsKey(title)) {
cardsByMilestone.get(title).addAll(cards);
} else {
cardsByMilestone.put(title, cards);
}
}
cards.add(new Card(id, number, mapCardType(type), name, description, mapStatus(status), mapEstimate(estimate), assignees));
}
}
return cards;
return cardsByMilestone;
}

private String getCardType(GHIssue content) throws IOException {
Expand Down
25 changes: 23 additions & 2 deletions src/test/java/edu/tamu/app/service/manager/GitHubServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHLabel;
import org.kohsuke.github.GHMilestone;
import org.kohsuke.github.GHMilestoneState;
import org.kohsuke.github.GHOrganization;
import org.kohsuke.github.GHProject;
import org.kohsuke.github.GHProject.ProjectStateFilter;
Expand Down Expand Up @@ -97,7 +99,9 @@ public class GitHubServiceTest extends CacheMockTests {
private static final GHUser TEST_USER2 = mock(GHUser.class);
private static final GHUser TEST_USER3 = mock(GHUser.class);

private static final GHProjectCard TEST_CARD1 = mock(GHProjectCard.class);
private static final GHMilestone TEST_MILESTONE = mock(GHMilestone.class);

private static final GHProjectCard TEST_CARD1 = mock(GHProjectCard.class, RETURNS_DEEP_STUBS.get());
private static final GHProjectCard TEST_CARD2 = mock(GHProjectCard.class, RETURNS_DEEP_STUBS.get());
private static final GHProjectCard TEST_CARD3 = mock(GHProjectCard.class, RETURNS_DEEP_STUBS.get());
private static final GHProjectCard TEST_CARD4 = mock(GHProjectCard.class, RETURNS_DEEP_STUBS.get());
Expand Down Expand Up @@ -227,7 +231,19 @@ public void setUp() throws Exception {
when(TEST_COLUMN2.listCards().asList()).thenReturn(TEST_COLUMN2_CARDS);
when(TEST_COLUMN3.listCards().asList()).thenReturn(TEST_COLUMN3_CARDS);

when(TEST_MILESTONE.getState()).thenReturn(GHMilestoneState.OPEN);

when(TEST_CARD1.getId()).thenReturn(1L);
when(TEST_CARD2.getId()).thenReturn(2L);
when(TEST_CARD3.getId()).thenReturn(3L);
when(TEST_CARD4.getId()).thenReturn(4L);
when(TEST_CARD5.getId()).thenReturn(5L);

when(TEST_CARD1.getContent()).thenReturn(TEST_ISSUE1);
when(TEST_CARD2.getContent()).thenReturn(TEST_ISSUE2);
when(TEST_CARD3.getContent()).thenReturn(TEST_ISSUE3);
when(TEST_CARD4.getContent()).thenReturn(TEST_ISSUE4);
when(TEST_CARD5.getContent()).thenReturn(TEST_ISSUE5);
when(TEST_CARD1.getColumn()).thenReturn(TEST_COLUMN1);

when(TEST_ISSUE1.getLabels()).thenReturn(TEST_CARD1_LABELS);
Expand All @@ -236,7 +252,11 @@ public void setUp() throws Exception {
when(TEST_ISSUE4.getLabels()).thenReturn(TEST_CARD4_LABELS);
when(TEST_ISSUE5.getLabels()).thenReturn(TEST_CARD5_LABELS);
when(TEST_ISSUE1.getAssignees()).thenReturn(TEST_USERS1);

when(TEST_ISSUE1.getMilestone()).thenReturn(TEST_MILESTONE);
when(TEST_ISSUE2.getMilestone()).thenReturn(TEST_MILESTONE);
when(TEST_ISSUE3.getMilestone()).thenReturn(TEST_MILESTONE);
when(TEST_ISSUE4.getMilestone()).thenReturn(TEST_MILESTONE);
when(TEST_ISSUE5.getMilestone()).thenReturn(TEST_MILESTONE);

when(TEST_COLUMN1.getName()).thenReturn(TEST_COLUMN1_NAME);

Expand Down Expand Up @@ -423,6 +443,7 @@ public void testGetGitHubInstanceByToken() throws IOException {
public void testGetCardsWithNote() throws Exception {
when(TEST_CARD1.getContent()).thenReturn(null);
List<Sprint> sprints = gitHubService.getAdditionalActiveSprints();
System.out.println("\n\n\nsprints: " + sprints.get(1).getCards().get(0).getId() + "\n\n\n");
assertEquals("Didn't get expected number of cards", 5, sprints.get(0).getCards().size());
}
}

0 comments on commit 5566c3a

Please sign in to comment.