Search in sources :

Example 1 with GtRelease

use of org.jreleaser.sdk.gitea.api.GtRelease in project jreleaser by jreleaser.

the class GiteaReleaser method createRelease.

private void createRelease(Gitea api, String tagName, String changelog, boolean deleteTags) throws IOException {
    org.jreleaser.model.Gitea gitea = resolveGiteaFromModel();
    if (context.isDryrun()) {
        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());
        }
        return;
    }
    if (deleteTags) {
        deleteTags(api, gitea.getOwner(), gitea.getName(), tagName);
    }
    // local tag
    if (deleteTags || !gitea.isSkipTag()) {
        context.getLogger().debug(RB.$("git.releaser.repository.tag"), tagName);
        GitSdk.of(context).tag(tagName, true, context);
    }
    // remote tag/release
    GtRelease release = new GtRelease();
    release.setName(gitea.getEffectiveReleaseName());
    release.setTagName(tagName);
    release.setTargetCommitish(gitea.getBranch());
    release.setBody(changelog);
    release = api.createRelease(gitea.getOwner(), gitea.getName(), release);
    api.uploadAssets(gitea.getOwner(), gitea.getName(), release, assets);
    if (gitea.getMilestone().isClose() && !context.getModel().getProject().isSnapshot()) {
        Optional<GtMilestone> milestone = api.findMilestoneByName(gitea.getOwner(), gitea.getName(), gitea.getMilestone().getEffectiveName());
        if (milestone.isPresent()) {
            api.closeMilestone(gitea.getOwner(), gitea.getName(), milestone.get());
        }
    }
}
Also used : GtRelease(org.jreleaser.sdk.gitea.api.GtRelease) GtMilestone(org.jreleaser.sdk.gitea.api.GtMilestone) Asset(org.jreleaser.model.releaser.spi.Asset)

Example 2 with GtRelease

use of org.jreleaser.sdk.gitea.api.GtRelease in project jreleaser by jreleaser.

the class GiteaReleaser method createRelease.

@Override
protected void createRelease() throws ReleaseException {
    org.jreleaser.model.Gitea gitea = resolveGiteaFromModel();
    context.getLogger().info(RB.$("git.releaser.releasing"), gitea.getResolvedRepoUrl(context.getModel()));
    String tagName = gitea.getEffectiveTagName(context.getModel());
    try {
        String branch = gitea.getBranch();
        List<String> branchNames = GitSdk.of(context).getRemoteBranches();
        if (!branchNames.contains(branch)) {
            throw new ReleaseException(RB.$("ERROR_git_release_branch_not_exists", branch, branchNames));
        }
        String changelog = context.getChangelog();
        Gitea api = new Gitea(context.getLogger(), gitea.getApiEndpoint(), gitea.getResolvedToken(), gitea.getConnectTimeout(), gitea.getReadTimeout());
        context.getLogger().debug(RB.$("git.releaser.release.lookup"), tagName, gitea.getCanonicalRepoName());
        GtRelease release = api.findReleaseByTag(gitea.getOwner(), gitea.getName(), tagName);
        boolean snapshot = context.getModel().getProject().isSnapshot();
        if (null != release) {
            context.getLogger().debug(RB.$("git.releaser.release.exists"), tagName);
            if (gitea.isOverwrite() || snapshot) {
                context.getLogger().debug(RB.$("git.releaser.release.delete"), tagName);
                if (!context.isDryrun()) {
                    api.deleteRelease(gitea.getOwner(), gitea.getName(), tagName, release.getId());
                }
                context.getLogger().debug(RB.$("git.releaser.release.create"), tagName);
                createRelease(api, tagName, changelog, gitea.isMatch());
            } else if (gitea.getUpdate().isEnabled()) {
                context.getLogger().debug(RB.$("git.releaser.release.update"), tagName);
                if (!context.isDryrun()) {
                    GtRelease updater = new GtRelease();
                    updater.setPrerelease(gitea.getPrerelease().isEnabled());
                    updater.setDraft(gitea.isDraft());
                    if (gitea.getUpdate().getSections().contains(UpdateSection.TITLE)) {
                        context.getLogger().info(RB.$("git.releaser.release.update.title"), gitea.getEffectiveReleaseName());
                        updater.setName(gitea.getEffectiveReleaseName());
                    }
                    if (gitea.getUpdate().getSections().contains(UpdateSection.BODY)) {
                        context.getLogger().info(RB.$("git.releaser.release.update.body"));
                        updater.setBody(changelog);
                    }
                    api.updateRelease(gitea.getOwner(), gitea.getName(), release.getId(), updater);
                    if (gitea.getUpdate().getSections().contains(UpdateSection.ASSETS)) {
                        api.uploadAssets(gitea.getOwner(), gitea.getName(), release, assets);
                    }
                }
            } else {
                if (context.isDryrun()) {
                    context.getLogger().debug(RB.$("git.releaser.release.create"), tagName);
                    createRelease(api, tagName, changelog, false);
                    return;
                }
                throw new IllegalStateException(RB.$("ERROR_git_releaser_cannot_release", capitalize(gitea.getServiceName()), tagName));
            }
        } else {
            context.getLogger().debug(RB.$("git.releaser.release.not.found"), tagName);
            context.getLogger().debug(RB.$("git.releaser.release.create"), tagName);
            createRelease(api, tagName, changelog, snapshot && gitea.isMatch());
        }
    } catch (RestAPIException e) {
        context.getLogger().trace(e.getStatus() + " " + e.getReason());
        context.getLogger().trace(e);
        throw new ReleaseException(e);
    } catch (IOException | IllegalStateException e) {
        context.getLogger().trace(e);
        throw new ReleaseException(e);
    }
}
Also used : GtRelease(org.jreleaser.sdk.gitea.api.GtRelease) IOException(java.io.IOException) RestAPIException(org.jreleaser.sdk.commons.RestAPIException) ReleaseException(org.jreleaser.model.releaser.spi.ReleaseException)

Aggregations

GtRelease (org.jreleaser.sdk.gitea.api.GtRelease)2 IOException (java.io.IOException)1 Asset (org.jreleaser.model.releaser.spi.Asset)1 ReleaseException (org.jreleaser.model.releaser.spi.ReleaseException)1 RestAPIException (org.jreleaser.sdk.commons.RestAPIException)1 GtMilestone (org.jreleaser.sdk.gitea.api.GtMilestone)1