-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from tmarzeion/SDK-161
SDK-161 - Fixed GitHub HTTP Key parsing
- Loading branch information
Showing
2 changed files
with
37 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}" | ||
*/ | ||
|
@@ -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; | ||
} | ||
} | ||
|
||
|
@@ -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())); | ||
|