Skip to content

Commit

Permalink
fix(release): Do not tag local repository if owner/name do not match. F…
Browse files Browse the repository at this point in the history
…ixes #891
  • Loading branch information
aalmiray committed Aug 13, 2022
1 parent 85bb145 commit 5659d28
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.jreleaser.sdk.git.GitSdk;
import org.jreleaser.util.Env;
import org.jreleaser.util.JReleaserException;
import org.jreleaser.util.JReleaserLogger;

import static org.jreleaser.model.GitService.BRANCH;
import static org.jreleaser.util.StringUtils.isBlank;
Expand Down Expand Up @@ -87,7 +88,7 @@ private static void autoConfigureGithub(JReleaserContext context, Repository rep
context.getModel().getRelease().setGithub(new Github());
}

fillGitProperties(context.getModel().getRelease().getGitService(),
fillGitProperties(context.getLogger(), context.getModel().getRelease().getGitService(),
repository, context.getModel().getCommit());
}

Expand All @@ -104,7 +105,7 @@ private static void autoConfigureGitlab(JReleaserContext context, Repository rep
context.getModel().getRelease().setGitlab(new Gitlab());
}

fillGitProperties(context.getModel().getRelease().getGitService(),
fillGitProperties(context.getLogger(), context.getModel().getRelease().getGitService(),
repository, context.getModel().getCommit());
}

Expand All @@ -121,25 +122,35 @@ private static void autoConfigureCodeberg(JReleaserContext context, Repository r
context.getModel().getRelease().setCodeberg(new Codeberg());
}

fillGitProperties(context.getModel().getRelease().getGitService(),
fillGitProperties(context.getLogger(), context.getModel().getRelease().getGitService(),
repository, context.getModel().getCommit());
}

private static void autoConfigureOther(JReleaserContext context, Repository repository) {
GitService service = context.getModel().getRelease().getGitService();

if (service != null) {
fillGitProperties(service, repository, context.getModel().getCommit());
fillGitProperties(context.getLogger(), service, repository, context.getModel().getCommit());
}
}

private static void fillGitProperties(GitService service, Repository repository, Commit head) {
private static void fillGitProperties(JReleaserLogger logger, GitService service, Repository repository, Commit head) {
if (isBlank(service.getOwner())) {
service.setOwner(repository.getOwner());
} else if (!service.getOwner().equals(repository.getOwner())) {
service.setMatch(false);
service.setSkipTag(true);
logger.warn(RB.$("ERROR_context_configurer_detected_git_owner"), repository.getOwner(), service.getOwner());
}

if (isBlank(service.getName())) {
service.setName(repository.getName());
} else if (!service.getName().equals(repository.getName())) {
service.setMatch(false);
service.setSkipTag(true);
logger.warn(RB.$("ERROR_context_configurer_detected_git_name"), repository.getName(), service.getName());
}

if (isBlank(Env.env(BRANCH, service.getBranch()))) {
service.setBranch(head.getRefName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ ERROR_context_configurer_fail_git_head = Could not determine git HEAD
ERROR_context_configurer_fail_git_remote = Could not determine remote
ERROR_context_configurer_jreleaser_misconfigured = JReleaser has not been properly configured.
ERROR_context_configurer_detected_git = Auto configure detected {} but project has {} configured
ERROR_context_configurer_detected_git_owner = Auto configure detected {} as repository owner but project has {} configured
ERROR_context_configurer_detected_git_name = Auto configure detected {} as repository name but project has {} configured
ERROR_version_parse = Cannot parse version '{}'
ERROR_version_parse_with = Cannot parse version '{}' with '{}'
ERROR_unsupported_algorithm = Unsupported algorithm {}
Expand Down

0 comments on commit 5659d28

Please sign in to comment.