-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
231 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
heylogs-api/src/main/java/internal/heylogs/ChangelogNodes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package internal.heylogs; | ||
|
||
import com.vladsch.flexmark.ast.BulletList; | ||
import com.vladsch.flexmark.ast.BulletListItem; | ||
import com.vladsch.flexmark.ast.Heading; | ||
import com.vladsch.flexmark.util.ast.Node; | ||
import nbbrd.heylogs.Nodes; | ||
import nbbrd.heylogs.TypeOfChange; | ||
import nbbrd.heylogs.Version; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.TreeMap; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
|
||
public final class ChangelogNodes { | ||
|
||
private ChangelogNodes() { | ||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); | ||
} | ||
|
||
public static boolean isNotVersionHeading(Node node) { | ||
return !(node instanceof Heading && Version.isVersionLevel((Heading) node)); | ||
} | ||
|
||
public static boolean isTypeOfChangeNode(Node node) { | ||
return node instanceof Heading && TypeOfChange.isTypeOfChangeLevel((Heading) node); | ||
} | ||
|
||
public static boolean isNotHeading(Node next) { | ||
return !(next instanceof Heading); | ||
} | ||
|
||
public static boolean isUnreleasedHeading(Heading heading) { | ||
try { | ||
return Version.isVersionLevel(heading) && Version.parse(heading).isUnreleased(); | ||
} catch (IllegalArgumentException ex) { | ||
return false; | ||
} | ||
} | ||
|
||
public static Optional<Heading> getUnreleasedHeading(Node doc) { | ||
return Nodes.of(Heading.class) | ||
.descendants(doc) | ||
.filter(ChangelogNodes::isUnreleasedHeading) | ||
.findFirst(); | ||
} | ||
|
||
public static Map<TypeOfChange, List<BulletListItem>> getBulletListsByTypeOfChange(Heading version) { | ||
TreeMap<TypeOfChange, List<BulletListItem>> result = new TreeMap<>(); | ||
Nodes.next(version, ChangelogNodes::isNotVersionHeading) | ||
.filter(ChangelogNodes::isTypeOfChangeNode) | ||
.map(Heading.class::cast) | ||
.forEach(typeOfChange -> result.put(TypeOfChange.parse(typeOfChange), collect(typeOfChange))); | ||
return result; | ||
} | ||
|
||
private static List<BulletListItem> collect(Heading typeOfChange) { | ||
return Nodes.next(typeOfChange, ChangelogNodes::isNotHeading) | ||
.filter(BulletList.class::isInstance) | ||
.map(BulletList.class::cast) | ||
.flatMap(Nodes.of(BulletListItem.class)::descendants) | ||
.collect(toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
heylogs-api/src/test/java/internal/heylogs/ChangelogNodesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package internal.heylogs; | ||
|
||
import com.vladsch.flexmark.ast.BulletListItem; | ||
import com.vladsch.flexmark.ast.Heading; | ||
import nbbrd.heylogs.TypeOfChange; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static _test.Sample.asHeading; | ||
import static _test.Sample.using; | ||
import static internal.heylogs.ChangelogNodes.*; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ChangelogNodesTest { | ||
|
||
@Test | ||
public void testIsUnreleasedHeading() { | ||
assertThat(isUnreleasedHeading(asHeading("## [Unreleased]"))).isTrue(); | ||
assertThat(isUnreleasedHeading(asHeading("## [unreleased]"))).isTrue(); | ||
assertThat(isUnreleasedHeading(asHeading("# [unreleased]"))).isFalse(); | ||
assertThat(isUnreleasedHeading(asHeading("## unreleased"))).isFalse(); | ||
assertThat(isUnreleasedHeading(asHeading("## [stuff]"))).isFalse(); | ||
} | ||
|
||
@Test | ||
public void testGetUnreleasedHeading() { | ||
assertThat(getUnreleasedHeading(using("/Empty.md"))) | ||
.isEmpty(); | ||
|
||
assertThat(getUnreleasedHeading(using("/Main.md"))) | ||
.isNotEmpty() | ||
.hasValueSatisfying(ChangelogNodes::isUnreleasedHeading); | ||
} | ||
|
||
@Test | ||
public void testGetBulletListsByTypeOfChange() { | ||
Heading unreleased = getUnreleasedHeading(using("/UnreleasedChanges.md")).orElseThrow(RuntimeException::new); | ||
|
||
Map<TypeOfChange, List<BulletListItem>> x = getBulletListsByTypeOfChange(unreleased); | ||
|
||
assertThat(x.keySet()) | ||
.hasSize(3) | ||
.containsExactly( | ||
TypeOfChange.ADDED, | ||
TypeOfChange.CHANGED, | ||
TypeOfChange.FIXED | ||
); | ||
|
||
assertThat(x.get(TypeOfChange.ADDED)) | ||
.hasSize(3) | ||
.map(o -> o.getChildChars().toString().replaceAll("\\n", "").replaceAll("\\r", "")) | ||
.containsExactly( | ||
"Added Dutch translation", | ||
"Added French translation", | ||
"Added German translation" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package nbbrd.heylogs; | ||
|
||
import com.vladsch.flexmark.ast.Heading; | ||
import internal.heylogs.ChangelogNodes; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static _test.Sample.using; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class NodesTest { | ||
|
||
@Test | ||
public void testNext() { | ||
Heading unreleased = ChangelogNodes.getUnreleasedHeading(using("/Main.md")).orElseThrow(RuntimeException::new); | ||
|
||
assertThat(Nodes.next(unreleased, ignore -> false)) | ||
.isEmpty(); | ||
|
||
assertThat(Nodes.next(unreleased, ChangelogNodes::isNotVersionHeading)) | ||
.hasSize(4); | ||
|
||
assertThat(Nodes.next(unreleased, ignore -> true)) | ||
.hasSize(75); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Changelog | ||
|
||
- Some bullet points | ||
|
||
## [Unreleased] | ||
|
||
- It's a trap ! | ||
|
||
### Added | ||
|
||
- Added Dutch translation | ||
- Added French translation | ||
- Added German translation | ||
|
||
### Fixed | ||
|
||
- Fixed foldouts in Dutch translation | ||
|
||
### Changed | ||
|
||
## [1.1.0] - 2019-02-15 | ||
|
||
[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.1.0...HEAD | ||
[1.1.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...v1.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
"to": "+999999999-12-31" | ||
}, | ||
"compatibilities": [], | ||
"hasUnreleasedSection": false | ||
"unreleasedChanges": 0 | ||
} | ||
} | ||
] |
Oops, something went wrong.