From 20f6d03c6e92f214a70fcc3d6b71d950424ada77 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Thu, 24 Feb 2022 16:00:48 -0800 Subject: [PATCH] dist --- dist/index.js | 81 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/dist/index.js b/dist/index.js index da8b64ac74..f0ff579d38 100644 --- a/dist/index.js +++ b/dist/index.js @@ -128596,6 +128596,8 @@ module.exports = (app, { getRouter }) => { if (config === null || disableReleaser) return + const includePaths = config['include-paths'] + // GitHub Actions merge payloads slightly differ, in that their ref points // to the PR branch instead of refs/heads/master const ref = process.env['GITHUB_REF'] || context.payload.ref @@ -128619,6 +128621,7 @@ module.exports = (app, { getRouter }) => { targetCommitish, lastRelease, config, + includePaths, }) const sortedMergedPullRequests = sortPullRequests( @@ -128725,6 +128728,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! @@ -128793,6 +128824,7 @@ const findCommitsWithAssociatedPullRequests = async ({ targetCommitish, lastRelease, config, + includePaths, }) => { const { owner, repo } = context.repo() const variables = { @@ -128807,7 +128839,36 @@ const findCommitsWithAssociatedPullRequests = async ({ 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 +128883,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 +128895,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 +128918,8 @@ const findCommitsWithAssociatedPullRequests = async ({ exports.findCommitsWithAssociatedPullRequestsQuery = findCommitsWithAssociatedPullRequestsQuery +exports.findCommitsWithPathChangesQuery = findCommitsWithPathChangesQuery + exports.findCommitsWithAssociatedPullRequests = findCommitsWithAssociatedPullRequests @@ -128944,6 +129014,7 @@ const DEFAULT_CONFIG = Object.freeze({ categories: [], 'exclude-labels': [], 'include-labels': [], + 'include-paths': [], 'exclude-contributors': [], 'no-contributors-template': 'No contributors', replacers: [], @@ -129503,6 +129574,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']),