diff --git a/src/createIssue.ts b/src/createIssue.ts
index de9e721d..1522e563 100644
--- a/src/createIssue.ts
+++ b/src/createIssue.ts
@@ -8,9 +8,16 @@ import { join, resolve } from "./path"
const repoSpecifier = /^([\w.-]+)\/([\w.-]+)$/
const githubURL = /github.com(:|\/)([\w.-]+\/[\w.-]+?)(.git|\/.*)?$/
-function parseRepoString(
- repository: string,
-): null | { repo: string; org: string; provider: "GitHub" } {
+type VCS =
+ | {
+ repo: string
+ org: string
+ provider: "GitHub"
+ }
+ | null
+ | undefined
+
+function parseRepoString(repository: string): VCS {
if (repository.startsWith("github:")) {
repository = repository.replace(/^github:/, "")
}
@@ -29,7 +36,7 @@ function parseRepoString(
return { org, repo, provider: "GitHub" }
}
-export function getPackageVCSDetails(packageDetails: PackageDetails) {
+export function getPackageVCSDetails(packageDetails: PackageDetails): VCS {
const repository = require(resolve(join(packageDetails.path, "package.json")))
.repository as undefined | string | { url: string }
@@ -46,6 +53,38 @@ export function getPackageVCSDetails(packageDetails: PackageDetails) {
}
}
+function createIssueUrl({
+ vcs,
+ packageDetails,
+ packageVersion,
+ diff,
+}: {
+ vcs: VCS
+ packageDetails: PackageDetails
+ packageVersion: string
+ diff: string
+}): string {
+ return `https://github.com/${vcs?.org}/${vcs?.repo}/issues/new?${stringify({
+ title: "",
+ body: `Hi! 👋
+
+Firstly, thanks for your work on this project! 🙂
+
+Today I used [patch-package](https://github.com/ds300/patch-package) to patch \`${packageDetails.name}@${packageVersion}\` for the project I'm working on.
+
+
+
+Here is the diff that solved my problem:
+
+\`\`\`diff
+${diff}
+\`\`\`
+
+This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).
+`,
+ })}`
+}
+
export function shouldRecommendIssue(
vcsDetails: ReturnType,
) {
@@ -81,10 +120,12 @@ export function openIssueCreationLink({
packageDetails,
patchFileContents,
packageVersion,
+ patchPath,
}: {
packageDetails: PackageDetails
patchFileContents: string
packageVersion: string
+ patchPath: string
}) {
const vcs = getPackageVCSDetails(packageDetails)
@@ -100,25 +141,28 @@ export function openIssueCreationLink({
patchFileContents = patchFileContents.slice(0, -1)
}
- open(
- `https://github.com/${vcs.org}/${vcs.repo}/issues/new?${stringify({
- title: "",
- body: `Hi! 👋
-
-Firstly, thanks for your work on this project! 🙂
-
-Today I used [patch-package](https://github.com/ds300/patch-package) to patch \`${packageDetails.name}@${packageVersion}\` for the project I'm working on.
-
-
-
-Here is the diff that solved my problem:
+ let issueUrl = createIssueUrl({
+ vcs,
+ packageDetails,
+ packageVersion,
+ diff: patchFileContents,
+ })
-\`\`\`diff
-${patchFileContents}
-\`\`\`
+ const urlExceedsLimit = patchFileContents.length > 1950
-This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).
-`,
- })}`,
- )
+ if (urlExceedsLimit) {
+ const diffMessage = ``
+ console.log(
+ `📋 Copy the contents in [ ${patchPath} ] and paste it in the new issue's diff section.`,
+ )
+ issueUrl = createIssueUrl({
+ vcs,
+ packageDetails,
+ packageVersion,
+ diff: diffMessage,
+ })
+ }
+ open(issueUrl)
}
diff --git a/src/makePatch.ts b/src/makePatch.ts
index 4d040297..6dbc6497 100644
--- a/src/makePatch.ts
+++ b/src/makePatch.ts
@@ -423,7 +423,7 @@ export function makePatch({
sequenceNumber,
})
- const patchPath = join(patchesDir, patchFileName)
+ const patchPath: string = join(patchesDir, patchFileName)
if (!existsSync(dirname(patchPath))) {
// scoped package
mkdirSync(dirname(patchPath))
@@ -538,6 +538,7 @@ export function makePatch({
packageDetails,
patchFileContents: diffResult.stdout.toString(),
packageVersion,
+ patchPath,
})
} else {
maybePrintIssueCreationPrompt(vcs, packageDetails, packageManager)