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;
}
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());
}
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());
}
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());
}
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);
}
}
Aggregations