-
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
18 changed files
with
249 additions
and
39 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
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
heylogs-api/src/main/java/internal/heylogs/github/GitHub.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,27 @@ | ||
package internal.heylogs.github; | ||
|
||
import lombok.NonNull; | ||
import nbbrd.design.DirectImpl; | ||
import nbbrd.heylogs.spi.Forge; | ||
import nbbrd.io.text.Parser; | ||
import nbbrd.service.ServiceProvider; | ||
|
||
@DirectImpl | ||
@ServiceProvider | ||
public final class GitHub implements Forge { | ||
|
||
@Override | ||
public @NonNull String getForgeId() { | ||
return "github"; | ||
} | ||
|
||
@Override | ||
public @NonNull String getForgeName() { | ||
return "GitHub"; | ||
} | ||
|
||
@Override | ||
public boolean isCompareLink(@NonNull CharSequence text) { | ||
return Parser.of(GitHubCompareLink::parse).parseValue(text).isPresent(); | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
heylogs-api/src/main/java/internal/heylogs/github/GitHubCompareLink.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,52 @@ | ||
package internal.heylogs.github; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NonNull; | ||
import nbbrd.design.RepresentableAsString; | ||
import nbbrd.design.StaticFactoryMethod; | ||
import nbbrd.heylogs.spi.ForgeLink; | ||
import nbbrd.io.http.URLQueryBuilder; | ||
|
||
import java.net.URL; | ||
import java.util.regex.Pattern; | ||
|
||
import static internal.heylogs.URLExtractor.*; | ||
|
||
// https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-comparing-branches-in-pull-requests#three-dot-and-two-dot-git-diff-comparisons | ||
@RepresentableAsString | ||
@lombok.Value | ||
@lombok.AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
class GitHubCompareLink implements ForgeLink { | ||
|
||
@StaticFactoryMethod | ||
public static @NonNull GitHubCompareLink parse(@NonNull CharSequence text) { | ||
return parseURL(urlOf(text)); | ||
} | ||
|
||
private static @NonNull GitHubCompareLink parseURL(@NonNull URL url) { | ||
String[] pathArray = getPathArray(url); | ||
|
||
checkPathLength(pathArray, 4); | ||
checkPathItem(pathArray, 0, OWNER); | ||
checkPathItem(pathArray, 1, REPO); | ||
checkPathItem(pathArray, 2, "compare"); | ||
checkPathItem(pathArray, 3, OID); | ||
|
||
return new GitHubCompareLink(baseOf(url), pathArray[0], pathArray[1], pathArray[2], pathArray[3]); | ||
} | ||
|
||
@NonNull URL base; | ||
@NonNull String owner; | ||
@NonNull String repo; | ||
@NonNull String type; | ||
@NonNull String oid; | ||
|
||
@Override | ||
public String toString() { | ||
return URLQueryBuilder.of(base).path(owner).path(repo).path(type).path(oid).toString(); | ||
} | ||
|
||
private static final Pattern OWNER = Pattern.compile("[a-z\\d](?:[a-z\\d]|-(?=[a-z\\d])){0,38}"); | ||
private static final Pattern REPO = Pattern.compile("[a-z\\d._-]{1,100}"); | ||
private static final Pattern OID = Pattern.compile(".+\\.{3}.+"); | ||
} |
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
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,19 @@ | ||
package nbbrd.heylogs.spi; | ||
|
||
import lombok.NonNull; | ||
import nbbrd.service.Quantifier; | ||
import nbbrd.service.ServiceDefinition; | ||
import nbbrd.service.ServiceId; | ||
|
||
@ServiceDefinition( | ||
quantifier = Quantifier.MULTIPLE | ||
) | ||
public interface Forge { | ||
|
||
@ServiceId(pattern = ServiceId.KEBAB_CASE) | ||
@NonNull String getForgeId(); | ||
|
||
@NonNull String getForgeName(); | ||
|
||
boolean isCompareLink(@NonNull CharSequence text); | ||
} |
4 changes: 2 additions & 2 deletions
4
...in/java/internal/heylogs/GitHostLink.java → ...ain/java/nbbrd/heylogs/spi/ForgeLink.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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package internal.heylogs; | ||
package nbbrd.heylogs.spi; | ||
|
||
import lombok.NonNull; | ||
|
||
import java.net.URL; | ||
|
||
public interface GitHostLink { | ||
public interface ForgeLink { | ||
|
||
@NonNull URL getBase(); | ||
} |
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,8 @@ | ||
package nbbrd.heylogs.spi; | ||
|
||
import lombok.NonNull; | ||
|
||
public interface ForgeRef<T extends ForgeLink> { | ||
|
||
boolean isCompatibleWith(@NonNull T link); | ||
} |
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
Oops, something went wrong.