Skip to content

Commit

Permalink
Add GitHub extension
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Aug 28, 2024
1 parent d8ef680 commit 63c7313
Show file tree
Hide file tree
Showing 33 changed files with 514 additions and 57 deletions.
71 changes: 59 additions & 12 deletions heylogs-api/src/test/java/nbbrd/heylogs/HeylogsTest.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
package nbbrd.heylogs;

import tests.heylogs.api.Sample;
import com.vladsch.flexmark.util.ast.Document;
import com.vladsch.flexmark.util.ast.Node;
import internal.heylogs.StylishFormat;
import lombok.NonNull;
import nbbrd.design.MightBePromoted;
import nbbrd.heylogs.spi.Forge;
import nbbrd.heylogs.spi.Rule;
import nbbrd.heylogs.spi.RuleIssue;
import nbbrd.heylogs.spi.RuleSeverity;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.junit.jupiter.api.Test;
import tests.heylogs.api.Sample;

import java.io.IOException;
import java.net.URL;
import java.time.LocalDate;
import java.util.List;
import java.util.function.Function;

import static tests.heylogs.api.Sample.using;
import static internal.heylogs.URLExtractor.urlOf;
import static java.util.Collections.singletonList;
import static nbbrd.heylogs.Filter.builder;
import static nbbrd.heylogs.Heylogs.FIRST_FORMAT_AVAILABLE;
import static nbbrd.heylogs.spi.RuleSeverity.ERROR;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.InstanceOfAssertFactories.list;
import static tests.heylogs.api.Sample.using;

