From 14a896b5e501e6c900b8d89ee16ff17289c1d3a1 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Tue, 14 Jul 2020 21:32:42 +0300 Subject: [PATCH] feat: apply --first-parent filter to commits --- lib/createInlinePluginCreator.js | 6 ++---- lib/getCommitsFiltered.js | 5 +++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/createInlinePluginCreator.js b/lib/createInlinePluginCreator.js index 071386a..96eb45d 100644 --- a/lib/createInlinePluginCreator.js +++ b/lib/createInlinePluginCreator.js @@ -126,11 +126,9 @@ function createInlinePluginCreator(packages, multiContext) { * @internal */ const analyzeCommits = async (pluginOptions, context) => { - const { logger } = context; - // Filter commits by directory. - commits = await getCommitsFiltered(cwd, dir, context.lastRelease.gitHead); - logger.log("filtered commits", JSON.stringify(commits, null, 2)); + commits = await getCommitsFiltered(cwd, dir, context.lastRelease.gitHead, context.branch.name); + // context.logger.log("filtered commits", JSON.stringify(commits, null, 2)); // Set context.commits so analyzeCommits does correct analysis. context.commits = commits; diff --git a/lib/getCommitsFiltered.js b/lib/getCommitsFiltered.js index cd7579a..1ed61be 100644 --- a/lib/getCommitsFiltered.js +++ b/lib/getCommitsFiltered.js @@ -14,9 +14,10 @@ const cleanPath = require("./cleanPath"); * @param {string} cwd Absolute path of the working directory the Git repo is in. * @param {string} dir Path to the target directory to filter by. Either absolute, or relative to cwd param. * @param {string|void} lastHead The SHA of the previous release + * @param {string|void} branch first-parent to determine which merges went into master * @return {Promise>} The list of commits on the branch `branch` since the last release. */ -async function getCommitsFiltered(cwd, dir, lastHead = undefined) { +async function getCommitsFiltered(cwd, dir, lastHead = undefined, branch = "master") { // Clean paths and make sure directories exist. check(cwd, "cwd: directory"); check(dir, "dir: path"); @@ -43,7 +44,7 @@ async function getCommitsFiltered(cwd, dir, lastHead = undefined) { // Use git-log-parser to get the commits. const relpath = relative(root, dir); const stream = gitLogParser.parse( - { _: [lastHead ? `${lastHead}..HEAD` : "HEAD", "--", relpath] }, + { _: ["--first-parent", branch, lastHead ? `${lastHead}..HEAD` : "HEAD", "--", relpath] }, { cwd, env: process.env } ); const commits = await getStream.array(stream);