Skip to content

Commit

Permalink
[model] add a branch field to repository taps/buckets. Resolves #313
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 26, 2021
1 parent 914146d commit ccd13c4
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public abstract class AbstractRepositoryTap implements RepositoryTap {
protected String basename;
protected String owner;
protected String name;
protected String branch;
protected String username;
protected String token;

Expand All @@ -53,6 +54,7 @@ public void setBasename(String basename) {
void setAll(AbstractRepositoryTap tap) {
this.owner = tap.owner;
this.name = tap.name;
this.branch = tap.branch;
this.username = tap.username;
this.token = tap.token;
}
Expand Down Expand Up @@ -102,6 +104,16 @@ public void setName(String name) {
this.name = name;
}

@Override
public String getBranch() {
return branch;
}

@Override
public void setBranch(String branch) {
this.branch = branch;
}

@Override
public String getUsername() {
return username;
Expand All @@ -127,6 +139,7 @@ public Map<String, Object> asMap(boolean full) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("owner", owner);
map.put("name", getResolvedName());
map.put("branch", branch);
map.put("username", username);
map.put("token", isNotBlank(token) ? HIDE : UNSET);
return map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public interface RepositoryTap extends Domain, OwnerAware {

void setName(String name);

String getBranch();

void setBranch(String branch);

String getUsername();

void setUsername(String username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static void validateArticle(JReleaserContext context, Article article, Er

validateCommitAuthor(article, service);
validateOwner(repository, service);

if (isBlank(repository.getName())) {
errors.configuration("announce.article.repository.name must not be blank.");
}
Expand All @@ -60,6 +61,13 @@ public static void validateArticle(JReleaserContext context, Article article, Er
repository.getToken(),
service.getResolvedToken()));

repository.setBranch(
checkProperty(context,
Env.toVar(repository.getBasename() + "_" + service.getServiceName()) + "_BRANCH",
"announce.article.repository.branch",
repository.getBranch(),
"HEAD"));

if (isBlank(article.getTemplateDirectory())) {
article.setTemplateDirectory("src/jreleaser/templates/article");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.jreleaser.model.HomebrewTap;
import org.jreleaser.model.JReleaserContext;
import org.jreleaser.model.JReleaserModel;
import org.jreleaser.util.Env;
import org.jreleaser.util.Errors;
import org.jreleaser.util.PlatformUtils;

Expand Down Expand Up @@ -66,6 +65,9 @@ public static void validateBrew(JReleaserContext context, Distribution distribut
validateCommitAuthor(tool, parentTool);
HomebrewTap tap = tool.getTap();
validateOwner(tap, parentTool.getTap());
if (isBlank(tap.getBranch())) {
tap.setBranch(parentTool.getTap().getBranch());
}
validateTemplate(context, distribution, tool, parentTool, errors);
mergeExtraProperties(tool, parentTool);
validateContinueOnError(tool, parentTool);
Expand All @@ -88,19 +90,7 @@ public static void validateBrew(JReleaserContext context, Distribution distribut
tap.setToken(parentTool.getTap().getToken());
}

tap.setUsername(
checkProperty(context,
Env.toVar(tap.getBasename() + "_" + service.getServiceName()) + "_USERNAME",
"distribution." + distribution.getName() + "brew.tap.username",
tap.getUsername(),
service.getResolvedUsername()));

tap.setToken(
checkProperty(context,
Env.toVar(tap.getBasename() + "_" + service.getServiceName()) + "_TOKEN",
"distribution." + distribution.getName() + "brew.tap.token",
tap.getToken(),
service.getResolvedToken()));
validateTap(context, distribution, tap, "brew.tap");

if (!tool.isMultiPlatformSet() && parentTool.isMultiPlatformSet()) {
tool.setMultiPlatform(parentTool.isMultiPlatform());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.jreleaser.model.GitService;
import org.jreleaser.model.JReleaserContext;
import org.jreleaser.model.JReleaserModel;
import org.jreleaser.util.Env;
import org.jreleaser.util.Errors;

import static org.jreleaser.model.validation.DistributionsValidator.validateArtifactPlatforms;
Expand Down Expand Up @@ -55,6 +54,9 @@ public static void validateChocolatey(JReleaserContext context, Distribution dis
validateCommitAuthor(tool, parentTool);
ChocolateyBucket bucket = tool.getBucket();
validateOwner(bucket, parentTool.getBucket());
if (isBlank(bucket.getBranch())) {
bucket.setBranch(parentTool.getBucket().getBranch());
}
validateTemplate(context, distribution, tool, parentTool, errors);
mergeExtraProperties(tool, parentTool);
validateContinueOnError(tool, parentTool);
Expand All @@ -77,19 +79,7 @@ public static void validateChocolatey(JReleaserContext context, Distribution dis
bucket.setToken(parentTool.getBucket().getToken());
}

bucket.setUsername(
checkProperty(context,
Env.toVar(bucket.getBasename() + "_" + service.getServiceName()) + "_USERNAME",
"distribution." + distribution.getName() + "chocolatey.bucket.username",
bucket.getUsername(),
service.getResolvedUsername()));

bucket.setToken(
checkProperty(context,
Env.toVar(bucket.getBasename() + "_" + service.getServiceName()) + "_TOKEN",
"distribution." + distribution.getName() + "chocolatey.bucket.token",
bucket.getToken(),
service.getResolvedToken()));
validateTap(context, distribution, bucket, "chocolatey.bucket");

validateArtifactPlatforms(context, distribution, tool, errors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public static void validateDocker(JReleaserContext context, Distribution distrib
validateCommitAuthor(tool, parentTool);
DockerRepository repository = tool.getRepository();
validateOwner(repository, parentTool.getRepository());
if (isBlank(repository.getBranch())) {
repository.setBranch(parentTool.getRepository().getBranch());
}
mergeExtraProperties(tool, parentTool);
validateContinueOnError(tool, parentTool);

Expand All @@ -99,6 +102,8 @@ public static void validateDocker(JReleaserContext context, Distribution distrib
repository.setToken(parentTool.getRepository().getToken());
}

validateTap(context, distribution, repository, "docker.repository");

if (isBlank(tool.getBaseImage())) {
tool.setBaseImage(parentTool.getBaseImage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.jreleaser.model.JReleaserModel;
import org.jreleaser.model.Jbang;
import org.jreleaser.model.JbangCatalog;
import org.jreleaser.util.Env;
import org.jreleaser.util.Errors;

import java.util.List;
Expand Down Expand Up @@ -60,6 +59,9 @@ public static void validateJbang(JReleaserContext context, Distribution distribu
validateCommitAuthor(tool, parentTool);
JbangCatalog catalog = tool.getCatalog();
validateOwner(catalog, parentTool.getCatalog());
if (isBlank(catalog.getBranch())) {
catalog.setBranch(parentTool.getCatalog().getBranch());
}
validateTemplate(context, distribution, tool, parentTool, errors);
mergeExtraProperties(tool, parentTool);
validateContinueOnError(tool, parentTool);
Expand All @@ -77,19 +79,7 @@ public static void validateJbang(JReleaserContext context, Distribution distribu
catalog.setToken(parentTool.getCatalog().getToken());
}

catalog.setUsername(
checkProperty(context,
Env.toVar(catalog.getBasename() + "_" + service.getServiceName()) + "_USERNAME",
"distribution." + distribution.getName() + "jbang.catalog.username",
catalog.getUsername(),
service.getResolvedUsername()));

catalog.setToken(
checkProperty(context,
Env.toVar(catalog.getBasename() + "_" + service.getServiceName()) + "_TOKEN",
"distribution." + distribution.getName() + "jbang.catalog.token",
catalog.getToken(),
service.getResolvedToken()));
validateTap(context, distribution, catalog, "jbang.catalog");

if (model.getProject().getExtraProperties().containsKey(KEY_REVERSE_REPO_HOST) &&
!parentTool.getExtraProperties().containsKey(KEY_REVERSE_REPO_HOST)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,9 @@ private static void validatePackager(JReleaserContext context,
"<empty>",
tap.getToken(),
service.getResolvedToken()));

if (isBlank(tap.getBranch())) {
tap.setBranch("HEAD");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.jreleaser.model.JReleaserModel;
import org.jreleaser.model.Scoop;
import org.jreleaser.model.ScoopBucket;
import org.jreleaser.util.Env;
import org.jreleaser.util.Errors;

import java.util.Set;
Expand Down Expand Up @@ -59,6 +58,9 @@ public static void validateScoop(JReleaserContext context, Distribution distribu
validateCommitAuthor(tool, parentTool);
ScoopBucket bucket = tool.getBucket();
validateOwner(bucket, parentTool.getBucket());
if (isBlank(bucket.getBranch())) {
bucket.setBranch(parentTool.getBucket().getBranch());
}
validateTemplate(context, distribution, tool, parentTool, errors);
mergeExtraProperties(tool, parentTool);
validateContinueOnError(tool, parentTool);
Expand Down Expand Up @@ -88,19 +90,7 @@ public static void validateScoop(JReleaserContext context, Distribution distribu
bucket.setToken(parentTool.getBucket().getToken());
}

bucket.setUsername(
checkProperty(context,
Env.toVar(bucket.getBasename() + "_" + service.getServiceName()) + "_USERNAME",
"distribution." + distribution.getName() + "scoop.bucket.username",
bucket.getUsername(),
service.getResolvedUsername()));

bucket.setToken(
checkProperty(context,
Env.toVar(bucket.getBasename() + "_" + service.getServiceName()) + "_TOKEN",
"distribution." + distribution.getName() + "scoop.bucket.token",
bucket.getToken(),
service.getResolvedToken()));
validateTap(context, distribution, bucket, "scoop.bucket");

validateArtifactPlatforms(context, distribution, tool, errors);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.jreleaser.model.Slot;
import org.jreleaser.model.Snap;
import org.jreleaser.model.SnapTap;
import org.jreleaser.util.Env;
import org.jreleaser.util.Errors;

import java.util.ArrayList;
Expand Down Expand Up @@ -63,6 +62,9 @@ public static void validateSnap(JReleaserContext context, Distribution distribut
validateCommitAuthor(tool, parentTool);
SnapTap snap = tool.getSnap();
validateOwner(snap, parentTool.getSnap());
if (isBlank(snap.getBranch())) {
snap.setBranch(parentTool.getSnap().getBranch());
}
validateTemplate(context, distribution, tool, parentTool, errors);
mergeExtraProperties(tool, parentTool);
validateContinueOnError(tool, parentTool);
Expand Down Expand Up @@ -111,19 +113,7 @@ public static void validateSnap(JReleaserContext context, Distribution distribut
snap.setToken(parentTool.getSnap().getToken());
}

snap.setUsername(
checkProperty(context,
Env.toVar(snap.getBasename() + "_" + service.getServiceName()) + "_USERNAME",
"distribution." + distribution.getName() + "snap.snap.username",
snap.getUsername(),
service.getResolvedUsername()));

snap.setToken(
checkProperty(context,
Env.toVar(snap.getBasename() + "_" + service.getServiceName()) + "_TOKEN",
"distribution." + distribution.getName() + "snap.snap.token",
snap.getToken(),
service.getResolvedToken()));
validateTap(context, distribution, snap, "snap.snap");

validateArtifactPlatforms(context, distribution, tool, errors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@

import org.jreleaser.model.CommitAuthor;
import org.jreleaser.model.CommitAuthorAware;
import org.jreleaser.model.Distribution;
import org.jreleaser.model.Environment;
import org.jreleaser.model.GitService;
import org.jreleaser.model.JReleaserContext;
import org.jreleaser.model.OwnerAware;
import org.jreleaser.model.RepositoryTap;
import org.jreleaser.model.TimeoutAware;
import org.jreleaser.model.Tool;
import org.jreleaser.util.Env;
Expand Down Expand Up @@ -108,4 +111,29 @@ static void validateTimeout(TimeoutAware self) {
self.setReadTimeout(60);
}
}

static void validateTap(JReleaserContext context, Distribution distribution, RepositoryTap tap, String property) {
GitService service = context.getModel().getRelease().getGitService();

tap.setUsername(
checkProperty(context,
Env.toVar(tap.getBasename() + "_" + service.getServiceName()) + "_USERNAME",
"distribution." + distribution.getName() + "." + property + ".username",
tap.getUsername(),
service.getResolvedUsername()));

tap.setToken(
checkProperty(context,
Env.toVar(tap.getBasename() + "_" + service.getServiceName()) + "_TOKEN",
"distribution." + distribution.getName() + "." + property + ".token",
tap.getToken(),
service.getResolvedToken()));

tap.setBranch(
checkProperty(context,
Env.toVar(tap.getBasename() + "_" + service.getServiceName()) + "_BRANCH",
"distribution." + distribution.getName() + "." + property + ".branch",
tap.getBranch(),
"HEAD"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void publishToRepository(Path prepareDirectory) throws AnnounceException
Path directory = Files.createTempDirectory("jreleaser-" + article.getRepository().getResolvedName());
Git git = Git.cloneRepository()
.setCredentialsProvider(credentialsProvider)
.setBranch("HEAD")
.setBranch(article.getRepository().getBranch())
.setDirectory(directory.toFile())
.setURI(repository.getHttpUrl())
.call();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected void doPublishDistribution(Distribution distribution, Map<String, Obje
Path directory = Files.createTempDirectory("jreleaser-" + tool.getRepositoryTap().getResolvedName());
Git git = Git.cloneRepository()
.setCredentialsProvider(credentialsProvider)
.setBranch("HEAD")
.setBranch(tool.getRepositoryTap().getBranch())
.setDirectory(directory.toFile())
.setURI(repository.getHttpUrl())
.call();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ interface Tap {
Property<String> getUsername()

Property<String> getToken()

Property<String> getBranch()
}

0 comments on commit ccd13c4

Please sign in to comment.