Skip to content

Commit 52f0eef

Browse files
committed
don't recommend --create-issue with --append
1 parent 23c591c commit 52f0eef

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

integration-tests/append-patches/__snapshots__/append-patches.test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,9 @@ exports[`Test append-patches: 07: patch-package fails when a patch in the sequen
8585
Failed to apply patch left-pad+1.3.0+001+FirstPatch.patch to left-pad
8686
END SNAPSHOT"
8787
`;
88+
89+
exports[`Test append-patches: 08: --append is not compatible with --create-issue 1`] = `
90+
"SNAPSHOT: --append is not compatible with --create-issue
91+
--create-issue is not compatible with --append.
92+
END SNAPSHOT"
93+
`;

integration-tests/append-patches/append-patches.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,10 @@ npx replace 'use strict' 'use bananas' patches/*FirstPatch.patch
7575
if patch-package left-pad --append 'Bananas' ; then
7676
exit 1
7777
fi
78+
(>&2 echo "END SNAPSHOT")
79+
80+
(>&2 echo "SNAPSHOT: --append is not compatible with --create-issue")
81+
if patch-package left-pad --append 'Bananas' --create-issue ; then
82+
exit 1
83+
fi
7884
(>&2 echo "END SNAPSHOT")

src/createIssue.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function parseRepoString(
2929
return { org, repo, provider: "GitHub" }
3030
}
3131

32-
function getPackageVCSDetails(packageDetails: PackageDetails) {
32+
export function getPackageVCSDetails(packageDetails: PackageDetails) {
3333
const repository = require(resolve(join(packageDetails.path, "package.json")))
3434
.repository as undefined | string | { url: string }
3535

@@ -61,11 +61,11 @@ export function shouldRecommendIssue(
6161
}
6262

6363
export function maybePrintIssueCreationPrompt(
64+
vcs: ReturnType<typeof getPackageVCSDetails>,
6465
packageDetails: PackageDetails,
6566
packageManager: PackageManager,
6667
) {
67-
const vcs = getPackageVCSDetails(packageDetails)
68-
if (vcs && shouldRecommendIssue(vcs)) {
68+
if (vcs) {
6969
console.log(`💡 ${chalk.bold(packageDetails.name)} is on ${
7070
vcs.provider
7171
}! To draft an issue based on your patch run

src/makePatch.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import { dirSync } from "tmp"
1414
import { gzipSync } from "zlib"
1515
import { applyPatch } from "./applyPatches"
1616
import {
17+
getPackageVCSDetails,
1718
maybePrintIssueCreationPrompt,
1819
openIssueCreationLink,
20+
shouldRecommendIssue,
1921
} from "./createIssue"
2022
import { PackageManager } from "./detectPackageManager"
2123
import { removeIgnoredFiles } from "./filterFiles"
@@ -74,6 +76,19 @@ export function makePatch({
7476
packageDetails.pathSpecifier
7577
] || []
7678

79+
if (createIssue && mode.type === "append") {
80+
console.error("--create-issue is not compatible with --append.")
81+
process.exit(1)
82+
}
83+
84+
const numPatchesAfterCreate =
85+
mode.type === "append" ? existingPatches.length + 1 : existingPatches.length
86+
const vcs = getPackageVCSDetails(packageDetails)
87+
const canCreateIssue =
88+
shouldRecommendIssue(vcs) &&
89+
numPatchesAfterCreate === 1 &&
90+
mode.type !== "append"
91+
7792
const appPackageJson = require(join(appPath, "package.json"))
7893
const packagePath = join(appPath, packageDetails.path)
7994
const packageJsonPath = join(packagePath, "package.json")
@@ -367,14 +382,16 @@ export function makePatch({
367382
console.log(
368383
`${chalk.green("✔")} Created file ${join(patchDir, patchFileName)}\n`,
369384
)
370-
if (createIssue) {
371-
openIssueCreationLink({
372-
packageDetails,
373-
patchFileContents: diffResult.stdout.toString(),
374-
packageVersion,
375-
})
376-
} else {
377-
maybePrintIssueCreationPrompt(packageDetails, packageManager)
385+
if (canCreateIssue) {
386+
if (createIssue) {
387+
openIssueCreationLink({
388+
packageDetails,
389+
patchFileContents: diffResult.stdout.toString(),
390+
packageVersion,
391+
})
392+
} else {
393+
maybePrintIssueCreationPrompt(vcs, packageDetails, packageManager)
394+
}
378395
}
379396
} catch (e) {
380397
console.error(e)

0 commit comments

Comments
 (0)