Skip to content
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

Improvement for isRevExcluded method. For matching on commit message #1516

Closed
wants to merge 1 commit into from
Closed
Changes from all 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 @@ -25,53 +25,75 @@
* @author Kanstantsin Shautsou
*/
public class MessageExclusion extends GitSCMExtension {
/**
* Java Pattern for matching messages to be ignored.
*/
private String excludedMessage;
/**
* Java Pattern for matching messages to be ignored.
*/
private String excludedMessage;

private transient volatile Pattern excludedPattern;
private transient volatile Pattern excludedPattern;

@DataBoundConstructor
public MessageExclusion(String excludedMessage) { this.excludedMessage = excludedMessage; }
@DataBoundConstructor
public MessageExclusion(String excludedMessage) {
this.excludedMessage = excludedMessage;
}

@Override
public boolean requiresWorkspaceForPolling() { return true; }
@Override
public boolean requiresWorkspaceForPolling() {
return true;
}

public String getExcludedMessage() { return excludedMessage; }
public String getExcludedMessage() {
return excludedMessage;
}

@Override
@SuppressFBWarnings(value="NP_BOOLEAN_RETURN_NULL", justification="null used to indicate other extensions should decide")
@CheckForNull
public Boolean isRevExcluded(GitSCM scm, GitClient git, GitChangeSet commit, TaskListener listener, BuildData buildData) throws IOException, InterruptedException, GitException {
if (excludedPattern == null){
excludedPattern = Pattern.compile(excludedMessage);
}
String msg = commit.getComment();
if (excludedPattern.matcher(msg).matches()){
listener.getLogger().println("Ignored commit " + commit.getId() + ": Found excluded message: " + msg);
return true;
}
@Override
@SuppressFBWarnings(value = "NP_BOOLEAN_RETURN_NULL", justification = "null used to indicate other extensions should decide")
@CheckForNull
public Boolean isRevExcluded(GitSCM scm, GitClient git, GitChangeSet commit, TaskListener listener, BuildData buildData) throws IOException, InterruptedException, GitException {
if (excludedMessage == null || excludedMessage.trim().isEmpty()) {

Check warning on line 53 in src/main/java/hudson/plugins/git/extensions/impl/MessageExclusion.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 53 is only partially covered, 2 branches are missing
listener.getLogger().println("Excluded message pattern is empty. No commits will be excluded based on message.");
return null; // No decision

Check warning on line 55 in src/main/java/hudson/plugins/git/extensions/impl/MessageExclusion.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 54-55 are not covered by tests
}

return null;
}
if (excludedPattern == null) {
try {
excludedPattern = Pattern.compile(excludedMessage);
} catch (PatternSyntaxException ex) {
listener.getLogger().println("Error compiling the excluded message pattern: " + ex.getMessage());
return null; // Pattern is invalid, so no decision

Check warning on line 63 in src/main/java/hudson/plugins/git/extensions/impl/MessageExclusion.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 61-63 are not covered by tests
}
}

@Extension
// No @Symbol annotation because message exclusion is done using a trait in Pipeline
public static class DescriptorImpl extends GitSCMExtensionDescriptor {
String msg = commit.getComment();
if (msg == null) {

Check warning on line 68 in src/main/java/hudson/plugins/git/extensions/impl/MessageExclusion.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 68 is only partially covered, one branch is missing
listener.getLogger().println("Commit " + commit.getId() + " has a null message. It won't be excluded based on message.");
return null; // Commit message is null, so no decision

Check warning on line 70 in src/main/java/hudson/plugins/git/extensions/impl/MessageExclusion.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 69-70 are not covered by tests
}

public FormValidation doCheckExcludedMessage(@QueryParameter String value) {
try {
Pattern.compile(value);
} catch (PatternSyntaxException ex){
return FormValidation.error(ex.getMessage());
}
return FormValidation.ok();
}
if (excludedPattern.matcher(msg).find()) {

Check warning on line 73 in src/main/java/hudson/plugins/git/extensions/impl/MessageExclusion.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 73 is only partially covered, one branch is missing
listener.getLogger().println("Ignored commit " + commit.getId() + ": Found excluded message: " + msg);
return true; // Commit message contains the excluded pattern
}

@Override
public String getDisplayName() {
return "Polling ignores commits with certain messages";
}
}
return null; // No decision

Check warning on line 78 in src/main/java/hudson/plugins/git/extensions/impl/MessageExclusion.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 78 is not covered by tests
}

@Extension
// No @Symbol annotation because message exclusion is done using a trait in Pipeline
public static class DescriptorImpl extends GitSCMExtensionDescriptor {

public FormValidation doCheckExcludedMessage(@QueryParameter String value) {
try {
Pattern.compile(value);
} catch (PatternSyntaxException ex) {
return FormValidation.error(ex.getMessage());
}
return FormValidation.ok();
}

@Override
public String getDisplayName() {
return "Polling ignores commits with certain messages";
}
}
}
Loading