Skip to content

Commit

Permalink
Fixes #345
Browse files Browse the repository at this point in the history
  • Loading branch information
Riduidel committed Apr 5, 2023
1 parent 55398b9 commit a2d61e7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ private Optional<UserAuthenticationData> getAuthenticationData(FileSystemOptions
return Optional.ofNullable(userAuthenticationData);
}

/**
* Convert the relative project url into a valid commons-vfs url (with the GitHub prefix)
* @param project user/project identifier. If absolute path is given as parameter, it is replaced.
* @return
*/
public static String urlFor(String project) {
if(project.contains(".git")) {
project = project.replace(".git", "");
}
if(project.startsWith("https://github.com")) {
return project.replace("https://", "github://");
}
return String.format("github://github.com/%s", project);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.ndx.aadarchi.vfs.github;

import java.io.IOException;
import java.nio.charset.Charset;

import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.VFS;
import org.apache.commons.vfs2.auth.StaticUserAuthenticator;
import org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

class TestFor345_Fail_When_Using_Repository_Path {
private static FileSystemOptions authenticationOptions;

@BeforeAll public static void putGitHubCredentialsInAuth() {
String token = System.getProperty("aadarchi.github.token");
StaticUserAuthenticator auth = new StaticUserAuthenticator("github.com",
null, token);
authenticationOptions = new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(authenticationOptions, auth);
}

@Test
void can_have_file_object_when_repo_path_is_given() throws FileSystemException {
FileObject rootFile = VFS.getManager().resolveFile(GitHubFileProvider.urlFor("https://github.com/Riduidel/aadarchi.git"), authenticationOptions);
Assertions.assertThat((Object) rootFile).isNotNull();
}
}

0 comments on commit a2d61e7

Please sign in to comment.