use of org.craftercms.studio.api.v2.dal.RemoteRepositoryInfo in project studio by craftercms.
the class RepositoryManagementServiceInternalImpl method listRemotes.
@Override
public List<RemoteRepositoryInfo> listRemotes(String siteId, String sandboxBranch) throws ServiceLayerException, CryptoException {
List<RemoteRepositoryInfo> res = new ArrayList<RemoteRepositoryInfo>();
Map<String, String> unreachableRemotes = new HashMap<String, String>();
GitRepositoryHelper helper = GitRepositoryHelper.getHelper(studioConfiguration, securityService, userServiceInternal, encryptor, generalLockService, retryingRepositoryOperationFacade);
try (Repository repo = helper.getRepository(siteId, SANDBOX)) {
try (Git git = new Git(repo)) {
List<RemoteConfig> resultRemotes = git.remoteList().call();
if (CollectionUtils.isNotEmpty(resultRemotes)) {
for (RemoteConfig conf : resultRemotes) {
try {
fetchRemote(siteId, git, conf);
} catch (Exception e) {
logger.warn("Failed to fetch from remote repository " + conf.getName());
unreachableRemotes.put(conf.getName(), e.getMessage());
}
}
Map<String, List<String>> remoteBranches = getRemoteBranches(git);
String sandboxBranchName = sandboxBranch;
if (StringUtils.isEmpty(sandboxBranchName)) {
sandboxBranchName = studioConfiguration.getProperty(REPO_SANDBOX_BRANCH);
}
res = getRemoteRepositoryInfo(resultRemotes, remoteBranches, unreachableRemotes, sandboxBranchName);
}
} catch (GitAPIException e) {
logger.error("Error getting remote repositories for site " + siteId, e);
}
}
return res;
}
use of org.craftercms.studio.api.v2.dal.RemoteRepositoryInfo in project studio by craftercms.
the class RepositoryManagementController method listRemotes.
@GetMapping(value = LIST_REMOTES, produces = APPLICATION_JSON_VALUE)
public ResponseBody listRemotes(@RequestParam(name = "siteId", required = true) String siteId) throws ServiceLayerException, CryptoException {
if (!siteService.exists(siteId)) {
throw new SiteNotFoundException(siteId);
}
List<RemoteRepositoryInfo> remotes = repositoryManagementService.listRemotes(siteId);
ResponseBody responseBody = new ResponseBody();
ResultList<RemoteRepositoryInfo> result = new ResultList<RemoteRepositoryInfo>();
result.setEntities(RESULT_KEY_REMOTES, remotes);
result.setResponse(OK);
responseBody.setResult(result);
return responseBody;
}
use of org.craftercms.studio.api.v2.dal.RemoteRepositoryInfo in project studio by craftercms.
the class RepositoryManagementServiceInternalImpl method getRemoteRepositoryInfo.
private List<RemoteRepositoryInfo> getRemoteRepositoryInfo(List<RemoteConfig> resultRemotes, Map<String, List<String>> remoteBranches, Map<String, String> unreachableRemotes, String sandboxBranchName) {
List<RemoteRepositoryInfo> res = new ArrayList<RemoteRepositoryInfo>();
for (RemoteConfig conf : resultRemotes) {
RemoteRepositoryInfo rri = new RemoteRepositoryInfo();
rri.setName(conf.getName());
if (MapUtils.isNotEmpty(unreachableRemotes) && unreachableRemotes.containsKey(conf.getName())) {
rri.setReachable(false);
rri.setUnreachableReason(unreachableRemotes.get(conf.getName()));
}
List<String> branches = remoteBranches.get(rri.getName());
if (CollectionUtils.isEmpty(branches)) {
branches = new ArrayList<String>();
branches.add(sandboxBranchName);
}
rri.setBranches(branches);
StringBuilder sbUrl = new StringBuilder();
if (CollectionUtils.isNotEmpty(conf.getURIs())) {
for (int i = 0; i < conf.getURIs().size(); i++) {
sbUrl.append(conf.getURIs().get(i).toString());
if (i < conf.getURIs().size() - 1) {
sbUrl.append(":");
}
}
}
rri.setUrl(sbUrl.toString());
StringBuilder sbFetch = new StringBuilder();
if (CollectionUtils.isNotEmpty(conf.getFetchRefSpecs())) {
for (int i = 0; i < conf.getFetchRefSpecs().size(); i++) {
sbFetch.append(conf.getFetchRefSpecs().get(i).toString());
if (i < conf.getFetchRefSpecs().size() - 1) {
sbFetch.append(":");
}
}
}
rri.setFetch(sbFetch.toString());
StringBuilder sbPushUrl = new StringBuilder();
if (CollectionUtils.isNotEmpty(conf.getPushURIs())) {
for (int i = 0; i < conf.getPushURIs().size(); i++) {
sbPushUrl.append(conf.getPushURIs().get(i).toString());
if (i < conf.getPushURIs().size() - 1) {
sbPushUrl.append(":");
}
}
} else {
sbPushUrl.append(rri.getUrl());
}
rri.setPushUrl(sbPushUrl.toString());
res.add(rri);
}
return res;
}
Aggregations