Search in sources :

Example 1 with FileUpload

use of org.jreleaser.sdk.gitlab.api.FileUpload 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 FileUpload

use of org.jreleaser.sdk.gitlab.api.FileUpload 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)

Example 3 with FileUpload

use of org.jreleaser.sdk.gitlab.api.FileUpload in project jreleaser by jreleaser.

the class GitlabReleaser method createRelease.

private void createRelease(Gitlab api, String tagName, String changelog, boolean deleteTags) throws IOException {
    org.jreleaser.model.Gitlab gitlab = context.getModel().getRelease().getGitlab();
    Collection<LinkRequest> links = collectUploadLinks(gitlab);
    if (context.isDryrun()) {
        if (!assets.isEmpty()) {
            for (Asset asset : assets) {
                if (0 == Files.size(asset.getPath()) || !Files.exists(asset.getPath())) {
                    // do not upload empty or non existent files
                    continue;
                }
                context.getLogger().info(" " + RB.$("git.upload.asset"), asset.getFilename());
            }
        }
        if (!links.isEmpty()) {
            for (LinkRequest link : links) {
                context.getLogger().info(" " + RB.$("git.upload.asset"), link.getName());
            }
        }
        return;
    }
    if (deleteTags) {
        deleteTags(api, gitlab.getOwner(), gitlab.getName(), gitlab.getIdentifier(), tagName);
    }
    // local tag
    if (deleteTags || !gitlab.isSkipTag()) {
        context.getLogger().debug(RB.$("git.releaser.repository.tag"), tagName);
        GitSdk.of(context).tag(tagName, true, context);
    }
    Release release = new Release();
    release.setName(gitlab.getEffectiveReleaseName());
    release.setTagName(tagName);
    release.setRef(gitlab.getBranch());
    release.setDescription(changelog);
    // remote tag/release
    api.createRelease(gitlab.getOwner(), gitlab.getName(), gitlab.getIdentifier(), release);
    if (!assets.isEmpty()) {
        Collection<FileUpload> uploads = api.uploadAssets(gitlab.getOwner(), gitlab.getName(), gitlab.getIdentifier(), assets);
        api.linkReleaseAssets(gitlab.getOwner(), gitlab.getName(), release, gitlab.getIdentifier(), uploads);
    }
    if (!links.isEmpty()) {
        api.linkAssets(gitlab.getOwner(), gitlab.getName(), release, gitlab.getIdentifier(), links);
    }
    if (gitlab.getMilestone().isClose() && !context.getModel().getProject().isSnapshot()) {
        Optional<Milestone> milestone = api.findMilestoneByName(gitlab.getOwner(), gitlab.getName(), gitlab.getIdentifier(), gitlab.getMilestone().getEffectiveName());
        if (milestone.isPresent()) {
            api.closeMilestone(gitlab.getOwner(), gitlab.getName(), gitlab.getIdentifier(), milestone.get());
        }
    }
}
Also used : LinkRequest(org.jreleaser.sdk.gitlab.api.LinkRequest) Milestone(org.jreleaser.sdk.gitlab.api.Milestone) Asset(org.jreleaser.model.releaser.spi.Asset) Release(org.jreleaser.sdk.gitlab.api.Release) FileUpload(org.jreleaser.sdk.gitlab.api.FileUpload)

Aggregations

FileUpload (org.jreleaser.sdk.gitlab.api.FileUpload)3 Asset (org.jreleaser.model.releaser.spi.Asset)2 RestAPIException (org.jreleaser.sdk.commons.RestAPIException)2 Project (org.jreleaser.sdk.gitlab.api.Project)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)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