From 59d9340fd52cc334d477b7cea332406df788c39f Mon Sep 17 00:00:00 2001 From: bombillazo Date: Sun, 28 May 2023 16:42:38 -0400 Subject: [PATCH 1/9] feat: add limit check and print diff output for --creat-issue command --- src/createIssue.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/createIssue.ts b/src/createIssue.ts index 6ce03e8f..a33f3b5e 100644 --- a/src/createIssue.ts +++ b/src/createIssue.ts @@ -99,8 +99,19 @@ export function openIssueCreationLink({ if (patchFileContents.endsWith("\n")) { patchFileContents = patchFileContents.slice(0, -1) } - - open( + + const bodyExceedsLimit = patchFileContents.length > 300; + let diffContents = patchFileContents; + if (bodyExceedsLimit) { + diffContents = ''; + console.log(`📋 Copy the following diff contents and paste them into the issue diff section: + +${patchFileContents} +`); + } + + else { + open( `https://github.com/${vcs.org}/${vcs.repo}/issues/new?${stringify({ title: "", body: `Hi! 👋 @@ -114,11 +125,12 @@ Today I used [patch-package](https://github.com/ds300/patch-package) to patch \` Here is the diff that solved my problem: \`\`\`diff -${patchFileContents} +${diffContents} \`\`\` This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296). `, })}`, ) + } } From a233f9c9ecd5563d4d93eec5004b514879e0df33 Mon Sep 17 00:00:00 2001 From: bombillazo Date: Sun, 28 May 2023 16:49:55 -0400 Subject: [PATCH 2/9] chore: fix logic to always run open command, rename variables --- src/createIssue.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/createIssue.ts b/src/createIssue.ts index a33f3b5e..145131e0 100644 --- a/src/createIssue.ts +++ b/src/createIssue.ts @@ -100,22 +100,21 @@ export function openIssueCreationLink({ patchFileContents = patchFileContents.slice(0, -1) } - const bodyExceedsLimit = patchFileContents.length > 300; + const patchContentExceedsLimit = patchFileContents.length > 300; let diffContents = patchFileContents; - if (bodyExceedsLimit) { + + if (patchContentExceedsLimit) { diffContents = ''; console.log(`📋 Copy the following diff contents and paste them into the issue diff section: ${patchFileContents} `); } - - else { - open( - `https://github.com/${vcs.org}/${vcs.repo}/issues/new?${stringify({ - title: "", - body: `Hi! 👋 - + 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. @@ -129,8 +128,6 @@ ${diffContents} \`\`\` This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296). -`, - })}`, +`,})}`, ) - } } From caf5057a96570f6568169ea00253dd430a266081 Mon Sep 17 00:00:00 2001 From: bombillazo Date: Sun, 28 May 2023 16:52:06 -0400 Subject: [PATCH 3/9] chore: fix code styling --- src/createIssue.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/createIssue.ts b/src/createIssue.ts index 145131e0..bebe3b38 100644 --- a/src/createIssue.ts +++ b/src/createIssue.ts @@ -111,9 +111,9 @@ ${patchFileContents} `); } open( - `https://github.com/${vcs.org}/${vcs.repo}/issues/new?${stringify({ - title: "", - body: `Hi! 👋 + `https://github.com/${vcs.org}/${vcs.repo}/issues/new?${stringify({ + title: "", + body: `Hi! 👋 Firstly, thanks for your work on this project! 🙂 @@ -128,6 +128,7 @@ ${diffContents} \`\`\` This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296). -`,})}`, +`, + })}`, ) } From c81fbe49c2441a828f989d861e6d7103246ec085 Mon Sep 17 00:00:00 2001 From: bombillazo Date: Sun, 28 May 2023 16:52:48 -0400 Subject: [PATCH 4/9] chore: fix code styling --- src/createIssue.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/createIssue.ts b/src/createIssue.ts index bebe3b38..c0579c30 100644 --- a/src/createIssue.ts +++ b/src/createIssue.ts @@ -114,7 +114,7 @@ ${patchFileContents} `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. From 7f3d68a96ec30c780ebc37b9ad0ad9d1622ea81e Mon Sep 17 00:00:00 2001 From: bombillazo Date: Sun, 28 May 2023 17:01:02 -0400 Subject: [PATCH 5/9] chore: update messaging --- src/createIssue.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/createIssue.ts b/src/createIssue.ts index c0579c30..72da42f0 100644 --- a/src/createIssue.ts +++ b/src/createIssue.ts @@ -105,7 +105,7 @@ export function openIssueCreationLink({ if (patchContentExceedsLimit) { diffContents = ''; - console.log(`📋 Copy the following diff contents and paste them into the issue diff section: + console.log(`📋 Copy the following diff contents and paste it in the new issue's diff section: ${patchFileContents} `); From 85b439216e090bde0e59c54cc3d847c32bbcc019 Mon Sep 17 00:00:00 2001 From: bombillazo Date: Thu, 1 Jun 2023 10:47:48 -0400 Subject: [PATCH 6/9] chore: bump char limit, add function to create URL --- src/createIssue.ts | 97 ++++++++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 33 deletions(-) diff --git a/src/createIssue.ts b/src/createIssue.ts index 72da42f0..62fb37f1 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" } } -function getPackageVCSDetails(packageDetails: PackageDetails) { +function getPackageVCSDetails(packageDetails: PackageDetails): VCS { const repository = require(resolve(join(packageDetails.path, "package.json"))) .repository as undefined | string | { url: string } @@ -46,6 +53,38 @@ 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, ) { @@ -99,36 +138,28 @@ export function openIssueCreationLink({ if (patchFileContents.endsWith("\n")) { patchFileContents = patchFileContents.slice(0, -1) } - - const patchContentExceedsLimit = patchFileContents.length > 300; - let diffContents = patchFileContents; - - if (patchContentExceedsLimit) { - diffContents = ''; - console.log(`📋 Copy the following diff contents and paste it in the new issue's diff section: - -${patchFileContents} -`); - } - 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. + let issueUrl = createIssueUrl({ + vcs, + packageDetails, + packageVersion, + diff: patchFileContents, + }) - + const urlExceedsLimit = patchFileContents.length > 1950 -Here is the diff that solved my problem: - -\`\`\`diff -${diffContents} -\`\`\` - -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 and paste it in the new issue's diff section:`, + ) + issueUrl = createIssueUrl({ + vcs, + packageDetails, + packageVersion, + diff: diffMessage, + }) + } + open(issueUrl) } From aaab532e80aa9fba1ae7ab75ca7f624809f2f831 Mon Sep 17 00:00:00 2001 From: bombillazo Date: Thu, 1 Jun 2023 11:09:21 -0400 Subject: [PATCH 7/9] chore: pass patchPath to createIssue, print path for user to copy --- src/createIssue.ts | 9 ++++++--- src/makePatch.ts | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/createIssue.ts b/src/createIssue.ts index 62fb37f1..36f916ed 100644 --- a/src/createIssue.ts +++ b/src/createIssue.ts @@ -120,10 +120,12 @@ export function openIssueCreationLink({ packageDetails, patchFileContents, packageVersion, + patchPath, }: { packageDetails: PackageDetails patchFileContents: string packageVersion: string + patchPath: string }) { const vcs = getPackageVCSDetails(packageDetails) @@ -149,10 +151,11 @@ export function openIssueCreationLink({ const urlExceedsLimit = patchFileContents.length > 1950 if (urlExceedsLimit) { - const diffMessage = - "" + const diffMessage = `` console.log( - `📋 Copy the contents in and paste it in the new issue's diff section:`, + `📋 Copy the contents in [ ${patchPath} ] and paste it in the new issue's diff section.`, ) issueUrl = createIssueUrl({ vcs, diff --git a/src/makePatch.ts b/src/makePatch.ts index d51465d3..046c2e70 100644 --- a/src/makePatch.ts +++ b/src/makePatch.ts @@ -110,15 +110,15 @@ export function makePatch({ join(resolve(packageDetails.path), "package.json"), ) - // copy .npmrc/.yarnrc in case packages are hosted in private registry - // copy .yarn directory as well to ensure installations work in yarn 2 - // tslint:disable-next-line:align - ;[".npmrc", ".yarnrc", ".yarn"].forEach((rcFile) => { - const rcPath = join(appPath, rcFile) - if (existsSync(rcPath)) { - copySync(rcPath, join(tmpRepo.name, rcFile), { dereference: true }) - } - }) + // copy .npmrc/.yarnrc in case packages are hosted in private registry + // copy .yarn directory as well to ensure installations work in yarn 2 + // tslint:disable-next-line:align + ;[".npmrc", ".yarnrc", ".yarn"].forEach((rcFile) => { + const rcPath = join(appPath, rcFile) + if (existsSync(rcPath)) { + copySync(rcPath, join(tmpRepo.name, rcFile), { dereference: true }) + } + }) if (packageManager === "yarn") { console.info( @@ -216,7 +216,7 @@ export function makePatch({ "--ignore-space-at-eol", "--no-ext-diff", "--src-prefix=a/", - "--dst-prefix=b/" + "--dst-prefix=b/", ) if (diffResult.stdout.length === 0) { @@ -306,6 +306,7 @@ export function makePatch({ packageDetails, patchFileContents: diffResult.stdout.toString(), packageVersion, + patchPath, }) } else { maybePrintIssueCreationPrompt(packageDetails, packageManager) From b8790b88aaedd0f02529970bc80e7e384f9595c9 Mon Sep 17 00:00:00 2001 From: bombillazo Date: Mon, 11 Sep 2023 12:32:40 -0400 Subject: [PATCH 8/9] chore: add type to path --- src/makePatch.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/makePatch.ts b/src/makePatch.ts index 6397b767..71c17170 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)) @@ -524,12 +524,10 @@ export function makePatch({ if (isRebasing || numPatchesAfterCreate > 1) { savePatchApplicationState({ + isRebasing: didFailWhileFinishingRebase, packageDetails, - patchFileContents: diffResult.stdout.toString(), - packageVersion, - patchPath, patches: nextState, - isRebasing: didFailWhileFinishingRebase, + // patchFileContents: diffResult.stdout.toString(), }) } else { clearPatchApplicationState(packageDetails) @@ -541,6 +539,7 @@ export function makePatch({ packageDetails, patchFileContents: diffResult.stdout.toString(), packageVersion, + patchPath, }) } else { maybePrintIssueCreationPrompt(vcs, packageDetails, packageManager) From fe46169c79deeaa13f2807847b5ddabb0326f35d Mon Sep 17 00:00:00 2001 From: bombillazo Date: Mon, 11 Sep 2023 12:37:43 -0400 Subject: [PATCH 9/9] chore: fix code order --- src/makePatch.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/makePatch.ts b/src/makePatch.ts index 71c17170..6dbc6497 100644 --- a/src/makePatch.ts +++ b/src/makePatch.ts @@ -524,10 +524,9 @@ export function makePatch({ if (isRebasing || numPatchesAfterCreate > 1) { savePatchApplicationState({ - isRebasing: didFailWhileFinishingRebase, packageDetails, patches: nextState, - // patchFileContents: diffResult.stdout.toString(), + isRebasing: didFailWhileFinishingRebase, }) } else { clearPatchApplicationState(packageDetails)