Search in sources :

Example 1 with ReleaseException

use of org.jreleaser.model.releaser.spi.ReleaseException in project jreleaser by jreleaser.

the class ReleaseUtils method tagRelease.

private static void tagRelease(JReleaserContext context, Repository repository, String tagName) throws ReleaseException {
    try {
        GitSdk gitSdk = GitSdk.of(context);
        gitSdk.tag(tagName, true, context);
        context.getLogger().info(RB.$("git.push.release"), repository.getHttpUrl());
        context.getLogger().debug(RB.$("git.push.tag"), context.isDryrun());
        UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(context.getModel().getRelease().getGitService().getResolvedUsername(), context.getModel().getRelease().getGitService().getResolvedToken());
        gitSdk.open().push().setDryRun(context.isDryrun()).setPushTags().setCredentialsProvider(credentialsProvider).call();
    } catch (Exception e) {
        context.getLogger().trace(e);
        throw new ReleaseException(e);
    }
}
Also used : UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) ReleaseException(org.jreleaser.model.releaser.spi.ReleaseException) IOException(java.io.IOException) ReleaseException(org.jreleaser.model.releaser.spi.ReleaseException)

Example 2 with ReleaseException

use of org.jreleaser.model.releaser.spi.ReleaseException in project jreleaser by jreleaser.

the class GitlabReleaser method createRelease.

