use of org.jreleaser.sdk.gitlab.api.Release 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());
}
}
}
use of org.jreleaser.sdk.gitlab.api.Release 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);
}
}
Aggregations