diff --git a/dist/index.js b/dist/index.js index da8b64ac7..6da2f13f3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -128621,6 +128621,8 @@ module.exports = (app, { getRouter }) => { config, }) + if (commits.length === 0) return + const sortedMergedPullRequests = sortPullRequests( mergedPullRequests, config['sort-by'], @@ -128725,6 +128727,34 @@ const _ = __nccwpck_require__(90250) const { log } = __nccwpck_require__(71911) const { paginate } = __nccwpck_require__(46418) +const findCommitsWithPathChangesQuery = ({ includePaths }) => /* GraphQL */ ` + query findCommitsWithPathChangesQuery( + $name: String! + $owner: String! + $targetCommitish: String! + $since: GitTimestamp + $after: String + ) { + repository(name: $name, owner: $owner) { + object(expression: $targetCommitish) { + ... on Commit { + ${includePaths + .map( + (path, idx) => `\ + path${idx}: history(path: "${path}", since: $since, after: $after) { + nodes { + id + } + } + ` + ) + .join('\n')} + } + } + } + } +` + const findCommitsWithAssociatedPullRequestsQuery = /* GraphQL */ ` query findCommitsWithAssociatedPullRequests( $name: String! @@ -128804,10 +128834,40 @@ const findCommitsWithAssociatedPullRequests = async ({ withBaseRefName: config['change-template'].includes('$BASE_REF_NAME'), withHeadRefName: config['change-template'].includes('$HEAD_REF_NAME'), } + const includePaths = config['include-paths'] const dataPath = ['repository', 'object', 'history'] const repoNameWithOwner = `${owner}/${repo}` - let data, commits + let data, + allCommits, + includedIds = {} + + if (includePaths.length > 0) { + const commitsWithPathChanges = await paginate( + context.octokit.graphql, + findCommitsWithPathChangesQuery({ + includePaths, + }), + lastRelease ? { ...variables, since: lastRelease.created_at } : variables, + ['repository', 'object'] + ) + + var anyChanges = false + for (const [idx, path] of includePaths.entries()) { + const { nodes } = commitsWithPathChanges[`path${idx}`] + includedIds[path] = includedIds[path] || new Set([]) + for (const { id } of nodes) { + anyChanges = true + includedIds[path].add(id) + } + } + + if (!anyChanges) { + // Short circuit to avoid blowing GraphQL budget + return { commits: [], pullRequests: [] } + } + } + if (lastRelease) { log({ context, @@ -128822,7 +128882,7 @@ const findCommitsWithAssociatedPullRequests = async ({ ) // GraphQL call is inclusive of commits from the specified dates. This means the final // commit from the last tag is included, so we remove this here. - commits = _.get(data, [...dataPath, 'nodes']).filter( + allCommits = _.get(data, [...dataPath, 'nodes']).filter( (commit) => commit.committedDate != lastRelease.created_at ) } else { @@ -128834,9 +128894,16 @@ const findCommitsWithAssociatedPullRequests = async ({ variables, dataPath ) - commits = _.get(data, [...dataPath, 'nodes']) + allCommits = _.get(data, [...dataPath, 'nodes']) } + const commits = + includePaths.length > 0 + ? allCommits.filter((commit) => + includePaths.some((path) => includedIds[path].has(commit.id)) + ) + : allCommits + const pullRequests = _.uniqBy( commits.flatMap((commit) => commit.associatedPullRequests.nodes), 'number' @@ -128850,6 +128917,8 @@ const findCommitsWithAssociatedPullRequests = async ({ exports.findCommitsWithAssociatedPullRequestsQuery = findCommitsWithAssociatedPullRequestsQuery +exports.findCommitsWithPathChangesQuery = findCommitsWithPathChangesQuery + exports.findCommitsWithAssociatedPullRequests = findCommitsWithAssociatedPullRequests @@ -128944,6 +129013,7 @@ const DEFAULT_CONFIG = Object.freeze({ categories: [], 'exclude-labels': [], 'include-labels': [], + 'include-paths': [], 'exclude-contributors': [], 'no-contributors-template': 'No contributors', replacers: [], @@ -129503,6 +129573,10 @@ const schema = (context) => { .items(Joi.string()) .default(DEFAULT_CONFIG['include-labels']), + 'include-paths': Joi.array() + .items(Joi.string()) + .default(DEFAULT_CONFIG['include-paths']), + 'exclude-contributors': Joi.array() .items(Joi.string()) .default(DEFAULT_CONFIG['exclude-contributors']),