Skip to content

Commit

Permalink
feat: support running bsky posts (#1869)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxandersen authored Nov 16, 2024
1 parent ca6e4b6 commit e44b721
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
10 changes: 10 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion jreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/dev/jbang/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
36 changes: 32 additions & 4 deletions src/test/java/dev/jbang/cli/TestRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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"));
}
Expand Down

0 comments on commit e44b721

Please sign in to comment.