Skip to content

Commit

Permalink
support regex patterns for tagFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Corley committed Aug 20, 2024
1 parent 4847391 commit 89ec916
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,26 @@ private boolean notMatchUseRepository(String gitUrl) {
private Set<String> getTag(GitClient gitClient, String gitUrl) throws InterruptedException {
Set<String> tagSet = new HashSet<>();
try {
Map<String, ObjectId> tags = gitClient.getRemoteReferences(gitUrl, tagFilter, false, true);

Map<String, ObjectId> tags = null;

boolean isRegex = tagFilter != null && tagFilter.startsWith("/");
tags = gitClient.getRemoteReferences(gitUrl, isRegex ? "*" : tagFilter, false, true);

Pattern pattern = null;
if (isRegex) {
pattern = Pattern.compile(tagFilter.substring(1));
}

for (String tagName : tags.keySet()) {
tagSet.add(tagName.replaceFirst(REFS_TAGS_PATTERN, ""));
tagName = tagName.replaceFirst(REFS_TAGS_PATTERN, "");
if (isRegex) {
if (pattern.matcher(tagName).matches()) {
tagSet.add(tagName);
}
} else {
tagSet.add(tagName);
}
}
} catch (GitException e) {
LOGGER.log(Level.WARNING, getCustomJobName() + " " + Messages.GitParameterDefinition_getTag(), e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div>
This parameter is used to get tag from git.<br/>
If is blank, parameter is set to "*".<br/>
Regex patterns must be prefixed with with a forward slash (ie /.*).
Properly is executed command: <tt>git ls-remote -t &lt;repository&gt; "*"</tt> or <tt>git ls-remote -t &lt;repository&gt; "$tagFilter"</tt>.<br/>
<a href="https://git-scm.com/docs/git-ls-remote.html">git-ls-remote</a> documentation.
</div>

0 comments on commit 89ec916

Please sign in to comment.