Skip to content

Commit

Permalink
Ignore non-semver tags
Browse files Browse the repository at this point in the history
  • Loading branch information
radoslaw-panuszewski committed Oct 4, 2024
1 parent a158fe6 commit 38cfb73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ root = true
[*]
indent_style = space
indent_size = 4
ij_continuation_indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pl.allegro.tech.build.axion.release.infrastructure.git;

import com.github.zafarkhaja.semver.ParseException;
import com.github.zafarkhaja.semver.Version;
import org.eclipse.jgit.api.*;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.NoHeadException;
Expand Down Expand Up @@ -491,13 +493,24 @@ private Map<String, List<String>> tagsMatching(List<Pattern> patterns, RevWalk w
parseCommitSafe(walk, tag.getObjectId())
))
.filter(t -> patterns.stream().anyMatch(pattern -> pattern.matcher(t.name).matches()))
.filter(t -> isSemver(t.name))
.collect(
HashMap::new,
(m, t) -> m.computeIfAbsent(t.id, (s) -> new ArrayList<>()).add(t.name),
HashMap::putAll
);
}

private boolean isSemver(String tagName) {
try {
Version.valueOf(tagName);
return true;
} catch (ParseException e) {
logger.info("Found non-semver tag '{}' matching one of the configured prefixes, ignoring it.", tagName);
return false;
}
}

private String parseCommitSafe(RevWalk walk, AnyObjectId commitId) {
try {
return walk.parseCommit(commitId).getName();
Expand Down

0 comments on commit 38cfb73

Please sign in to comment.