use of org.jreleaser.sdk.commons.RestAPIException in project jreleaser by jreleaser.
the class Gitlab method uploadAssets.
Collection<FileUpload> uploadAssets(String owner, String repoName, String identifier, List<Asset> assets) throws IOException, RestAPIException {
logger.debug(RB.$("git.upload.assets"), owner, repoName);
List<FileUpload> uploads = new ArrayList<>();
Project project = getProject(repoName, identifier);
for (Asset asset : assets) {
if (0 == Files.size(asset.getPath()) || !Files.exists(asset.getPath())) {
// do not upload empty or non existent files
continue;
}
logger.info(" " + RB.$("git.upload.asset"), asset.getFilename());
try {
FileUpload upload = api.uploadFile(project.getId(), toFormData(asset.getPath()));
upload.setName(asset.getFilename());
uploads.add(upload);
} catch (IOException | RestAPIException e) {
logger.error(" " + RB.$("git.upload.asset.failure"), asset.getFilename());
throw e;
}
}
return uploads;
}
use of org.jreleaser.sdk.commons.RestAPIException in project jreleaser by jreleaser.
the class Gitlab method getProject.
Project getProject(String projectName, String identifier) throws RestAPIException {
if (null == project) {
if (StringUtils.isNotBlank(identifier)) {
logger.debug(RB.$("git.fetch.gitlab.project_by_id"), identifier);
project = api.getProject(identifier.trim());
} else {
User u = getCurrentUser();
logger.debug(RB.$("git.fetch.gitlab.project.by.user"), projectName, u.getUsername(), u.getId());
List<Project> projects = api.getProject(u.getId(), CollectionUtils.<String, Object>map().e("search", projectName));
if (projects == null || projects.isEmpty()) {
throw new RestAPIException(404, RB.$("ERROR_project_not_exist", projectName));
}
project = projects.get(0);
}
logger.debug(RB.$("git.gitlab.project.found"), project.getNameWithNamespace(), project.getId());
}
return project;
}
use of org.jreleaser.sdk.commons.RestAPIException in project jreleaser by jreleaser.
the class Gitlab method findMilestoneByName.
Optional<Milestone> findMilestoneByName(String owner, String repo, String identifier, String milestoneName) throws IOException {
logger.debug(RB.$("git.milestone.lookup"), milestoneName, owner, repo);
Project project = getProject(repo, identifier);
try {
List<Milestone> milestones = api.findMilestoneByTitle(project.getId(), CollectionUtils.<String, Object>map().e("title", milestoneName));
if (milestones == null || milestones.isEmpty()) {
return Optional.empty();
}
Milestone milestone = milestones.get(0);
return "active".equals(milestone.getState()) ? Optional.of(milestone) : Optional.empty();
} catch (RestAPIException e) {
if (e.isNotFound() || e.isForbidden()) {
// ok
return Optional.empty();
}
throw e;
}
}
use of org.jreleaser.sdk.commons.RestAPIException in project jreleaser by jreleaser.
the class Gitlab method findReleaseByTag.
Release findReleaseByTag(String owner, String repoName, String identifier, String tagName) throws RestAPIException {
logger.debug(RB.$("git.fetch.release.by.tag"), owner, repoName, tagName);
Project project = getProject(repoName, identifier);
try {
return api.getRelease(project.getId(), urlEncode(tagName));
} catch (RestAPIException e) {
if (e.isNotFound() || e.isForbidden()) {
// ok
return null;
}
throw e;
}
}
use of org.jreleaser.sdk.commons.RestAPIException in project jreleaser by jreleaser.
the class Gitlab method linkReleaseAssets.
void linkReleaseAssets(String owner, String repoName, Release release, String identifier, Collection<FileUpload> uploads) throws IOException, RestAPIException {
logger.debug(RB.$("git.upload.asset.links"), owner, repoName, release.getTagName());
Project project = getProject(repoName, identifier);
for (FileUpload upload : uploads) {
logger.debug(" " + RB.$("git.upload.asset.link"), upload.getName());
try {
api.linkAsset(upload.toLinkRequest(apiHost), project.getId(), release.getTagName());
} catch (RestAPIException e) {
logger.error(" " + RB.$("git.upload.asset.link.failure"), upload.getName());
throw e;
}
}
}
Aggregations