Skip to content

Commit 85b4392

Browse files
committed
chore: bump char limit, add function to create URL
1 parent 7f3d68a commit 85b4392

File tree

1 file changed

+64
-33
lines changed

1 file changed

+64
-33
lines changed

src/createIssue.ts

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@ import { join, resolve } from "./path"
88
const repoSpecifier = /^([\w.-]+)\/([\w.-]+)$/
99
const githubURL = /github.com(:|\/)([\w.-]+\/[\w.-]+?)(.git|\/.*)?$/
1010

11-
function parseRepoString(
12-
repository: string,
13-
): null | { repo: string; org: string; provider: "GitHub" } {
11+
type VCS =
12+
| {
13+
repo: string
14+
org: string
15+
provider: "GitHub"
16+
}
17+
| null
18+
| undefined
19+
20+
function parseRepoString(repository: string): VCS {
1421
if (repository.startsWith("github:")) {
1522
repository = repository.replace(/^github:/, "")
1623
}
@@ -29,7 +36,7 @@ function parseRepoString(
2936
return { org, repo, provider: "GitHub" }
3037
}
3138

32-
function getPackageVCSDetails(packageDetails: PackageDetails) {
39+
function getPackageVCSDetails(packageDetails: PackageDetails): VCS {
3340
const repository = require(resolve(join(packageDetails.path, "package.json")))
3441
.repository as undefined | string | { url: string }
3542

@@ -46,6 +53,38 @@ function getPackageVCSDetails(packageDetails: PackageDetails) {
4653
}
4754
}
4855

56+
function createIssueUrl({
57+
vcs,
58+
packageDetails,
59+
packageVersion,
60+
diff,
61+
}: {
62+
vcs: VCS
63+
packageDetails: PackageDetails
64+
packageVersion: string
65+
diff: string
66+
}): string {
67+
return `https://github.com/${vcs?.org}/${vcs?.repo}/issues/new?${stringify({
68+
title: "",
69+
body: `Hi! 👋
70+
71+
Firstly, thanks for your work on this project! 🙂
72+
73+
Today I used [patch-package](https://github.com/ds300/patch-package) to patch \`${packageDetails.name}@${packageVersion}\` for the project I'm working on.
74+
75+
<!-- 🔺️🔺️🔺️ PLEASE REPLACE THIS BLOCK with a description of your problem, and any other relevant context 🔺️🔺️🔺️ -->
76+
77+
Here is the diff that solved my problem:
78+
79+
\`\`\`diff
80+
${diff}
81+
\`\`\`
82+
83+
<em>This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).</em>
84+
`,
85+
})}`
86+
}
87+
4988
export function shouldRecommendIssue(
5089
vcsDetails: ReturnType<typeof getPackageVCSDetails>,
5190
) {
@@ -99,36 +138,28 @@ export function openIssueCreationLink({
99138
if (patchFileContents.endsWith("\n")) {
100139
patchFileContents = patchFileContents.slice(0, -1)
101140
}
102-
103-
const patchContentExceedsLimit = patchFileContents.length > 300;
104-
let diffContents = patchFileContents;
105-
106-
if (patchContentExceedsLimit) {
107-
diffContents = '<!-- 🔺️🔺️🔺️ PLEASE REPLACE THIS BLOCK with the diff contents printed out by the `--create-issue` command. 🔺️🔺️🔺️ -->';
108-
console.log(`📋 Copy the following diff contents and paste it in the new issue's diff section:
109-
110-
${patchFileContents}
111-
`);
112-
}
113-
open(
114-
`https://github.com/${vcs.org}/${vcs.repo}/issues/new?${stringify({
115-
title: "",
116-
body: `Hi! 👋
117-
118-
Firstly, thanks for your work on this project! 🙂
119141

120-
Today I used [patch-package](https://github.com/ds300/patch-package) to patch \`${packageDetails.name}@${packageVersion}\` for the project I'm working on.
142+
let issueUrl = createIssueUrl({
143+
vcs,
144+
packageDetails,
145+
packageVersion,
146+
diff: patchFileContents,
147+
})
121148

122-
<!-- 🔺️🔺️🔺️ PLEASE REPLACE THIS BLOCK with a description of your problem, and any other relevant context 🔺️🔺️🔺️ -->
149+
const urlExceedsLimit = patchFileContents.length > 1950
123150

124-
Here is the diff that solved my problem:
125-
126-
\`\`\`diff
127-
${diffContents}
128-
\`\`\`
129-
130-
<em>This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).</em>
131-
`,
132-
})}`,
133-
)
151+
if (urlExceedsLimit) {
152+
const diffMessage =
153+
"<!-- 🔺️🔺️🔺️ PLEASE REPLACE THIS BLOCK with the diff contents of . 🔺️🔺️🔺️ -->"
154+
console.log(
155+
`📋 Copy the contents in and paste it in the new issue's diff section:`,
156+
)
157+
issueUrl = createIssueUrl({
158+
vcs,
159+
packageDetails,
160+
packageVersion,
161+
diff: diffMessage,
162+
})
163+
}
164+
open(issueUrl)
134165
}

0 commit comments

Comments
 (0)