Skip to content

Commit db1a371

Browse files
fix: don't word-wrap long repo descriptions in API calls (#2047)
## PR Checklist - [x] Addresses an existing open issue: fixes #2046 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Reuses the existing `wordwrap: false` logic in a new shared `htmlToTextSafe` function. The fact that I didn't do this already is an indication of why it should be centralized. 🎁
1 parent 4ef6223 commit db1a371

File tree

4 files changed

+95
-7
lines changed

4 files changed

+95
-7
lines changed

src/blocks/blockPackageJson.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as htmlToText from "html-to-text";
21
import removeUndefinedObjects from "remove-undefined-objects";
32
import semver from "semver";
43
import sortPackageJson from "sort-package-json";
@@ -7,6 +6,7 @@ import { PackageJson } from "zod-package-json";
76

87
import { base } from "../base.js";
98
import { blockRemoveFiles } from "./blockRemoveFiles.js";
9+
import { htmlToTextSafe } from "./html/htmlToTextSafe.js";
1010
import { CommandPhase } from "./phases.js";
1111

1212
const PackageJsonWithNullableScripts = PackageJson.partial().extend({
@@ -35,9 +35,7 @@ export const blockPackageJson = base.createBlock({
3535
...addons.properties.devDependencies,
3636
},
3737
);
38-
const description = htmlToText.convert(options.description, {
39-
wordwrap: false,
40-
});
38+
const description = htmlToTextSafe(options.description);
4139

4240
return {
4341
files: {
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { testBlock } from "bingo-stratum-testers";
2+
import { describe, expect, test } from "vitest";
3+
4+
import { blockRepositorySettings } from "./blockRepositorySettings.js";
5+
import { optionsBase } from "./options.fakes.js";
6+
7+
describe("blockRepositorySettings", () => {
8+
test("with a short description", () => {
9+
const creation = testBlock(blockRepositorySettings, {
10+
options: optionsBase,
11+
});
12+
13+
expect(creation).toMatchInlineSnapshot(`
14+
{
15+
"requests": [
16+
{
17+
"endpoint": "PATCH /repos/{owner}/{repo}",
18+
"parameters": {
19+
"allow_auto_merge": true,
20+
"allow_merge_commit": false,
21+
"allow_rebase_merge": false,
22+
"allow_squash_merge": true,
23+
"delete_branch_on_merge": true,
24+
"description": "Test description",
25+
"has_wiki": false,
26+
"owner": "test-owner",
27+
"repo": "test-repository",
28+
"security_and_analysis": {
29+
"secret_scanning": {
30+
"status": "enabled",
31+
},
32+
"secret_scanning_push_protection": {
33+
"status": "enabled",
34+
},
35+
},
36+
"squash_merge_commit_message": "PR_BODY",
37+
"squash_merge_commit_title": "PR_TITLE",
38+
},
39+
"type": "octokit",
40+
},
41+
],
42+
}
43+
`);
44+
});
45+
46+
test("with a long description", () => {
47+
const creation = testBlock(blockRepositorySettings, {
48+
options: {
49+
...optionsBase,
50+
description: `A very very very very very very very very very very very very very very very very long <em><code>HTML-ish</code> description</em> ending with an emoji. 🧵`,
51+
},
52+
});
53+
54+
expect(creation).toMatchInlineSnapshot(`
55+
{
56+
"requests": [
57+
{
58+
"endpoint": "PATCH /repos/{owner}/{repo}",
59+
"parameters": {
60+
"allow_auto_merge": true,
61+
"allow_merge_commit": false,
62+
"allow_rebase_merge": false,
63+
"allow_squash_merge": true,
64+
"delete_branch_on_merge": true,
65+
"description": "A very very very very very very very very very very very very very very very very long HTML-ish description ending with an emoji. 🧵",
66+
"has_wiki": false,
67+
"owner": "test-owner",
68+
"repo": "test-repository",
69+
"security_and_analysis": {
70+
"secret_scanning": {
71+
"status": "enabled",
72+
},
73+
"secret_scanning_push_protection": {
74+
"status": "enabled",
75+
},
76+
},
77+
"squash_merge_commit_message": "PR_BODY",
78+
"squash_merge_commit_title": "PR_TITLE",
79+
},
80+
"type": "octokit",
81+
},
82+
],
83+
}
84+
`);
85+
});
86+
});

src/blocks/blockRepositorySettings.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import * as htmlToText from "html-to-text";
2-
31
import { base } from "../base.js";
2+
import { htmlToTextSafe } from "./html/htmlToTextSafe.js";
43

54
export const blockRepositorySettings = base.createBlock({
65
about: {
76
name: "Repository Settings",
87
},
98
produce({ options }) {
10-
const description = htmlToText.convert(options.description);
9+
const description = htmlToTextSafe(options.description);
1110

1211
return {
1312
requests: [

src/blocks/html/htmlToTextSafe.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { convert } from "html-to-text";
2+
3+
export function htmlToTextSafe(raw: string) {
4+
return convert(raw, { wordwrap: false });
5+
}

0 commit comments

Comments
 (0)