Skip to content

Commit

Permalink
Merge pull request #104 from tmarzeion/SDK-161
Browse files Browse the repository at this point in the history
SDK-161 - Fixed GitHub HTTP Key parsing
  • Loading branch information
AdamGrzybkowski authored Sep 12, 2016
2 parents 016dbf9 + ed1d9f0 commit e7c58b0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@

public class CloneIntegrationTest extends AbstractSdkIntegrationTest {

private static final String ORIGIN_URL = "https://github.com/tmarzeion/openmrs-module-appui.git";
private static final String UPSTREAM_URL = "https://github.com/openmrs/openmrs-module-appui.git";

@Test
public void clone_shouldCloneRepository() throws Exception{

String moduleArtifactId = "appui";
String username = "tmarzeion";
String password = "TEST CASE";
final String MODULE_ARTIFACT_ID = "appui";
final String USERNAME = "tmarzeion";
final String PASSWORD = "TEST CASE";

addTaskParam("groupId", "org.openmrs.module");
addTaskParam("artifactId", moduleArtifactId);
addTaskParam("githubUsername", username);
addTaskParam("githubPassword", password);
addTaskParam("artifactId", MODULE_ARTIFACT_ID);
addTaskParam("githubUsername", USERNAME);
addTaskParam("githubPassword", PASSWORD);
executeTask("clone");

// Check build success
Expand Down
48 changes: 31 additions & 17 deletions maven-plugin/src/main/java/org/openmrs/maven/plugins/Clone.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
*/
public class Clone extends AbstractTask {

public static final String GITHUB_COM = "https://github.com/";
public static final String GITHUB_COM = "github.com";
public static final String GITHUB_HTTP_SUFFIX = "https://github.com/";
/**
* @parameter expression="${groupId}"
*/
Expand Down Expand Up @@ -76,10 +77,28 @@ private String extractGitHubHttpKeyFromModulePom(String artifactId, String versi
String url = pomProperties.getScm().getUrl();
pom.delete();
pomDir.delete();
if (!url.endsWith(".git")) {
return StringUtils.removeEnd(url, "/") + ".git";
} else {
return url;

return extractUniversalRepoUrl(url);
}

/**
* This method is modifying repoUrl extracted from OpenMRS' project's pom.xml
* There are some differences in repoUrl syntax for example:
* [email protected]:openmrs/openmrs-contrib-uitestframework.git
* or https://github.com/openmrs/openmrs-module-webservices.rest.git
* This method ensures that repoUrl will be always the same.
*/
private String extractUniversalRepoUrl(String repoUrl) {
String result;
result = repoUrl.substring(repoUrl.indexOf(GITHUB_COM) + GITHUB_COM.length() + 1);

StringUtils.removeEnd(result,"/");

if (!repoUrl.endsWith(".git")) {
return result + ".git";
}
else {
return result;
}
}

Expand Down Expand Up @@ -115,29 +134,24 @@ private void forkRepo(String repoName, String repoOwner) {
}

private void cloneRepo(String repoUrl) {
String repoOwner = repoUrl.substring(repoUrl.indexOf(GITHUB_COM) + GITHUB_COM.length(), repoUrl.lastIndexOf("/"));
String repoOwnerUrlPart = "/" + repoOwner + "/";
String originUrl = repoUrl.replace(repoOwnerUrlPart, "/" + githubUsername + "/");
String repoOwner = repoUrl.substring(0, repoUrl.indexOf("/"));
String originUrl = StringUtils.replaceOnce(repoUrl, repoOwner, githubUsername);

String repoName = repoUrl.substring(
repoUrl.indexOf(repoOwnerUrlPart) + repoOwnerUrlPart.length(),
repoUrl.indexOf(".git")
);
String repoName = repoUrl.substring(repoOwner.length() + 1, repoUrl.lastIndexOf(".git"));

if ("false".equals(testMode)) {
forkRepo(repoName, repoOwner);
}

wizard.showMessage("Cloning from " + originUrl + " into " + repoName);

File localPath = new File(repoName, "");
File localPath = new File(repoName);
wizard.showMessage("Cloning from " + originUrl + " into " + localPath.getAbsolutePath());
if (localPath.exists()) {
throw new IllegalStateException("Destination path \"" + localPath.getAbsolutePath() + "\" already exists.");
}

try {
Git repository = Git.cloneRepository()
.setURI(originUrl)
Git.cloneRepository()
.setURI(GITHUB_HTTP_SUFFIX + originUrl)
.setDirectory(localPath)
.call();
Git git = new Git(gitHelper.getLocalRepository(localPath.getAbsolutePath()));
Expand Down

0 comments on commit e7c58b0

Please sign in to comment.