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

feat(git): add merge filter options #241

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ npx changelogen@latest [...args] [--dir <dir>]
- `--output`: Changelog file name to create or update. Defaults to `CHANGELOG.md` and resolved relative to dir. Use `--no-output` to write to console only.
- `--bump`: Determine semver change and update version in `package.json`.
- `--release`. Bumps version in `package.json` and creates commit and git tags using local `git`. You can disable commit using `--no-commit` and tag using `--no-tag`. You can enable the automatic push of the new tag and release commit to your git repository by adding `--push`.
- `--onlyMerges`: Use merge commits in changelog.
- `--noMerges`: Exclude merge commits in changelog.
- `--publish`. Publishes package as a new version on `npm`. You will need to set authorisation tokens separately via `.npmrc` or environment variables.
- `--publishTag` Use custom npm tag for publishing (Default is `latest`)
- `--nameSuffix`: Adds suffix to package name (Example: `--nameSuffix canary` renames `foo` to `foo-canary`)
Expand Down
10 changes: 9 additions & 1 deletion src/commands/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@
const logger = consola.create({ stdout: process.stderr });
logger.info(`Generating changelog for ${config.from || ""}...${config.to}`);

const rawCommits = await getGitDiff(config.from, config.to);
let onlyMerges: boolean;
if (args.onlyMerges) {
onlyMerges = true;
}
if (args.noMerges) {
onlyMerges = false;
}

Check warning on line 47 in src/commands/default.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/default.ts#L41-L47

Added lines #L41 - L47 were not covered by tests

const rawCommits = await getGitDiff(config.from, config.to, onlyMerges);

Check warning on line 49 in src/commands/default.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/default.ts#L49

Added line #L49 was not covered by tests

// Parse commits as conventional commits
const commits = parseCommits(rawCommits, config)
Expand Down
13 changes: 11 additions & 2 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,20 @@

export async function getGitDiff(
from: string | undefined,
to = "HEAD"
to = "HEAD",
onlyMerges?: boolean
): Promise<RawGitCommit[]> {
let mergeFilter = "";
if (onlyMerges === true) {
mergeFilter = "--merges";
}

Check warning on line 66 in src/git.ts

View check run for this annotation

Codecov / codecov/patch

src/git.ts#L65-L66

Added lines #L65 - L66 were not covered by tests
if (onlyMerges === false) {
mergeFilter = "--no-merges";
}

Check warning on line 69 in src/git.ts

View check run for this annotation

Codecov / codecov/patch

src/git.ts#L68-L69

Added lines #L68 - L69 were not covered by tests

// https://git-scm.com/docs/pretty-formats
const r = execCommand(
`git --no-pager log "${from ? `${from}...` : ""}${to}" --pretty="----%n%s|%h|%an|%ae%n%b" --name-status`
`git --no-pager log "${from ? `${from}...` : ""}${to}" --pretty="----%n%s|%h|%an|%ae%n%b" --name-status ${mergeFilter}`
);
return r
.split("----\n")
Expand Down