Skip to content

Commit

Permalink
support brnaches in APP_URL #423
Browse files Browse the repository at this point in the history
  • Loading branch information
aeberhart committed Nov 13, 2024
1 parent 80c81b0 commit e915ded
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
27 changes: 23 additions & 4 deletions dashjoin-core/src/main/java/org/dashjoin/util/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import java.io.File;
import java.util.Optional;
import java.util.logging.Level;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import lombok.extern.java.Log;

/**
Expand Down Expand Up @@ -65,7 +65,10 @@ public Home(@ConfigProperty(name = "dashjoin.home", defaultValue = "") Optional<
log.info("git clone ...");
CloneCommand cloneCommand = Git.cloneRepository();
cloneCommand.setDirectory(new File(fileHome));
cloneCommand.setURI(appurl.get());
UrlBranch ub = getUrlBranch(appurl.get());
cloneCommand.setURI(ub.url);
if (ub.branch != null)
cloneCommand.setBranch(ub.branch);
cloneCommand.call();
}
} catch (Exception e) {
Expand All @@ -89,4 +92,20 @@ public String getHome() {
public File getFile(String path) {
return new File(fileHome, path);
}

static class UrlBranch {
String url;
String branch;
}

static UrlBranch getUrlBranch(String s) {
UrlBranch res = new UrlBranch();
String[] a = s.split("#");
if (a.length == 2) {
res.url = a[0];
res.branch = a[1];
} else
res.url = s;
return res;
}
}
33 changes: 33 additions & 0 deletions dashjoin-core/src/test/java/org/dashjoin/util/HomeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.dashjoin.util;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class HomeTest {

@Test
public void testUrlBranch() {
// with branch
Assertions.assertEquals("https://github.com/dashjoin/dashjoin-demo",
Home.getUrlBranch("https://github.com/dashjoin/dashjoin-demo#5.0").url);
Assertions.assertEquals("5.0",
Home.getUrlBranch("https://github.com/dashjoin/dashjoin-demo#5.0").branch);

// no branch
Assertions.assertEquals("https://github.com/dashjoin/dashjoin-demo",
Home.getUrlBranch("https://github.com/dashjoin/dashjoin-demo").url);
Assertions.assertNull(Home.getUrlBranch("https://github.com/dashjoin/dashjoin-demo").branch);

// empty string
Assertions.assertEquals("", Home.getUrlBranch("").url);
Assertions.assertNull(Home.getUrlBranch("").branch);

// illegal double ## - ignore and use url 1:1
Assertions.assertEquals("file:x##f", Home.getUrlBranch("file:x##f").url);
Assertions.assertNull(Home.getUrlBranch("file:x##f").branch);

// ends with # - ignore
Assertions.assertEquals("x#", Home.getUrlBranch("x#").url);
Assertions.assertNull(Home.getUrlBranch("x#").branch);
}
}

0 comments on commit e915ded

Please sign in to comment.