Skip to content

Commit

Permalink
feat: adjustments after merge (refs #175)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Oct 30, 2023
1 parent f6c2b3f commit 3b52d87
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 59 deletions.
17 changes: 4 additions & 13 deletions src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <path>...
*
* @param pathFilters the path filters to be used for filtering.
*/
public GitChangelogApi withPathFilters(final List<String> pathFilters) {
this.settings.setPathFilters(pathFilters);
public GitChangelogApi withPathFilters(final String... pathFilters) {
this.settings.setPathFilters(Arrays.asList(pathFilters));
return this;
}

Expand All @@ -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<ObjectId> fromId = this.getFrom(gitRepo, this.settings);
final RevisionBoundary<ObjectId> toId = this.getTo(gitRepo, this.settings);
GitRepoData gitRepoData =
Expand Down
20 changes: 2 additions & 18 deletions src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> pathFilters) {
this.pathFilters = pathFilters;
}

public List<String> getTags(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> pathFilters;

Expand Down Expand Up @@ -708,7 +698,7 @@ public Charset getEncoding() {
return Charset.forName(this.encoding);
}

public void setPathFilters(List<String> pathFilters) {
public void setPathFilters(final List<String> pathFilters) {
this.pathFilters = pathFilters;
}

Expand Down Expand Up @@ -779,7 +769,6 @@ public int hashCode() {
this.semanticMajorPattern,
this.semanticMinorPattern,
this.semanticPatchPattern,
this.subDirFilter,
this.pathFilters,
this.templateBaseDir,
this.templatePath,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -954,8 +942,6 @@ public String toString() {
+ this.semanticPatchPattern
+ ", useIntegrations="
+ this.useIntegrations
+ ", subDirFilter="
+ this.subDirFilter
+ ", pathFilters="
+ this.pathFilters
+ ", encoding="
Expand Down
10 changes: 4 additions & 6 deletions src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,7 +144,7 @@ public void testPathFilterCanBeSpecified() throws Exception {
.withFromCommit(ZERO_COMMIT) //
.withToRef("1.71") //
.withTemplatePath(templatePath) //
.withPathFilter("src");
.withPathFilters("src");

ApprovalsWrapper.verify(given);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ settings:
"gitLabEnabled": true,
"gitLabProjectName": "tomasbjerre",
"useIntegrations": false,
"subDirFilter": "src",
"pathFilters": [
"src"
],
"encoding": "UTF-8"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ settings:
"gitLabEnabled": false,
"gitLabProjectName": "tomasbjerre",
"useIntegrations": true,
"subDirFilter": "src",
"pathFilters": [
"src"
],
"encoding": "UTF-8"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ settings:
"gitLabEnabled": false,
"gitLabProjectName": "tomasbjerre",
"useIntegrations": false,
"subDirFilter": "src",
"pathFilters": [
"src"
],
"encoding": "UTF-8"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand All @@ -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");

Expand Down

0 comments on commit 3b52d87

Please # to comment.