diff --git a/src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java b/src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java index 34751cb..7063a08 100644 --- a/src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java +++ b/src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java @@ -22,6 +22,7 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; @@ -689,24 +690,14 @@ public GitChangelogApi withToCommit(final String toCommit) { public GitChangelogApi withToRef(final String toBranch) { return this.withToRevision(toBranch); } - - /** - * Filter commits using the provided path filter, analogous to using the cli command git log -- - * 'pathFilter' - */ - public GitChangelogApi withPathFilter(final String pathFilter) { - this.settings.setPathFilter(pathFilter); - return this; - } - /** * Filter commits using the provided path filters, analogous to using the cli command git log -- * git log ... * * @param pathFilters the path filters to be used for filtering. */ - public GitChangelogApi withPathFilters(final List pathFilters) { - this.settings.setPathFilters(pathFilters); + public GitChangelogApi withPathFilters(final String... pathFilters) { + this.settings.setPathFilters(Arrays.asList(pathFilters)); return this; } @@ -722,7 +713,7 @@ public GitChangelogApi withUntaggedName(final String untaggedName) { private Changelog getChangelog(final GitRepo gitRepo, final boolean useIntegrations) throws GitChangelogRepositoryException { - gitRepo.setPathFilters(this.settings.getSubDirFilter(), this.settings.getPathFilters()); + gitRepo.setPathFilters(this.settings.getPathFilters()); final RevisionBoundary fromId = this.getFrom(gitRepo, this.settings); final RevisionBoundary toId = this.getTo(gitRepo, this.settings); GitRepoData gitRepoData = diff --git a/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java b/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java index d2dd40b..a220ca8 100644 --- a/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java +++ b/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java @@ -653,24 +653,8 @@ private GitCommit toGitCommit(final RevCommit revCommit) { merge); } - /** - * Sets the pathFilters to be used when filtering commits - * - * @param pathFilter used when filtering commits from single path (kept to ensure backwards - * compatibility) - * @param pathFilters used when filtering commits from multiple paths - */ - public void setPathFilters(final String pathFilter, List pathFilters) { - if (pathFilters == null) { - if (pathFilter != null && !pathFilter.isEmpty()) { - this.pathFilters.add(pathFilter); - } - } else { - if (pathFilter != null && !pathFilter.isEmpty()) { - pathFilters.add(pathFilter); - } - this.pathFilters = pathFilters; - } + public void setPathFilters(List pathFilters) { + this.pathFilters = pathFilters; } public List getTags( diff --git a/src/main/java/se/bjurr/gitchangelog/internal/settings/Settings.java b/src/main/java/se/bjurr/gitchangelog/internal/settings/Settings.java index ad4fca3..8786653 100644 --- a/src/main/java/se/bjurr/gitchangelog/internal/settings/Settings.java +++ b/src/main/java/se/bjurr/gitchangelog/internal/settings/Settings.java @@ -235,16 +235,6 @@ public class Settings implements Serializable { /** Integrate with services to get more details about issues. */ private boolean useIntegrations; - public String getSubDirFilter() { - return ofNullable(this.subDirFilter).orElse(""); - } - - public void setPathFilter(final String subDirFilter) { - this.subDirFilter = subDirFilter; - } - - private String subDirFilter; - /** Path filters to use for filtering commits */ private List pathFilters; @@ -708,7 +698,7 @@ public Charset getEncoding() { return Charset.forName(this.encoding); } - public void setPathFilters(List pathFilters) { + public void setPathFilters(final List pathFilters) { this.pathFilters = pathFilters; } @@ -779,7 +769,6 @@ public int hashCode() { this.semanticMajorPattern, this.semanticMinorPattern, this.semanticPatchPattern, - this.subDirFilter, this.pathFilters, this.templateBaseDir, this.templatePath, @@ -844,7 +833,6 @@ public boolean equals(final Object obj) { && Objects.equals(this.semanticMajorPattern, other.semanticMajorPattern) && Objects.equals(this.semanticMinorPattern, other.semanticMinorPattern) && Objects.equals(this.semanticPatchPattern, other.semanticPatchPattern) - && Objects.equals(this.subDirFilter, other.subDirFilter) && Objects.equals(this.pathFilters, other.pathFilters) && Objects.equals(this.templateBaseDir, other.templateBaseDir) && Objects.equals(this.templatePath, other.templatePath) @@ -954,8 +942,6 @@ public String toString() { + this.semanticPatchPattern + ", useIntegrations=" + this.useIntegrations - + ", subDirFilter=" - + this.subDirFilter + ", pathFilters=" + this.pathFilters + ", encoding=" diff --git a/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.java b/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.java index 75c058b..37c9a4e 100644 --- a/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.java +++ b/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.java @@ -13,8 +13,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; import org.junit.After; @@ -146,7 +144,7 @@ public void testPathFilterCanBeSpecified() throws Exception { .withFromCommit(ZERO_COMMIT) // .withToRef("1.71") // .withTemplatePath(templatePath) // - .withPathFilter("src"); + .withPathFilters("src"); ApprovalsWrapper.verify(given); } @@ -164,7 +162,7 @@ public void testPathFiltersCanBeSpecified() throws Exception { .withFromRevision(ZERO_COMMIT) .withToRevision("1.71") // .withTemplatePath(templatePath) // - .withPathFilters(new ArrayList<>(Arrays.asList("src"))); + .withPathFilters("src"); ApprovalsWrapper.verify(given); } @@ -367,7 +365,7 @@ public void testThatOnlyGithubIssuesCanBeParsed() throws Exception { .withUseIntegrations(true) .withFromCommit(ZERO_COMMIT) // .withToRef("1.71") // - .withPathFilter("src") + .withPathFilters("src") .withIgnoreCommitsWithoutIssue(true); ApprovalsWrapper.verify(given); @@ -380,7 +378,7 @@ public void testThatOnlyJiraIssuesCanBeParsed() throws Exception { .withJiraEnabled(true) .withFromCommit(ZERO_COMMIT) // .withToRef("1.71") // - .withPathFilter("src") + .withPathFilters("src") .withIgnoreCommitsWithoutIssue(true); ApprovalsWrapper.verify(given); diff --git a/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testPathFilterCanBeSpecified.approved.txt b/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testPathFilterCanBeSpecified.approved.txt index 1014360..abf7ca0 100644 --- a/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testPathFilterCanBeSpecified.approved.txt +++ b/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testPathFilterCanBeSpecified.approved.txt @@ -30,7 +30,9 @@ settings: "gitLabEnabled": true, "gitLabProjectName": "tomasbjerre", "useIntegrations": false, - "subDirFilter": "src", + "pathFilters": [ + "src" + ], "encoding": "UTF-8" } diff --git a/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatOnlyGithubIssuesCanBeParsed.approved.txt b/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatOnlyGithubIssuesCanBeParsed.approved.txt index fdb0292..44d6c34 100644 --- a/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatOnlyGithubIssuesCanBeParsed.approved.txt +++ b/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatOnlyGithubIssuesCanBeParsed.approved.txt @@ -77,7 +77,9 @@ settings: "gitLabEnabled": false, "gitLabProjectName": "tomasbjerre", "useIntegrations": true, - "subDirFilter": "src", + "pathFilters": [ + "src" + ], "encoding": "UTF-8" } diff --git a/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatOnlyJiraIssuesCanBeParsed.approved.txt b/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatOnlyJiraIssuesCanBeParsed.approved.txt index d96e217..cf5f70f 100644 --- a/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatOnlyJiraIssuesCanBeParsed.approved.txt +++ b/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.testThatOnlyJiraIssuesCanBeParsed.approved.txt @@ -77,7 +77,9 @@ settings: "gitLabEnabled": false, "gitLabProjectName": "tomasbjerre", "useIntegrations": false, - "subDirFilter": "src", + "pathFilters": [ + "src" + ], "encoding": "UTF-8" } diff --git a/src/test/java/se/bjurr/gitchangelog/internal/git/GitRepoTest.java b/src/test/java/se/bjurr/gitchangelog/internal/git/GitRepoTest.java index e0cdd43..3318b01 100644 --- a/src/test/java/se/bjurr/gitchangelog/internal/git/GitRepoTest.java +++ b/src/test/java/se/bjurr/gitchangelog/internal/git/GitRepoTest.java @@ -319,7 +319,7 @@ public void testThatZeroCommitCanBeRetrieved() throws Exception { @Test public void testThatRepoFilterReducesTheNumberOfCommits() throws Exception { final GitRepo gitRepo = this.getGitRepo(); - gitRepo.setPathFilters("src/", null); + gitRepo.setPathFilters(Arrays.asList("src/")); final ObjectId firstCommit = gitRepo.getCommit(ZERO_COMMIT); final ObjectId lastCommit = gitRepo.getRef("1.71"); @@ -343,7 +343,7 @@ public void testThatRepoFilterReducesTheNumberOfCommits() throws Exception { @Test public void testThatRepoFilterReducesTheNumberOfCommitsUsingPathFilters() throws Exception { final GitRepo gitRepo = this.getGitRepo(); - gitRepo.setPathFilters(null, Arrays.asList("src/")); + gitRepo.setPathFilters(Arrays.asList("src/")); final ObjectId firstCommit = gitRepo.getCommit(ZERO_COMMIT); final ObjectId lastCommit = gitRepo.getRef("1.71"); @@ -368,7 +368,7 @@ public void testThatRepoFilterReducesTheNumberOfCommitsUsingPathFilters() throws public void testThatRepoFilterIncreasesTheNumberOfCommitsUsingMultiplePathFilters() throws Exception { final GitRepo gitRepo = this.getGitRepo(); - gitRepo.setPathFilters(null, Arrays.asList("src/", "examples/")); + gitRepo.setPathFilters(Arrays.asList("src/", "examples/")); final ObjectId firstCommit = gitRepo.getCommit(ZERO_COMMIT); final ObjectId lastCommit = gitRepo.getRef("1.71"); @@ -394,7 +394,7 @@ public void testThatRepoFilterIncreasesTheNumberOfCommitsUsingMultiplePathFilter testThatRepoFilterIncreasesTheNumberOfCommitsUsingBothPathFilterAndMultiplePathFilters() throws Exception { final GitRepo gitRepo = this.getGitRepo(); - gitRepo.setPathFilters("src/", new ArrayList<>(Arrays.asList("examples/"))); + gitRepo.setPathFilters(Arrays.asList("src/", "examples/")); final ObjectId firstCommit = gitRepo.getCommit(ZERO_COMMIT); final ObjectId lastCommit = gitRepo.getRef("1.71");