Search in sources :

Example 1 with RestAPIException

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;
}
Also used : Project(org.jreleaser.sdk.gitlab.api.Project) ArrayList(java.util.ArrayList) Asset(org.jreleaser.model.releaser.spi.Asset) RestAPIException(org.jreleaser.sdk.commons.RestAPIException) IOException(java.io.IOException) FileUpload(org.jreleaser.sdk.gitlab.api.FileUpload)

Example 2 with RestAPIException

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;
}
Also used : Project(org.jreleaser.sdk.gitlab.api.Project) User(org.jreleaser.sdk.gitlab.api.User) RestAPIException(org.jreleaser.sdk.commons.RestAPIException)

Example 3 with RestAPIException

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;
    }
}
Also used : Project(org.jreleaser.sdk.gitlab.api.Project) Milestone(org.jreleaser.sdk.gitlab.api.Milestone) RestAPIException(org.jreleaser.sdk.commons.RestAPIException)

Example 4 with RestAPIException

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;
    }
}
Also used : Project(org.jreleaser.sdk.gitlab.api.Project) RestAPIException(org.jreleaser.sdk.commons.RestAPIException)

Example 5 with RestAPIException

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;
        }
    }
}
Also used : Project(org.jreleaser.sdk.gitlab.api.Project) RestAPIException(org.jreleaser.sdk.commons.RestAPIException) FileUpload(org.jreleaser.sdk.gitlab.api.FileUpload)

Aggregations

RestAPIException (org.jreleaser.sdk.commons.RestAPIException)11 Project (org.jreleaser.sdk.gitlab.api.Project)7 IOException (java.io.IOException)5 ReleaseException (org.jreleaser.model.releaser.spi.ReleaseException)3 FileUpload (org.jreleaser.sdk.gitlab.api.FileUpload)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Asset (org.jreleaser.model.releaser.spi.Asset)1 Repository (org.jreleaser.model.releaser.spi.Repository)1 GtRelease (org.jreleaser.sdk.gitea.api.GtRelease)1 GhRelease (org.jreleaser.sdk.github.api.GhRelease)1 LinkRequest (org.jreleaser.sdk.gitlab.api.LinkRequest)1 Milestone (org.jreleaser.sdk.gitlab.api.Milestone)1 Release (org.jreleaser.sdk.gitlab.api.Release)1 User (org.jreleaser.sdk.gitlab.api.User)1 GHRelease (org.kohsuke.github.GHRelease)1 GHReleaseUpdater (org.kohsuke.github.GHReleaseUpdater)1