Search in sources :

Example 1 with Repository

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

the class ModelAutoConfigurer method autoConfiguredModel.

private JReleaserModel autoConfiguredModel(Path basedir) {
    JReleaserModel model = new JReleaserModel();
    model.getProject().setName(projectName);
    model.getProject().setVersion(projectVersion);
    model.getProject().setVersionPattern(projectVersionPattern);
    model.getProject().getSnapshot().setPattern(projectSnapshotPattern);
    model.getProject().getSnapshot().setLabel(projectSnapshotLabel);
    model.getProject().getSnapshot().setFullChangelog(projectSnapshotFullChangelog);
    try {
        Repository repository = GitSdk.of(basedir, gitRootSearch).getRemote();
        GitService service = null;
        switch(repository.getKind()) {
            case GITHUB:
                service = new Github();
                model.getRelease().setGithub((Github) service);
                if (prerelease)
                    ((Github) service).getPrerelease().setEnabled(true);
                ((Github) service).getPrerelease().setPattern(prereleasePattern);
                ((Github) service).setDraft(draft);
                break;
            case GITLAB:
                service = new Gitlab();
                model.getRelease().setGitlab((Gitlab) service);
                break;
            case CODEBERG:
                service = new Codeberg();
                model.getRelease().setCodeberg((Codeberg) service);
                if (prerelease)
                    ((Codeberg) service).getPrerelease().setEnabled(true);
                ((Codeberg) service).getPrerelease().setPattern(prereleasePattern);
                ((Codeberg) service).setDraft(draft);
                break;
            default:
                throw new JReleaserException(RB.$("ERROR_context_configurer_unsupported_url", repository.getHttpUrl()));
        }
        service.setUsername(username);
        service.setTagName(tagName);
        service.setPreviousTagName(previousTagName);
        service.setReleaseName(releaseName);
        service.getMilestone().setName(milestoneName);
        service.setOverwrite(overwrite);
        service.getUpdate().setEnabled(update);
        if (!updateSections.isEmpty()) {
            if (!update) {
                throw new JReleaserException(RB.$("ERROR_context_configurer_update_not_set"));
            }
            service.getUpdate().setSections(updateSections);
        }
        service.setSkipTag(skipTag);
        service.setSkipRelease(skipRelease);
        if (isNotBlank(branch))
            service.setBranch(branch);
        if (isNotBlank(changelog))
            service.getChangelog().setExternal(changelog);
        if (isNotBlank(commitAuthorName))
            service.getCommitAuthor().setName(commitAuthorName);
        if (isNotBlank(commitAuthorEmail))
            service.getCommitAuthor().setEmail(commitAuthorEmail);
        if (changelogFormatted)
            service.getChangelog().setFormatted(Active.ALWAYS);
    } catch (IOException e) {
        throw new JReleaserException(e.getMessage());
    }
    if (signing) {
        model.getSigning().setActive(Active.ALWAYS);
        model.getSigning().setArmored(armored);
    }
    if (!files.isEmpty()) {
        for (String file : files) {
            model.getFiles().addArtifact(Artifact.of(basedir.resolve(file)));
        }
    }
    if (!globs.isEmpty()) {
        model.getFiles().addArtifacts(Artifacts.resolveFiles(logger, basedir, globs));
    }
    return model;
}
Also used : Codeberg(org.jreleaser.model.Codeberg) Repository(org.jreleaser.model.releaser.spi.Repository) Github(org.jreleaser.model.Github) JReleaserModel(org.jreleaser.model.JReleaserModel) GitService(org.jreleaser.model.GitService) IOException(java.io.IOException) Gitlab(org.jreleaser.model.Gitlab) JReleaserException(org.jreleaser.util.JReleaserException)

Example 2 with Repository

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

the class GitlabReleaser method maybeCreateRepository.

@Override
public Repository maybeCreateRepository(String owner, String repo, String password) throws IOException {
    org.jreleaser.model.Gitlab gitlab = context.getModel().getRelease().getGitlab();
    context.getLogger().debug(RB.$("git.repository.lookup"), owner, repo);
    Gitlab api = new Gitlab(context.getLogger(), gitlab.getApiEndpoint(), password, gitlab.getConnectTimeout(), gitlab.getReadTimeout());
    Project project = null;
    try {
        project = api.findProject(repo, gitlab.getIdentifier());
    } catch (RestAPIException e) {
        if (!e.isNotFound()) {
            throw e;
        }
    }
    if (null == project) {
        project = api.createProject(owner, repo);
    }
    return new Repository(Repository.Kind.GITLAB, owner, repo, project.getWebUrl(), project.getHttpUrlToRepo());
}
Also used : Project(org.jreleaser.sdk.gitlab.api.Project) Repository(org.jreleaser.model.releaser.spi.Repository) RestAPIException(org.jreleaser.sdk.commons.RestAPIException)

Example 3 with Repository

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

the class GiteaReleaser method maybeCreateRepository.

@Override
public Repository maybeCreateRepository(String owner, String repo, String password) throws IOException {
    org.jreleaser.model.Gitea gitea = resolveGiteaFromModel();
    context.getLogger().debug(RB.$("git.repository.lookup"), owner, repo);
    Gitea api = new Gitea(context.getLogger(), gitea.getApiEndpoint(), password, gitea.getConnectTimeout(), gitea.getReadTimeout());
    GtRepository repository = api.findRepository(owner, repo);
    if (null == repository) {
        repository = api.createRepository(owner, repo);
    }
    return new Repository(resolveRepositoryKind(), owner, repo, repository.getHtmlUrl(), repository.getCloneUrl());
}
Also used : Repository(org.jreleaser.model.releaser.spi.Repository) GtRepository(org.jreleaser.sdk.gitea.api.GtRepository) GtRepository(org.jreleaser.sdk.gitea.api.GtRepository)

