From b92671cb95d04e07fc9911be71ac3b8639915540 Mon Sep 17 00:00:00 2001 From: Raffael Sahli Date: Fri, 4 Nov 2022 12:39:03 +0000 Subject: [PATCH] feat: add successSearchQuery option Signed-off-by: Raffael Sahli --- README.md | 3 ++- index.js | 1 + lib/resolve-config.js | 2 ++ lib/success.js | 4 +++- lib/verify.js | 1 + 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3f87d33f..b590aa46 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ When using the _GITHUB_TOKEN_, the **minimum required permissions** are: | `proxy` | The proxy to use to access the GitHub API. Set to `false` to disable usage of proxy. See [proxy](#proxy). | `HTTP_PROXY` environment variable. | | `assets` | An array of files to upload to the release. See [assets](#assets). | - | | `successComment` | The comment to add to each issue and pull request resolved by the release. Set to `false` to disable commenting on issues and pull requests. See [successComment](#successcomment). | `:tada: This issue has been resolved in version ${nextRelease.version} :tada:\n\nThe release is available on [GitHub release]()` | +| `successSearchQuery` | The GitHub search query used to search for pr's to consider commenting/labeling after release | `repo:${owner}/${repo}+type:pr+is:merged` | | `failComment` | The content of the issue created when a release fails. Set to `false` to disable opening an issue when a release fails. See [failComment](#failcomment). | Friendly message with links to **semantic-release** documentation and support, with the list of errors that caused the release to fail. | | `failTitle` | The title of the issue created when a release fails. Set to `false` to disable opening an issue when a release fails. | `The automated release is failing 🚨` | | `labels` | The [labels](https://help.github.com/articles/about-labels) to add to the issue created when a release fails. Set to `false` to not add any label. | `['semantic-release']` | @@ -218,4 +219,4 @@ Valid values for this option are `false`, `"top"` or `"bottom"`. ##### addReleases example -See [The introducing PR](https://github.com/semantic-release/github/pull/282) for an example on how it will look. \ No newline at end of file +See [The introducing PR](https://github.com/semantic-release/github/pull/282) for an example on how it will look. diff --git a/index.js b/index.js index fa549f08..7f5b454f 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ async function verifyConditions(pluginConfig, context) { pluginConfig.assets = defaultTo(pluginConfig.assets, publishPlugin.assets); pluginConfig.successComment = defaultTo(pluginConfig.successComment, publishPlugin.successComment); + pluginConfig.successSearchQuery = defaultTo(pluginConfig.successSearchQuery, publishPlugin.successSearchQuery); pluginConfig.failComment = defaultTo(pluginConfig.failComment, publishPlugin.failComment); pluginConfig.failTitle = defaultTo(pluginConfig.failTitle, publishPlugin.failTitle); pluginConfig.labels = defaultTo(pluginConfig.labels, publishPlugin.labels); diff --git a/lib/resolve-config.js b/lib/resolve-config.js index 91b85a84..d129b33a 100644 --- a/lib/resolve-config.js +++ b/lib/resolve-config.js @@ -7,6 +7,7 @@ module.exports = ( proxy, assets, successComment, + successSearchQuery, failTitle, failComment, labels, @@ -22,6 +23,7 @@ module.exports = ( proxy: isNil(proxy) ? env.http_proxy || env.HTTP_PROXY || false : proxy, assets: assets ? castArray(assets) : assets, successComment, + successSearchQuery: isNil(successSearchQuery) ? `repo:${owner}/${repo}+type:pr+is:merged` : successSearchQuery, failTitle: isNil(failTitle) ? 'The automated release is failing 🚨' : failTitle, failComment, labels: isNil(labels) ? ['semantic-release'] : labels === false ? false : castArray(labels), diff --git a/lib/success.js b/lib/success.js index a62bec84..20331c35 100644 --- a/lib/success.js +++ b/lib/success.js @@ -26,6 +26,7 @@ module.exports = async (pluginConfig, context) => { githubApiPathPrefix, proxy, successComment, + successSearchQuery, failComment, failTitle, releasedLabels, @@ -44,8 +45,9 @@ module.exports = async (pluginConfig, context) => { const parser = issueParser('github', githubUrl ? {hosts: [githubUrl]} : {}); const releaseInfos = releases.filter((release) => Boolean(release.name)); const shas = commits.map(({hash}) => hash); + let query = successSearchQuery.replace("${owner}", owner).replace("${repo}", repo) - const searchQueries = getSearchQueries(`repo:${owner}/${repo}+type:pr+is:merged`, shas).map( + const searchQueries = getSearchQueries(query, shas).map( async (q) => (await github.search.issuesAndPullRequests({q})).data.items ); diff --git a/lib/verify.js b/lib/verify.js index e9ee6bb7..861c4e2f 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -21,6 +21,7 @@ const VALIDATORS = { (asset) => isStringOrStringArray(asset) || (isPlainObject(asset) && isStringOrStringArray(asset.path)) ), successComment: canBeDisabled(isNonEmptyString), + successSearchQuery: isNonEmptyString, failTitle: canBeDisabled(isNonEmptyString), failComment: canBeDisabled(isNonEmptyString), labels: canBeDisabled(isArrayOf(isNonEmptyString)),