From b27928823c54bbd280dc32938ac6c91b1b1e025c Mon Sep 17 00:00:00 2001 From: Max Rydahl Andersen Date: Sat, 16 Nov 2024 15:32:12 +0100 Subject: [PATCH] feat: support running bsky posts --- .justfile | 10 +++++++ jreleaser.yml | 2 +- src/main/java/dev/jbang/util/Util.java | 11 ++++---- src/test/java/dev/jbang/cli/TestRun.java | 36 +++++++++++++++++++++--- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/.justfile b/.justfile index 0305986bc..20766d13d 100644 --- a/.justfile +++ b/.justfile @@ -29,3 +29,13 @@ itest: # open integeration test report openitest: {{open}} build/karate/surefire-reports/karate-summary.html + +# tag minor +tagminor: + git commit --allow-empty -m "[minor] relase" + ./gradlew tag + +tagpatch: + git commit --allow-empty -m "[patch] relase" + ./gradlew tag + diff --git a/jreleaser.yml b/jreleaser.yml index 0a1cedde9..e06bb2cd3 100644 --- a/jreleaser.yml +++ b/jreleaser.yml @@ -61,7 +61,7 @@ announce: bluesky: active: RELEASE status: 'JBang {{projectVersion}} has been released! {{releaseNotesUrl}}' - handle: '@jbang.dev' + handle: 'jbang.dev' host: https://bsky.social sdkman: active: RELEASE diff --git a/src/main/java/dev/jbang/util/Util.java b/src/main/java/dev/jbang/util/Util.java index 146e7168a..20e5d8264 100644 --- a/src/main/java/dev/jbang/util/Util.java +++ b/src/main/java/dev/jbang/util/Util.java @@ -597,11 +597,12 @@ public static String getVendor() { */ public static Path swizzleContent(String fileURL, Path filePath) throws IOException { boolean mastodon = fileURL.matches("https://.*/@(\\w+)/([0-9]+)"); - if (mastodon || fileURL.startsWith("https://carbon.now.sh")) { // sites known - // to have - // og:description - // meta name or - // property + if (mastodon || fileURL.startsWith("https://carbon.now.sh") || fileURL.startsWith("https://bsky.app/")) { // sites + // known + // to have + // og:description + // meta name or + // property try { Document doc = Jsoup.parse(filePath.toFile(), "UTF-8", fileURL); diff --git a/src/test/java/dev/jbang/cli/TestRun.java b/src/test/java/dev/jbang/cli/TestRun.java index 3ccc7f99f..478b091c1 100644 --- a/src/test/java/dev/jbang/cli/TestRun.java +++ b/src/test/java/dev/jbang/cli/TestRun.java @@ -9,7 +9,19 @@ import static org.hamcrest.CoreMatchers.endsWith; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.hasXPath; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.matchesPattern; +import static org.hamcrest.Matchers.matchesRegex; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; @@ -20,7 +32,11 @@ import java.io.PrintWriter; import java.io.StringReader; import java.io.StringWriter; -import java.nio.file.*; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -1128,6 +1144,12 @@ void testFetchFromTwitter(@TempDir Path dir) throws IOException { verifyHello("https://twitter.com/maxandersen/status/1266329490927616001", dir); } + @Test + void testFetchFromBluesky(@TempDir Path dir) throws IOException { + + verifyHello("https://bsky.app/profile/maxandersen.xam.dk/post/3lb2vbnfpns24", dir, false); + } + @Test void testFetchFromMastdon(@TempDir Path dir) throws IOException { verifyHello("https://mastodon.social/@maxandersen/109361828562755062", dir); @@ -1143,11 +1165,17 @@ void testFetchFromMastdon(@TempDir Path dir) throws IOException { */ private void verifyHello(String url, Path dir) throws IOException { + verifyHello(url, dir, true); + } + + private void verifyHello(String url, Path dir, boolean expectFile) throws IOException { String u = Util.swizzleURL(url); Path x = Util.swizzleContent(u, Util.downloadFile(u, dir)); - assertEquals("hello.java", x.getFileName().toString()); + if (expectFile) { + assertEquals("hello.java", x.getFileName().toString()); + } String java = Util.readString(x); - assertThat(java, startsWith("//DEPS")); + assertThat(java, containsString("//DEPS")); assertThat(java, not(containsString(">"))); assertThat(java, containsString("\n")); }