Skip to content

JENKINS-73658 Support regex for tag filter #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,26 @@
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("/");

Check warning on line 388 in src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 388 is only partially covered, 2 branches are missing
tags = gitClient.getRemoteReferences(gitUrl, isRegex ? "*" : tagFilter, false, true);

Check warning on line 389 in src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 389 is only partially covered, one branch is missing

Pattern pattern = null;
if (isRegex) {

Check warning on line 392 in src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 392 is only partially covered, one branch is missing
pattern = Pattern.compile(tagFilter.substring(1));

Check warning on line 393 in src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 393 is not covered by tests
}

for (String tagName : tags.keySet()) {
tagSet.add(tagName.replaceFirst(REFS_TAGS_PATTERN, ""));
tagName = tagName.replaceFirst(REFS_TAGS_PATTERN, "");
if (isRegex) {

Check warning on line 398 in src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 398 is only partially covered, one branch is missing
if (pattern.matcher(tagName).matches()) {
tagSet.add(tagName);

Check warning on line 400 in src/main/java/net/uaznia/lukanus/hudson/plugins/gitparameter/GitParameterDefinition.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 399-400 are not covered by tests
}
} 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 /.*).<br/>
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>
Loading