Example 4 with Repository

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

the class GithubReleaser method maybeCreateRepository.

@Override
public Repository maybeCreateRepository(String owner, String repo, String password) throws IOException {
    org.jreleaser.model.Github github = context.getModel().getRelease().getGithub();
    context.getLogger().debug(RB.$("git.repository.lookup"), owner, repo);
    Github api = new Github(context.getLogger(), github.getApiEndpoint(), password, github.getConnectTimeout(), github.getReadTimeout());
    GHRepository repository = api.findRepository(owner, repo);
    if (null == repository) {
        repository = api.createRepository(owner, repo);
    }
    return new Repository(Repository.Kind.GITHUB, owner, repo, repository.getUrl().toExternalForm(), repository.getHttpTransportUrl());
}
Also used : GHRepository(org.kohsuke.github.GHRepository) Repository(org.jreleaser.model.releaser.spi.Repository) GHRepository(org.kohsuke.github.GHRepository)

Example 5 with Repository

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

the class ArticleAnnouncer method publishToRepository.

private void publishToRepository(Path prepareDirectory) throws AnnounceException {
    context.getLogger().info(RB.$("repository.setup"), article.getRepository().getCanonicalRepoName());
    if (context.isDryrun()) {
        return;
    }
    GitService gitService = context.getModel().getRelease().getGitService();
    try {
        // get the repository
        context.getLogger().debug(RB.$("repository.locate"), article.getRepository().getCanonicalRepoName());
        Repository repository = context.getReleaser().maybeCreateRepository(article.getRepository().getOwner(), article.getRepository().getResolvedName(), resolveGitToken(gitService));
        UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(resolveGitUsername(gitService), resolveGitToken(gitService));
        // clone the repository
        context.getLogger().debug(RB.$("repository.clone"), repository.getHttpUrl());
        Path directory = Files.createTempDirectory("jreleaser-" + article.getRepository().getResolvedName());
        Git git = Git.cloneRepository().setCredentialsProvider(credentialsProvider).setBranch(article.getRepository().getBranch()).setDirectory(directory.toFile()).setURI(repository.getHttpUrl()).call();
        copyFiles(prepareDirectory, directory);
        // add everything
        git.add().addFilepattern(".").call();
        Map<String, Object> props = context.fullProps();
        context.getModel().getRelease().getGitService().fillProps(props, context.getModel());
        // setup commit
        context.getLogger().debug(RB.$("repository.commit.setup"));
        CommitCommand commitCommand = git.commit().setAll(true).setMessage(article.getRepository().getResolvedCommitMessage(props)).setAuthor(article.getCommitAuthor().getName(), article.getCommitAuthor().getEmail());
        commitCommand.setCredentialsProvider(credentialsProvider);
        commitCommand = commitCommand.setSign(gitService.isSign()).setSigningKey("**********").setGpgSigner(new JReleaserGpgSigner(context, gitService.isSign()));
        commitCommand.call();
        context.getLogger().info(RB.$("repository.push"), article.getRepository().getCanonicalRepoName());
        // push commit
        context.getLogger().debug(RB.$("repository.commit.push"));
        git.push().setDryRun(false).setPushAll().setCredentialsProvider(credentialsProvider).call();
    } catch (Exception e) {
        throw new AnnounceException(RB.$("ERROR_unexpected_repository_update", article.getRepository().getCanonicalRepoName()), e);
    }
}
Also used : Path(java.nio.file.Path) Repository(org.jreleaser.model.releaser.spi.Repository) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) AnnounceException(org.jreleaser.model.announcer.spi.AnnounceException) Git(org.eclipse.jgit.api.Git) GitService(org.jreleaser.model.GitService) CommitCommand(org.eclipse.jgit.api.CommitCommand) JReleaserGpgSigner(org.jreleaser.sdk.git.JReleaserGpgSigner) IOException(java.io.IOException) AnnounceException(org.jreleaser.model.announcer.spi.AnnounceException) JReleaserException(org.jreleaser.util.JReleaserException)

Aggregations

Repository (org.jreleaser.model.releaser.spi.Repository)8 IOException (java.io.IOException)5 Git (org.eclipse.jgit.api.Git)3 GitService (org.jreleaser.model.GitService)3 Path (java.nio.file.Path)2 CommitCommand (org.eclipse.jgit.api.CommitCommand)2 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)2 JReleaserGpgSigner (org.jreleaser.sdk.git.JReleaserGpgSigner)2 JReleaserException (org.jreleaser.util.JReleaserException)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 RemoteConfig (org.eclipse.jgit.transport.RemoteConfig)1 URIish (org.eclipse.jgit.transport.URIish)1 Codeberg (org.jreleaser.model.Codeberg)1 Github (org.jreleaser.model.Github)1 Gitlab (org.jreleaser.model.Gitlab)1 JReleaserModel (org.jreleaser.model.JReleaserModel)1 RepositoryTap (org.jreleaser.model.RepositoryTap)1 AnnounceException (org.jreleaser.model.announcer.spi.AnnounceException)1 PackagerProcessingException (org.jreleaser.model.packager.spi.PackagerProcessingException)1 ReleaseException (org.jreleaser.model.releaser.spi.ReleaseException)1