From 95c7cdd19b9f053913839cf7b0f9a55bd8f0e494 Mon Sep 17 00:00:00 2001 From: babblebey Date: Fri, 6 Sep 2024 19:58:24 +0100 Subject: [PATCH 1/7] chore: update peer dependency for `semantic-release` BREAKING CHANGE: the minimum required version of semantic-release to use @semantic-release/github is now v24.1.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4289871b..296885ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,7 +45,7 @@ "node": ">=20.8.1" }, "peerDependencies": { - "semantic-release": ">=20.1.0" + "semantic-release": ">=24.1.0" } }, "node_modules/@ampproject/remapping": { diff --git a/package.json b/package.json index f9f4f32a..7edc3114 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ ] }, "peerDependencies": { - "semantic-release": ">=20.1.0" + "semantic-release": ">=24.1.0" }, "publishConfig": { "access": "public", From 7a9914a30247cef045bf0cebaac3970318408c1c Mon Sep 17 00:00:00 2001 From: babblebey Date: Fri, 6 Sep 2024 19:59:44 +0100 Subject: [PATCH 2/7] feat: integrate `warn` in `fail` script --- lib/fail.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/fail.js b/lib/fail.js index 070b076e..0820148b 100644 --- a/lib/fail.js +++ b/lib/fail.js @@ -32,8 +32,7 @@ export default async function fail(pluginConfig, context, { Octokit }) { if (failComment === false || failTitle === false) { logger.log("Skip issue creation."); - // TODO: use logger.warn() instead of logger.log() - logger.log( + logger.warn( `DEPRECATION: 'false' for 'failComment' or 'failTitle' is deprecated and will be removed in a future major version. Use 'failCommentCondition' instead.`, ); } else if (failCommentCondition === false) { From 792720d84633569c88254f6d654894f378e6edca Mon Sep 17 00:00:00 2001 From: babblebey Date: Fri, 6 Sep 2024 20:02:26 +0100 Subject: [PATCH 3/7] feat: integrate `warn` in `success` script --- lib/success.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/success.js b/lib/success.js index 06fe203c..d57c4535 100644 --- a/lib/success.js +++ b/lib/success.js @@ -61,8 +61,7 @@ export default async function success(pluginConfig, context, { Octokit }) { logger.log("No commits found in release"); } logger.log("Skip commenting on issues and pull requests."); - // TODO: use logger.warn() instead of logger.log() - logger.log( + logger.warn( `DEPRECATION: 'false' for 'successComment' is deprecated and will be removed in a future major version. Use 'successCommentCondition' instead.`, ); } else if (successCommentCondition === false) { From b8f0c9cbf9d22b0faa9f4dccf520dce48a85b14f Mon Sep 17 00:00:00 2001 From: babblebey Date: Tue, 10 Sep 2024 14:52:44 +0100 Subject: [PATCH 4/7] test: add `warn` method to mock `logger` --- test/add-channel.test.js | 7 ++++++- test/fail.test.js | 7 ++++++- test/find-sr-issue.test.js | 7 ++++++- test/integration.test.js | 7 ++++++- test/publish.test.js | 7 ++++++- test/success.test.js | 7 ++++++- test/verify.test.js | 7 ++++++- 7 files changed, 42 insertions(+), 7 deletions(-) diff --git a/test/add-channel.test.js b/test/add-channel.test.js index 19b2a285..e14d696d 100644 --- a/test/add-channel.test.js +++ b/test/add-channel.test.js @@ -12,7 +12,12 @@ test.beforeEach((t) => { // Mock logger t.context.log = sinon.stub(); t.context.error = sinon.stub(); - t.context.logger = { log: t.context.log, error: t.context.error }; + t.context.warn = sinon.stub(); + t.context.logger = { + log: t.context.log, + error: t.context.error, + warn: t.context.warn, + }; }); test("Update a release", async (t) => { diff --git a/test/fail.test.js b/test/fail.test.js index f0277d8d..ca710d59 100644 --- a/test/fail.test.js +++ b/test/fail.test.js @@ -14,7 +14,12 @@ test.beforeEach((t) => { // Mock logger t.context.log = sinon.stub(); t.context.error = sinon.stub(); - t.context.logger = { log: t.context.log, error: t.context.error }; + t.context.warn = sinon.stub(); + t.context.logger = { + log: t.context.log, + error: t.context.error, + warn: t.context.warn, + }; }); test("Open a new issue with the list of errors", async (t) => { diff --git a/test/find-sr-issue.test.js b/test/find-sr-issue.test.js index b6e4cefd..d935e102 100644 --- a/test/find-sr-issue.test.js +++ b/test/find-sr-issue.test.js @@ -10,7 +10,12 @@ test.beforeEach((t) => { // Mock logger t.context.log = sinon.stub(); t.context.error = sinon.stub(); - t.context.logger = { log: t.context.log, error: t.context.error }; + t.context.warn = sinon.stub(); + t.context.logger = { + log: t.context.log, + error: t.context.error, + warn: t.context.warn, + }; }); test("Filter out issues without ID", async (t) => { diff --git a/test/integration.test.js b/test/integration.test.js index f512c7fa..12986ee1 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -13,7 +13,12 @@ test.beforeEach(async (t) => { // Stub the logger t.context.log = sinon.stub(); t.context.error = sinon.stub(); - t.context.logger = { log: t.context.log, error: t.context.error }; + t.context.warn = sinon.stub(); + t.context.logger = { + log: t.context.log, + error: t.context.error, + warn: t.context.warn, + }; }); test("Verify GitHub auth", async (t) => { diff --git a/test/publish.test.js b/test/publish.test.js index 8b28c037..3009068a 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -15,7 +15,12 @@ test.beforeEach((t) => { // Mock logger t.context.log = sinon.stub(); t.context.error = sinon.stub(); - t.context.logger = { log: t.context.log, error: t.context.error }; + t.context.warn = sinon.stub(); + t.context.logger = { + log: t.context.log, + error: t.context.error, + warn: t.context.warn, + }; }); test("Publish a release without creating discussion", async (t) => { diff --git a/test/success.test.js b/test/success.test.js index 36d88c81..c5691f8c 100644 --- a/test/success.test.js +++ b/test/success.test.js @@ -16,7 +16,12 @@ test.beforeEach((t) => { // Mock logger t.context.log = sinon.stub(); t.context.error = sinon.stub(); - t.context.logger = { log: t.context.log, error: t.context.error }; + t.context.warn = sinon.stub(); + t.context.logger = { + log: t.context.log, + error: t.context.error, + warn: t.context.warn, + }; }); test("Add comment and labels to PRs associated with release commits and issues solved by PR/commits comments", async (t) => { diff --git a/test/verify.test.js b/test/verify.test.js index 495c7b1b..d5154c36 100644 --- a/test/verify.test.js +++ b/test/verify.test.js @@ -12,7 +12,12 @@ test.beforeEach((t) => { // Mock logger t.context.log = sinon.stub(); t.context.error = sinon.stub(); - t.context.logger = { log: t.context.log, error: t.context.error }; + t.context.warn = sinon.stub(); + t.context.logger = { + log: t.context.log, + error: t.context.error, + warn: t.context.warn, + }; }); test("Verify package, token and repository access", async (t) => { From 718134ac436f2be4378c3982ae1af725a7aafe63 Mon Sep 17 00:00:00 2001 From: babblebey Date: Thu, 12 Sep 2024 21:54:06 +0100 Subject: [PATCH 5/7] refactor: modify commit associatedPRs and relatedIssues `label` property data type. BREAKING CHANGE: the commit associatedPR and relatedIssues `label` prop is now an array of objects with more properties --- lib/success.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/success.js b/lib/success.js index d57c4535..b6b19c4f 100644 --- a/lib/success.js +++ b/lib/success.js @@ -378,6 +378,8 @@ const baseFields = ` url name color + description + isDefault } } milestone { @@ -513,7 +515,16 @@ function buildIssuesOrPRsFromResponseNode(responseNodes, type = "ISSUE") { number: node.number, title: node.title, body: node.body, - labels: node.labels?.nodes.map((label) => label.name), + labels: node.labels?.nodes.map((label) => { + return { + id: label.id, + url: label.url, + name: label.name, + color: label.color, + description: label.description, + default: label.isDefault, + }; + }), html_url: node.url, created_at: node.createdAt, updated_at: node.updatedAt, From abcf4c4431452a62b29d2d1bfa73e7abbad75536 Mon Sep 17 00:00:00 2001 From: babblebey Date: Thu, 12 Sep 2024 21:56:47 +0100 Subject: [PATCH 6/7] doc: updated usage example for `successCommentsConditions` and `failCommentCondition`; updated information on relatedIssue type of issue --- README.md | 66 +++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index b72b0d22..9fd0e8dc 100644 --- a/README.md +++ b/README.md @@ -168,14 +168,14 @@ files. The message for the issue comments is generated with [Lodash template](https://lodash.com/docs#template). The following variables are available: -| Parameter | Description | -| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `branch` | `Object` with `name`, `type`, `channel`, `range` and `prerelease` properties of the branch from which the release is done. | -| `lastRelease` | `Object` with `version`, `channel`, `gitTag` and `gitHead` of the last release. | -| `nextRelease` | `Object` with `version`, `channel`, `gitTag`, `gitHead` and `notes` of the release being done. | -| `commits` | `Array` of commit `Object`s with `hash`, `subject`, `body` `message` and `author`. | -| `releases` | `Array` with a release `Object`s for each release published, with optional release data such as `name` and `url`. | -| `issue` | A [GitHub API pull request object](https://developer.github.com/v3/search/#search-issues) for pull requests related to a commit, or an `Object` with the `number` property for issues resolved via [keywords](https://help.github.com/articles/closing-issues-using-keywords) | +| Parameter | Description | +| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `branch` | `Object` with `name`, `type`, `channel`, `range` and `prerelease` properties of the branch from which the release is done. | +| `lastRelease` | `Object` with `version`, `channel`, `gitTag` and `gitHead` of the last release. | +| `nextRelease` | `Object` with `version`, `channel`, `gitTag`, `gitHead` and `notes` of the release being done. | +| `commits` | `Array` of commit `Object`s with `hash`, `subject`, `body` `message` and `author`. | +| `releases` | `Array` with a release `Object`s for each release published, with optional release data such as `name` and `url`. | +| `issue` | A [GitHub API pull request object](https://developer.github.com/v3/search/#search-issues) for pull requests related to a commit, or [GitHub API issue object](https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#get-an-issue) for issues resolved via [keywords](https://help.github.com/articles/closing-issues-using-keywords) | ##### successComment example @@ -187,14 +187,14 @@ The `successComment` `This ${issue.pull_request ? 'pull request' : 'issue'} is i The message for the issue comments is generated with [Lodash template](https://lodash.com/docs#template). The following variables are available: -| Parameter | Description | -| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `branch` | `Object` with `name`, `type`, `channel`, `range` and `prerelease` properties of the branch from which the release is done. | -| `lastRelease` | `Object` with `version`, `channel`, `gitTag` and `gitHead` of the last release. | -| `nextRelease` | `Object` with `version`, `channel`, `gitTag`, `gitHead` and `notes` of the release being done. | -| `commits` | `Array` of commit `Object`s with `hash`, `subject`, `body` `message` and `author`. | -| `releases` | `Array` with a release `Object`s for each release published, with optional release data such as `name` and `url`. | -| `issue` | A [GitHub API Pull Request object](https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request) for pull requests related to a commit, or an `Object` with the `number` property for issues resolved via [keywords](https://help.github.com/articles/closing-issues-using-keywords) | +| Parameter | Description | +| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `branch` | `Object` with `name`, `type`, `channel`, `range` and `prerelease` properties of the branch from which the release is done. | +| `lastRelease` | `Object` with `version`, `channel`, `gitTag` and `gitHead` of the last release. | +| `nextRelease` | `Object` with `version`, `channel`, `gitTag`, `gitHead` and `notes` of the release being done. | +| `commits` | `Array` of commit `Object`s with `hash`, `subject`, `body` `message` and `author`. | +| `releases` | `Array` with a release `Object`s for each release published, with optional release data such as `name` and `url`. | +| `issue` | A [GitHub API Pull Request object](https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request) for pull requests related to a commit | ##### successCommentCondition example @@ -202,7 +202,7 @@ The message for the issue comments is generated with [Lodash template](https://l - to only comment on issues: `"<% return !issue.pull_request; %>"` - to only comment on pull requests: `"<% return issue.pull_request; %>"` - to avoid comment on PRs or issues created by Bots: `"<% return issue.user.type !== 'Bot'; %>"` -- you can use labels to filter issues: `"<% return issue.labels?.includes('semantic-release-relevant'); %>"` +- you can use labels to filter issues: `"<% return issue.labels?.some((label) => { return label.name === ('semantic-release-relevant'); }); %>"` > check the [GitHub API issue object](https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#get-an-issue) for properties which can be used for the filter @@ -228,14 +228,14 @@ The `failComment` `This release from branch ${branch.name} had failed due to the The message for the issue content is generated with [Lodash template](https://lodash.com/docs#template). The following variables are available: -| Parameter | Description | -| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `branch` | `Object` with `name`, `type`, `channel`, `range` and `prerelease` properties of the branch from which the release is done. | -| `lastRelease` | `Object` with `version`, `channel`, `gitTag` and `gitHead` of the last release. | -| `nextRelease` | `Object` with `version`, `channel`, `gitTag`, `gitHead` and `notes` of the release being done. | -| `commits` | `Array` of commit `Object`s with `hash`, `subject`, `body` `message` and `author`. | -| `releases` | `Array` with a release `Object`s for each release published, with optional release data such as `name` and `url`. | -| `issue` | A [GitHub API pull request object](https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request) for pull requests related to a commit, or an `Object` with the `number` property for issues resolved via [keywords](https://help.github.com/articles/closing-issues-using-keywords) | +| Parameter | Description | +| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `branch` | `Object` with `name`, `type`, `channel`, `range` and `prerelease` properties of the branch from which the release is done. | +| `lastRelease` | `Object` with `version`, `channel`, `gitTag` and `gitHead` of the last release. | +| `nextRelease` | `Object` with `version`, `channel`, `gitTag`, `gitHead` and `notes` of the release being done. | +| `commits` | `Array` of commit `Object`s with `hash`, `subject`, `body` `message` and `author`. | +| `releases` | `Array` with a release `Object`s for each release published, with optional release data such as `name` and `url`. | +| `issue` | A [GitHub API pull request object](https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request) for pull requests related to a commit, or [GitHub API issue object](https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#get-an-issue) for issues resolved via [keywords](https://help.github.com/articles/closing-issues-using-keywords) | ##### failCommentCondition example @@ -249,14 +249,14 @@ The message for the issue content is generated with [Lodash template](https://lo Each label name is generated with [Lodash template](https://lodash.com/docs#template). The following variables are available: -| Parameter | Description | -| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `branch` | `Object` with `name`, `type`, `channel`, `range` and `prerelease` properties of the branch from which the release is done. | -| `lastRelease` | `Object` with `version`, `channel`, `gitTag` and `gitHead` of the last release. | -| `nextRelease` | `Object` with `version`, `channel`, `gitTag`, `gitHead` and `notes` of the release being done. | -| `commits` | `Array` of commit `Object`s with `hash`, `subject`, `body` `message` and `author`. | -| `releases` | `Array` with a release `Object`s for each release published, with optional release data such as `name` and `url`. | -| `issue` | A [GitHub API pull request object](https://developer.github.com/v3/search/#search-issues) for pull requests related to a commit, or an `Object` with the `number` property for issues resolved via [keywords](https://help.github.com/articles/closing-issues-using-keywords) | +| Parameter | Description | +| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `branch` | `Object` with `name`, `type`, `channel`, `range` and `prerelease` properties of the branch from which the release is done. | +| `lastRelease` | `Object` with `version`, `channel`, `gitTag` and `gitHead` of the last release. | +| `nextRelease` | `Object` with `version`, `channel`, `gitTag`, `gitHead` and `notes` of the release being done. | +| `commits` | `Array` of commit `Object`s with `hash`, `subject`, `body` `message` and `author`. | +| `releases` | `Array` with a release `Object`s for each release published, with optional release data such as `name` and `url`. | +| `issue` | A [GitHub API pull request object](https://developer.github.com/v3/search/#search-issues) for pull requests related to a commit, or [GitHub API issue object](https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#get-an-issue) for issues resolved via [keywords](https://help.github.com/articles/closing-issues-using-keywords) | ##### releasedLabels example From 87ff01de33f17f95ef53ecda70c4f58f5a7405ca Mon Sep 17 00:00:00 2001 From: babblebey Date: Thu, 12 Sep 2024 21:57:20 +0100 Subject: [PATCH 7/7] test: updated coverage for new label property update --- test/success.test.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test/success.test.js b/test/success.test.js index c5691f8c..06031d5c 100644 --- a/test/success.test.js +++ b/test/success.test.js @@ -130,6 +130,8 @@ test("Add comment and labels to PRs associated with release commits and issues s url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -164,6 +166,8 @@ test("Add comment and labels to PRs associated with release commits and issues s url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -423,6 +427,8 @@ test("Add comment and labels to PRs associated with release commits and issues ( url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -457,6 +463,8 @@ test("Add comment and labels to PRs associated with release commits and issues ( url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -662,6 +670,8 @@ test("Add comment and labels to PRs associated with release commits and issues c url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -696,6 +706,8 @@ test("Add comment and labels to PRs associated with release commits and issues c url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -1471,6 +1483,8 @@ test("Do not add comment and labels to PR/issues from other repo", async (t) => url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -1637,6 +1651,8 @@ test("Ignore missing and forbidden issues/PRs", async (t) => { url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -1671,6 +1687,8 @@ test("Ignore missing and forbidden issues/PRs", async (t) => { url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -1705,6 +1723,8 @@ test("Ignore missing and forbidden issues/PRs", async (t) => { url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -3099,7 +3119,7 @@ test('Add comment and label to found issues/associatedPR using the "successComme failTitle, // Issues with the label "semantic-release-relevant" will be commented and labeled successCommentCondition: - "<% return issue.labels.includes('semantic-release-relevant'); %>", + "<% return issue.labels?.some((label) => { return label.name === ('semantic-release-relevant'); }); %>", }; const options = { repositoryUrl: `https://github.com/${owner}/${repo}.git`, @@ -3148,6 +3168,8 @@ test('Add comment and label to found issues/associatedPR using the "successComme url: "https://github.com/babblebey/sr-github/labels/released", name: "semantic-release-relevant", color: "ededed", + description: "This issue is relevant to semantic-release", + isDefault: false, }, ], }, @@ -3196,6 +3218,8 @@ test('Add comment and label to found issues/associatedPR using the "successComme url: "https://github.com/babblebey/sr-github/labels/released", name: "released", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -3382,6 +3406,8 @@ test('Does not comment/label associatedPR and relatedIssues created by "Bots"', url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -3428,6 +3454,8 @@ test('Does not comment/label associatedPR and relatedIssues created by "Bots"', url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -3519,6 +3547,8 @@ test('Does not comment/label associatedPR and relatedIssues created by "Bots"', url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -3553,6 +3583,8 @@ test('Does not comment/label associatedPR and relatedIssues created by "Bots"', url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], }, @@ -3753,6 +3785,8 @@ test('Does not comment/label "associatedPR" when "successCommentCondition" disab url: "label_url", name: "label_name", color: "ededed", + description: "this is a label description", + isDefault: false, }, ], },