@Override
protected void createRelease() throws ReleaseException {
    org.jreleaser.model.Gitlab gitlab = context.getModel().getRelease().getGitlab();
    context.getLogger().info(RB.$("git.releaser.releasing"), gitlab.getResolvedRepoUrl(context.getModel()));
    String tagName = gitlab.getEffectiveTagName(context.getModel());
    try {
        String branch = gitlab.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();
        Gitlab api = new Gitlab(context.getLogger(), gitlab.getApiEndpoint(), gitlab.getResolvedToken(), gitlab.getConnectTimeout(), gitlab.getReadTimeout());
        context.getLogger().debug(RB.$("git.releaser.release.lookup"), tagName, gitlab.getCanonicalRepoName());
        Release release = api.findReleaseByTag(gitlab.getOwner(), gitlab.getName(), gitlab.getIdentifier(), tagName);
        boolean snapshot = context.getModel().getProject().isSnapshot();
        if (null != release) {
            context.getLogger().debug(RB.$("git.releaser.release.exists"), tagName);
            if (gitlab.isOverwrite() || snapshot) {
                context.getLogger().debug(RB.$("git.releaser.release.delete"), tagName);
                if (!context.isDryrun()) {
                    api.deleteRelease(gitlab.getOwner(), gitlab.getName(), gitlab.getIdentifier(), tagName);
                }
                context.getLogger().debug(RB.$("git.releaser.release.create"), tagName);
                createRelease(api, tagName, changelog, gitlab.isMatch());
            } else if (gitlab.getUpdate().isEnabled()) {
                context.getLogger().debug(RB.$("git.releaser.release.update"), tagName);
                if (!context.isDryrun()) {
                    boolean update = false;
                    Release updater = new Release();
                    if (gitlab.getUpdate().getSections().contains(UpdateSection.TITLE)) {
                        update = true;
                        context.getLogger().info(RB.$("git.releaser.release.update.title"), gitlab.getEffectiveReleaseName());
                        updater.setName(gitlab.getEffectiveReleaseName());
                    }
                    if (gitlab.getUpdate().getSections().contains(UpdateSection.BODY)) {
                        update = true;
                        context.getLogger().info(RB.$("git.releaser.release.update.body"));
                        updater.setDescription(changelog);
                    }
                    if (update) {
                        api.updateRelease(gitlab.getOwner(), gitlab.getName(), gitlab.getIdentifier(), updater);
                    }
                    if (gitlab.getUpdate().getSections().contains(UpdateSection.ASSETS)) {
                        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 (!gitlab.getUploadLinks().isEmpty()) {
                            Collection<LinkRequest> links = collectUploadLinks(gitlab);
                            api.linkAssets(gitlab.getOwner(), gitlab.getName(), release, gitlab.getIdentifier(), links);
                        }
                    }
                }
            } 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", "GitLab", 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 && gitlab.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 : IOException(java.io.IOException) Collection(java.util.Collection) RestAPIException(org.jreleaser.sdk.commons.RestAPIException) ReleaseException(org.jreleaser.model.releaser.spi.ReleaseException) Release(org.jreleaser.sdk.gitlab.api.Release)

Example 3 with ReleaseException

use of org.jreleaser.model.releaser.spi.ReleaseException 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)

Example 4 with ReleaseException

use of org.jreleaser.model.releaser.spi.ReleaseException in project jreleaser by jreleaser.

the class GithubReleaser method createRelease.

@Override
protected void createRelease() throws ReleaseException {
    org.jreleaser.model.Github github = context.getModel().getRelease().getGithub();
    context.getLogger().info(RB.$("git.releaser.releasing"), github.getResolvedRepoUrl(context.getModel()));
    String tagName = github.getEffectiveTagName(context.getModel());
    try {
        String branch = github.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();
        Github api = new Github(context.getLogger(), github.getApiEndpoint(), github.getResolvedToken(), github.getConnectTimeout(), github.getReadTimeout());
        context.getLogger().debug(RB.$("git.releaser.release.lookup"), tagName, github.getCanonicalRepoName());
        GHRelease release = api.findReleaseByTag(github.getCanonicalRepoName(), tagName);
        boolean snapshot = context.getModel().getProject().isSnapshot();
        if (null != release) {
            context.getLogger().debug(RB.$("git.releaser.release.exists"), tagName);
            if (github.isOverwrite() || snapshot) {
                context.getLogger().debug(RB.$("git.releaser.release.delete"), tagName);
                if (!context.isDryrun()) {
                    release.delete();
                }
                context.getLogger().debug(RB.$("git.releaser.release.create"), tagName);
                createRelease(api, tagName, changelog, github.isMatch());
            } else if (github.getUpdate().isEnabled()) {
                context.getLogger().debug(RB.$("git.releaser.release.update"), tagName);
                if (!context.isDryrun()) {
                    GHReleaseUpdater updater = release.update();
                    updater.prerelease(github.getPrerelease().isEnabled());
                    updater.draft(github.isDraft());
                    if (github.getUpdate().getSections().contains(UpdateSection.TITLE)) {
                        context.getLogger().info(RB.$("git.releaser.release.update.title"), github.getEffectiveReleaseName());
                        updater.name(github.getEffectiveReleaseName());
                    }
                    if (github.getUpdate().getSections().contains(UpdateSection.BODY)) {
                        context.getLogger().info(RB.$("git.releaser.release.update.body"));
                        updater.body(changelog);
                    }
                    updater.update();
                    if (github.getUpdate().getSections().contains(UpdateSection.ASSETS)) {
                        api.uploadAssets(release, assets);
                    }
                    linkDiscussion(tagName, release);
                }
            } 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", "GitHub", 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 && github.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 : IOException(java.io.IOException) GHRelease(org.kohsuke.github.GHRelease) GHReleaseUpdater(org.kohsuke.github.GHReleaseUpdater) RestAPIException(org.jreleaser.sdk.commons.RestAPIException) ReleaseException(org.jreleaser.model.releaser.spi.ReleaseException)

Example 5 with ReleaseException

use of org.jreleaser.model.releaser.spi.ReleaseException in project jreleaser by jreleaser.

the class ReleaseUtils method createTag.

public static void createTag(JReleaserContext context) throws ReleaseException {
    org.jreleaser.model.GitService service = context.getModel().getRelease().getGitService();
    try {
        GitSdk git = GitSdk.of(context);
        Repository repository = git.getRemote();
        context.getLogger().info(RB.$("git.tag"), repository.getHttpUrl());
        String tagName = service.getEffectiveTagName(context.getModel());
        context.getLogger().debug(RB.$("git.tag.lookup"), tagName);
        boolean tagged = git.findTag(tagName);
        boolean snapshot = context.getModel().getProject().isSnapshot();
        if (tagged) {
            context.getLogger().debug(RB.$("git.tag.exists"), tagName);
            if (service.isOverwrite() || snapshot) {
                context.getLogger().debug(RB.$("git.tag.release"), tagName);
                tagRelease(context, repository, tagName);
            } else if (!context.isDryrun()) {
                throw new IllegalStateException(RB.$("ERROR_git_release_existing_tag", tagName));
            }
        } else {
            context.getLogger().debug(RB.$("git.tag.not.exist"), tagName);
            context.getLogger().debug(RB.$("git.tag.release"), tagName);
            tagRelease(context, repository, tagName);
        }
    } catch (IOException | IllegalStateException e) {
        context.getLogger().trace(e);
        throw new ReleaseException(e);
    }
}
Also used : Repository(org.jreleaser.model.releaser.spi.Repository) IOException(java.io.IOException) ReleaseException(org.jreleaser.model.releaser.spi.ReleaseException)

Aggregations

IOException (java.io.IOException)5 ReleaseException (org.jreleaser.model.releaser.spi.ReleaseException)5 RestAPIException (org.jreleaser.sdk.commons.RestAPIException)3 Collection (java.util.Collection)1 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)1 Repository (org.jreleaser.model.releaser.spi.Repository)1 GtRelease (org.jreleaser.sdk.gitea.api.GtRelease)1 Release (org.jreleaser.sdk.gitlab.api.Release)1 GHRelease (org.kohsuke.github.GHRelease)1 GHReleaseUpdater (org.kohsuke.github.GHReleaseUpdater)1