Skip to content

Commit

Permalink
Merge pull request #56 from TAMULib/sprint4-count-unlabeled-as-issue
Browse files Browse the repository at this point in the history
Counting uncategorized cards as issues
  • Loading branch information
rladdusaw committed Jan 28, 2020
2 parents a0676a5 + ab48bde commit a98c3e1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
18 changes: 16 additions & 2 deletions src/main/java/edu/tamu/app/ProjectInitialization.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,22 @@ public void run(String... args) throws Exception {
remoteProjectManagerRepo.findAll().forEach(versionManagementSoftware -> {
managementBeanRegistry.register(versionManagementSoftware);
});
if (cardTypeRepo.findByIdentifier("Feature") == null) {
cardTypeRepo.create(new CardType("Feature", new HashSet<String>(Arrays.asList(new String[] { "Story" }))));
CardType type = cardTypeRepo.findByIdentifier("Feature");
HashSet<String> featureTypes = new HashSet<String>(Arrays.asList(new String[] { "Story", "feature" }));
if (type == null) {
cardTypeRepo.create(new CardType("Feature", featureTypes));
} else if (!type.getMapping().equals(featureTypes)) {
type.setMapping(featureTypes);
cardTypeRepo.update(type);
}
if (cardTypeRepo.findByIdentifier("Request") == null) {
cardTypeRepo.create(new CardType("Request", new HashSet<String>(Arrays.asList(new String[] { "request" }))));
}
if (cardTypeRepo.findByIdentifier("Issue") == null) {
cardTypeRepo.create(new CardType("Issue", new HashSet<String>(Arrays.asList(new String[] { "issue" }))));
}
if (cardTypeRepo.findByIdentifier("Defect") == null) {
cardTypeRepo.create(new CardType("Defect", new HashSet<String>(Arrays.asList(new String[] { "bug" }))));
}
}

Expand Down
28 changes: 22 additions & 6 deletions src/main/java/edu/tamu/app/service/manager/GitHubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -200,24 +201,39 @@ private long countCardsOnColumn(GHProjectColumn column) {
return column.listCards()
.asList()
.stream()
.filter(this::cardContainsLabel)
.filter(this::cardIsLabelType)
.count();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private boolean cardContainsLabel(GHProjectCard card) {
private boolean cardIsLabelType(GHProjectCard card) {
try {
return card.getContent().getLabels().parallelStream()
.filter(cardLabel -> cardLabel.getName().equals(label.getName()))
.findAny()
.isPresent();
Collection<GHLabel> labels = card.getContent().getLabels();
if (label.getName().equals(ISSUE_LABEL) && isAnIssue(card)) {
return true;
}
return hasLabelByName(labels, label.getName());
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private boolean isAnIssue(GHProjectCard card) throws IOException {
Collection<GHLabel> labels = card.getContent().getLabels();
return !hasLabelByName(labels, REQUEST_LABEL)
&& !hasLabelByName(labels, DEFECT_LABEL)
&& !hasLabelByName(labels, FEATURE_LABEL);
}

private boolean hasLabelByName(Collection<GHLabel> labels, String name) {
return labels.parallelStream()
.filter(cardLabel -> cardLabel.getName().equals(name))
.findAny()
.isPresent();
}

private List<Card> getCards(GHProject project) throws IOException {
List<Card> cards = new ArrayList<Card>();
for (GHProjectColumn column : project.listColumns().asList()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public void testGetRemoteProjects() throws Exception {
List<RemoteProject> remoteProjects = gitHubService.getRemoteProjects();
assertEquals("Didn't get all the remote projects", 2, remoteProjects.size());
assertEquals("Number of Requests was incorrect", 3, remoteProjects.get(0).getRequestCount());
assertEquals("Number of Issues was incorrect", 3, remoteProjects.get(0).getIssueCount());
assertEquals("Number of Issues was incorrect", 6, remoteProjects.get(0).getIssueCount());
assertEquals("Number of Features was incorrect", 6, remoteProjects.get(0).getFeatureCount());
assertEquals("Number of Defects was incorrect", 3, remoteProjects.get(0).getDefectCount());
}
Expand All @@ -340,7 +340,7 @@ public void testGetRemoteProjectByScopeId() throws Exception {
assertNotNull("Didn't get the remote project", project);
assertEquals("Did not get the expected project", String.valueOf(TEST_REPOSITORY1_ID), project.getId());
assertEquals("Number of Requests was incorrect", 3, project.getRequestCount());
assertEquals("Number of Issues was incorrect", 3, project.getIssueCount());
assertEquals("Number of Issues was incorrect", 6, project.getIssueCount());
assertEquals("Number of Features was incorrect", 6, project.getFeatureCount());
assertEquals("Number of Defects was incorrect", 3, project.getDefectCount());
}
Expand Down

0 comments on commit a98c3e1

Please sign in to comment.