Skip to content

Commit 34c0afd

Browse files
authored
feat: add discussionCategoryName option (#702)
1 parent 9e2678c commit 34c0afd

File tree

9 files changed

+325
-29
lines changed

9 files changed

+325
-29
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,23 @@ When using the _GITHUB_TOKEN_, the **minimum required permissions** are:
7979

8080
### Options
8181

82-
| Option | Description | Default |
83-
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
84-
| `githubUrl` | The GitHub Enterprise endpoint. | `GH_URL` or `GITHUB_URL` environment variable. |
85-
| `githubApiPathPrefix` | The GitHub Enterprise API prefix. | `GH_PREFIX` or `GITHUB_PREFIX` environment variable. |
86-
| `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. |
87-
| `assets` | An array of files to upload to the release. See [assets](#assets). | - |
88-
| `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](<github_release_url>)` |
89-
| `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. |
90-
| `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 🚨` |
91-
| `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']` |
92-
| `assignees` | The [assignees](https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users) to add to the issue created when a release fails. | - |
93-
| `releasedLabels` | The [labels](https://help.github.com/articles/about-labels) to add to each issue and pull request resolved by the release. Set to `false` to not add any label. See [releasedLabels](#releasedlabels). | `['released<%= nextRelease.channel ? \` on @\${nextRelease.channel}\` : "" %>']- |
94-
| `addReleases` | Will add release links to the GitHub Release. Can be `false`, `"bottom"` or `"top"`. See [addReleases](#addReleases). | `false` |
95-
| `draftRelease` | A boolean indicating if a GitHub Draft Release should be created instead of publishing an actual GitHub Release. | `false` |
96-
| `releaseNameTemplate` | A [Lodash template](https://lodash.com/docs#template) to customize the github release's name | `<%= nextverison.name %>` |
97-
| `releaseBodyTemplate` | A [Lodash template](https://lodash.com/docs#template) to customize the github release's body | `<%= nextverison.notes %>` |
82+
| Option | Description | Default |
83+
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
84+
| `githubUrl` | The GitHub Enterprise endpoint. | `GH_URL` or `GITHUB_URL` environment variable. |
85+
| `githubApiPathPrefix` | The GitHub Enterprise API prefix. | `GH_PREFIX` or `GITHUB_PREFIX` environment variable. |
86+
| `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. |
87+
| `assets` | An array of files to upload to the release. See [assets](#assets). | - |
88+
| `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](<github_release_url>)` |
89+
| `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. |
90+
| `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 🚨` |
91+
| `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']` |
92+
| `assignees` | The [assignees](https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users) to add to the issue created when a release fails. | - |
93+
| `releasedLabels` | The [labels](https://help.github.com/articles/about-labels) to add to each issue and pull request resolved by the release. Set to `false` to not add any label. See [releasedLabels](#releasedlabels). | `['released<%= nextRelease.channel ? \` on @\${nextRelease.channel}\` : "" %>']- |
94+
| `addReleases` | Will add release links to the GitHub Release. Can be `false`, `"bottom"` or `"top"`. See [addReleases](#addReleases). | `false` |
95+
| `draftRelease` | A boolean indicating if a GitHub Draft Release should be created instead of publishing an actual GitHub Release. | `false` |
96+
| `releaseNameTemplate` | A [Lodash template](https://lodash.com/docs#template) to customize the github release's name | `<%= nextverison.name %>` |
97+
| `releaseBodyTemplate` | A [Lodash template](https://lodash.com/docs#template) to customize the github release's body | `<%= nextverison.notes %>` |
98+
| `discussionCategoryName` | The category name in which to create a linked discussion to the release. Set to `false` to disable creating discussion for a release. | `false` |
9899

99100
#### proxy
100101

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function verifyConditions(
1717
{ Octokit = SemanticReleaseOctokit } = {},
1818
) {
1919
const { options } = context;
20-
// If the GitHub publish plugin is used and has `assets`, `successComment`, `failComment`, `failTitle`, `labels` or `assignees` configured, validate it now in order to prevent any release if the configuration is wrong
20+
// If the GitHub publish plugin is used and has `assets`, `successComment`, `failComment`, `failTitle`, `labels`, `discussionCategoryName` or `assignees` configured, validate it now in order to prevent any release if the configuration is wrong
2121
if (options.publish) {
2222
const publishPlugin =
2323
castArray(options.publish).find(
@@ -42,6 +42,10 @@ export async function verifyConditions(
4242
pluginConfig.assignees,
4343
publishPlugin.assignees,
4444
);
45+
pluginConfig.discussionCategoryName = defaultTo(
46+
pluginConfig.discussionCategoryName,
47+
publishPlugin.discussionCategoryName,
48+
);
4549
}
4650

4751
await verifyGitHub(pluginConfig, context, { Octokit });

lib/definitions/errors.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,16 @@ Your configuration for the \`releaseNameTemplate\` option is \`${stringify(
221221
)}\`.`,
222222
};
223223
}
224+
225+
export function EINVALIDDISCUSSIONCATEGORYNAME({ discussionCategoryName }) {
226+
return {
227+
message: "Invalid `discussionCategoryName` option.",
228+
details: `The [discussionCategoryName option](${linkify(
229+
"README.md#discussionCategoryName",
230+
)}) if defined, must be a non empty \`String\`.
231+
232+
Your configuration for the \`discussionCategoryName\` option is \`${stringify(
233+
discussionCategoryName,
234+
)}\`.`,
235+
};
236+
}

lib/publish.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default async function publish(pluginConfig, context, { Octokit }) {
3131
draftRelease,
3232
releaseNameTemplate,
3333
releaseBodyTemplate,
34+
discussionCategoryName,
3435
} = resolveConfig(pluginConfig, context);
3536
const { owner, repo } = parseGithubUrl(repositoryUrl);
3637
const octokit = new Octokit(
@@ -53,6 +54,11 @@ export default async function publish(pluginConfig, context, { Octokit }) {
5354

5455
debug("release object: %O", release);
5556

57+
// If discussionCategoryName is not undefined or false
58+
if (discussionCategoryName) {
59+
release.discussion_category_name = discussionCategoryName;
60+
}
61+
5662
const draftReleaseOptions = { ...release, draft: true };
5763

5864
// When there are no assets, we publish a release directly.

lib/resolve-config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default function resolveConfig(
1616
draftRelease,
1717
releaseNameTemplate,
1818
releaseBodyTemplate,
19+
discussionCategoryName,
1920
},
2021
{ env },
2122
) {
@@ -52,5 +53,8 @@ export default function resolveConfig(
5253
releaseNameTemplate: !isNil(releaseNameTemplate)
5354
? releaseNameTemplate
5455
: "<%= nextRelease.name %>",
56+
discussionCategoryName: isNil(discussionCategoryName)
57+
? false
58+
: discussionCategoryName,
5559
};
5660
}

lib/verify.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const VALIDATORS = {
4747
draftRelease: isBoolean,
4848
releaseBodyTemplate: isNonEmptyString,
4949
releaseNameTemplate: isNonEmptyString,
50+
discussionCategoryName: canBeDisabled(isNonEmptyString),
5051
};
5152

5253
export default async function verify(pluginConfig, context, { Octokit }) {

test/integration.test.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ test("Throw SemanticReleaseError if invalid config", async (t) => {
121121
const failTitle = 42;
122122
const labels = 42;
123123
const assignees = 42;
124+
const discussionCategoryName = 42;
124125
const options = {
125126
publish: [
126127
{ path: "@semantic-release/npm" },
@@ -132,6 +133,7 @@ test("Throw SemanticReleaseError if invalid config", async (t) => {
132133
failTitle,
133134
labels,
134135
assignees,
136+
discussionCategoryName,
135137
},
136138
],
137139
repositoryUrl: "invalid_url",
@@ -163,9 +165,11 @@ test("Throw SemanticReleaseError if invalid config", async (t) => {
163165
t.is(errors[5].name, "SemanticReleaseError");
164166
t.is(errors[5].code, "EINVALIDASSIGNEES");
165167
t.is(errors[6].name, "SemanticReleaseError");
166-
t.is(errors[6].code, "EINVALIDGITHUBURL");
168+
t.is(errors[6].code, "EINVALIDDISCUSSIONCATEGORYNAME");
167169
t.is(errors[7].name, "SemanticReleaseError");
168-
t.is(errors[7].code, "ENOGHTOKEN");
170+
t.is(errors[7].code, "EINVALIDGITHUBURL");
171+
t.is(errors[8].name, "SemanticReleaseError");
172+
t.is(errors[8].code, "ENOGHTOKEN");
169173
});
170174

171175
test("Publish a release with an array of assets", async (t) => {
@@ -219,7 +223,9 @@ test("Publish a release with an array of assets", async (t) => {
219223
`${uploadOrigin}${uploadUri}?name=${encodeURIComponent(
220224
"upload_file_name.txt",
221225
)}&`,
222-
{ browser_download_url: assetUrl },
226+
{
227+
browser_download_url: assetUrl,
228+
},
223229
)
224230
.postOnce(
225231
`${uploadOrigin}${uploadUri}?name=${encodeURIComponent(
@@ -676,12 +682,16 @@ test("Verify, release and notify success", async (t) => {
676682
`${uploadOrigin}${uploadUri}?name=other_file.txt&label=${encodeURIComponent(
677683
"Other File",
678684
)}`,
679-
{ browser_download_url: otherAssetUrl },
685+
{
686+
browser_download_url: otherAssetUrl,
687+
},
680688
)
681689

682690
.postOnce(
683691
`https://api.github.local/repos/${owner}/${repo}/issues/1/comments`,
684-
{ html_url: "https://github.com/successcomment-1" },
692+
{
693+
html_url: "https://github.com/successcomment-1",
694+
},
685695
);
686696

687697
await t.notThrowsAsync(
@@ -804,7 +814,9 @@ test("Verify, update release and notify success", async (t) => {
804814
)
805815
.postOnce(
806816
`https://api.github.local/repos/${owner}/${repo}/issues/1/comments`,
807-
{ html_url: "https://github.com/successcomment-1" },
817+
{
818+
html_url: "https://github.com/successcomment-1",
819+
},
808820
)
809821
.postOnce(
810822
`https://api.github.local/repos/${owner}/${repo}/issues/1/labels`,

0 commit comments

Comments
 (0)