public class HeylogsTest {

Expand Down Expand Up @@ -108,7 +111,11 @@ public void testListResources() {

@Test
public void testReleaseChanges() {
Heylogs x = Heylogs.ofServiceLoader();
Heylogs x = Heylogs.ofServiceLoader()
.toBuilder()
.forge(new MockedForge())
.build();

Version v123 = Version.of("1.2.3", Version.HYPHEN, LocalDate.of(2010, 1, 1));

assertThatIllegalArgumentException().isThrownBy(() -> releaseChangesToString(x, using("/Empty.md"), v123))
Expand Down Expand Up @@ -141,7 +148,10 @@ public void testReleaseChanges() {

@Test
public void testScanContent() {
Heylogs x = Heylogs.ofServiceLoader();
Heylogs x = Heylogs.ofServiceLoader()
.toBuilder()
.forge(new MockedForge())
.build();

assertThat(x.scanContent(using("/Empty.md")))
.isEqualTo(Summary
Expand All @@ -155,15 +165,15 @@ public void testScanContent() {

assertThat(x.scanContent(using("/Main.md")))
.isEqualTo(Summary
.builder()
.valid(true)
.releaseCount(13)
.timeRange(TimeRange.of(LocalDate.of(2014, 5, 31), LocalDate.of(2019, 2, 15)))
.builder()
.valid(true)
.releaseCount(13)
.timeRange(TimeRange.of(LocalDate.of(2014, 5, 31), LocalDate.of(2019, 2, 15)))
// .compatibility("Semantic Versioning")
.unreleasedChanges(2)
.forgeName("GitHub")
.forgeURL(urlOf("https://github.com/olivierlacan/keep-a-changelog"))
.build()
.unreleasedChanges(2)
.forgeName("GitHub")
.forgeURL(urlOf("https://github.com/olivierlacan/keep-a-changelog"))
.build()
);

assertThat(x.scanContent(using("/InvalidSemver.md")))
Expand Down Expand Up @@ -286,4 +296,41 @@ public boolean isRuleAvailable() {
return null;
}
}

private static final class MockedForge implements Forge {

@Override
public @NonNull String getForgeId() {
return "github";
}

@Override
public @NonNull String getForgeName() {
return "GitHub";
}

@Override
public boolean isCompareLink(@NonNull URL url) {
return true;
}

@Override
public @NonNull URL getProjectURL(@NonNull URL url) {
return urlOf("https://github.com/olivierlacan/keep-a-changelog");
}

@Override
public @NonNull URL deriveCompareLink(@NonNull URL latest, @NonNull String nextTag) {
String urlAsString = latest.toString();
int oidIndex = urlAsString.lastIndexOf("/") + 1;
return urlOf(urlAsString.substring(0, oidIndex) + deriveOID(nextTag, urlAsString.substring(oidIndex)));
}

@MightBePromoted
private static String deriveOID(String nextTag, String oid) {
return oid.endsWith("...HEAD")
? oid.startsWith("HEAD...") ? (nextTag + "..." + nextTag) : (oid.substring(0, oid.length() - 4) + nextTag)
: (oid.substring(oid.indexOf("...") + 3) + "..." + nextTag);
}
}
}
40 changes: 40 additions & 0 deletions heylogs-api/src/test/java/tests/heylogs/spi/ForgeAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package tests.heylogs.spi;

import lombok.NonNull;
import nbbrd.heylogs.spi.Forge;

import static internal.heylogs.URLExtractor.urlOf;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNullPointerException;

public final class ForgeAssert {

private ForgeAssert() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

@SuppressWarnings("DataFlowIssue")
public static void assertForgeCompliance(@NonNull Forge x) {
assertThat(x.getForgeId())
.matches(nbbrd.heylogs.spi.ForgeLoader.ID_PATTERN);

assertThat(x.getForgeName())
.isNotEmpty()
.isNotNull();

assertThatNullPointerException()
.isThrownBy(() -> x.isCompareLink(null));

assertThatNullPointerException()
.isThrownBy(() -> x.getProjectURL(null));

assertThatNullPointerException()
.isThrownBy(() -> x.deriveCompareLink(null, ""));

assertThatNullPointerException()
.isThrownBy(() -> x.deriveCompareLink(urlOf("http://localhost"), null));

assertThat(x.getClass())
.isFinal();
}
}
21 changes: 21 additions & 0 deletions heylogs-api/src/test/java/tests/heylogs/spi/ForgeLinkAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tests.heylogs.spi;

import lombok.NonNull;
import nbbrd.heylogs.spi.ForgeLink;

import static org.assertj.core.api.Assertions.assertThat;

public final class ForgeLinkAssert {

private ForgeLinkAssert() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

public static void assertForgeLinkCompliance(@NonNull ForgeLink x) {
assertThat(x.getBase())
.isNotNull();

assertThat(x.getClass())
.isFinal();
}
}
23 changes: 23 additions & 0 deletions heylogs-api/src/test/java/tests/heylogs/spi/ForgeRefAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tests.heylogs.spi;

import lombok.NonNull;
import nbbrd.heylogs.spi.ForgeRef;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNullPointerException;

public final class ForgeRefAssert {

private ForgeRefAssert() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

@SuppressWarnings("DataFlowIssue")
public static void assertForgeRefCompliance(@NonNull ForgeRef<?> x) {
assertThatNullPointerException()
.isThrownBy(() -> x.isCompatibleWith(null));

assertThat(x.getClass())
.isFinal();
}
}
5 changes: 5 additions & 0 deletions heylogs-api/src/test/java/tests/heylogs/spi/RuleAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.NonNull;
import nbbrd.heylogs.spi.Rule;
import nbbrd.heylogs.spi.RuleBatch;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
Expand All @@ -12,6 +13,10 @@ private RuleAssert() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

public static void assertRuleCompliance(@NonNull RuleBatch x) {
x.getProviders().forEach(RuleAssert::assertRuleCompliance);
}

@SuppressWarnings("DataFlowIssue")
public static void assertRuleCompliance(@NonNull Rule x) {
assertThat(x.getRuleId())
Expand Down
5 changes: 5 additions & 0 deletions heylogs-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>heylogs-ext-github</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>heylogs-ext-semver</artifactId>
<groupId>${project.groupId}</groupId>
Expand Down
5 changes: 5 additions & 0 deletions heylogs-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>heylogs-ext-github</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>heylogs-ext-semver</artifactId>
<groupId>${project.groupId}</groupId>
Expand Down
66 changes: 66 additions & 0 deletions heylogs-ext-github/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.github.nbbrd.heylogs</groupId>
<artifactId>heylogs-parent</artifactId>
<version>0.8.2-SNAPSHOT</version>
</parent>

<artifactId>heylogs-ext-github</artifactId>
<packaging>jar</packaging>

<dependencies>
<!-- compile only -->
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.nbbrd.java-design-util</groupId>
<artifactId>java-design-processor</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.nbbrd.java-service-util</groupId>
<artifactId>java-service-processor</artifactId>
<scope>provided</scope>
</dependency>

<!-- compile and runtime -->
<dependency>
<artifactId>heylogs-api</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>

<!-- test only -->
<dependency>
<artifactId>heylogs-api</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal.heylogs.github;
package nbbrd.heylogs.ext.github;

import lombok.NonNull;
import nbbrd.design.DirectImpl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal.heylogs.github;
package nbbrd.heylogs.ext.github;

import nbbrd.heylogs.spi.ForgeLink;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal.heylogs.github;
package nbbrd.heylogs.ext.github;

import nbbrd.heylogs.spi.ForgeRef;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal.heylogs.github;
package nbbrd.heylogs.ext.github;

import lombok.AccessLevel;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal.heylogs.github;
package nbbrd.heylogs.ext.github;

import nbbrd.heylogs.spi.ForgeLink;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal.heylogs.github;
package nbbrd.heylogs.ext.github;

import nbbrd.heylogs.spi.ForgeRef;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal.heylogs.github;
package nbbrd.heylogs.ext.github;

import nbbrd.heylogs.spi.ForgeLink;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal.heylogs.github;
package nbbrd.heylogs.ext.github;

import nbbrd.heylogs.spi.ForgeRef;
import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal.heylogs.github;
package nbbrd.heylogs.ext.github;

import nbbrd.heylogs.spi.ForgeLink;
import nbbrd.heylogs.spi.ForgeRef;
Expand Down
Loading

0 comments on commit 63c7313

Please sign in to comment.