Skip to content

Commit

Permalink
don't recommend --create-issue with --append
Browse files Browse the repository at this point in the history
  • Loading branch information
ds300 committed Jul 3, 2023
1 parent 9fd54e3 commit b12fb0e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,9 @@ exports[`Test append-patches: 07: patch-package fails when a patch in the sequen
Failed to apply patch left-pad+1.3.0+001+FirstPatch.patch to left-pad
END SNAPSHOT"
`;

exports[`Test append-patches: 08: --append is not compatible with --create-issue 1`] = `
"SNAPSHOT: --append is not compatible with --create-issue
--create-issue is not compatible with --append.
END SNAPSHOT"
`;
6 changes: 6 additions & 0 deletions integration-tests/append-patches/append-patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,10 @@ npx replace 'use strict' 'use bananas' patches/*FirstPatch.patch
if patch-package left-pad --append 'Bananas' ; then
exit 1
fi
(>&2 echo "END SNAPSHOT")

(>&2 echo "SNAPSHOT: --append is not compatible with --create-issue")
if patch-package left-pad --append 'Bananas' --create-issue ; then
exit 1
fi
(>&2 echo "END SNAPSHOT")
6 changes: 3 additions & 3 deletions src/createIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function parseRepoString(
return { org, repo, provider: "GitHub" }
}

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

Expand Down Expand Up @@ -61,11 +61,11 @@ export function shouldRecommendIssue(
}

export function maybePrintIssueCreationPrompt(
vcs: ReturnType<typeof getPackageVCSDetails>,
packageDetails: PackageDetails,
packageManager: PackageManager,
) {
const vcs = getPackageVCSDetails(packageDetails)
if (vcs && shouldRecommendIssue(vcs)) {
if (vcs) {
console.log(`💡 ${chalk.bold(packageDetails.name)} is on ${
vcs.provider
}! To draft an issue based on your patch run
Expand Down
33 changes: 25 additions & 8 deletions src/makePatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import { dirSync } from "tmp"
import { gzipSync } from "zlib"
import { applyPatch } from "./applyPatches"
import {
getPackageVCSDetails,
maybePrintIssueCreationPrompt,
openIssueCreationLink,
shouldRecommendIssue,
} from "./createIssue"
import { PackageManager } from "./detectPackageManager"
import { removeIgnoredFiles } from "./filterFiles"
Expand Down Expand Up @@ -74,6 +76,19 @@ export function makePatch({
packageDetails.pathSpecifier
] || []

if (createIssue && mode.type === "append") {
console.error("--create-issue is not compatible with --append.")
process.exit(1)
}

const numPatchesAfterCreate =
mode.type === "append" ? existingPatches.length + 1 : existingPatches.length
const vcs = getPackageVCSDetails(packageDetails)
const canCreateIssue =
shouldRecommendIssue(vcs) &&
numPatchesAfterCreate === 1 &&
mode.type !== "append"

const appPackageJson = require(join(appPath, "package.json"))
const packagePath = join(appPath, packageDetails.path)
const packageJsonPath = join(packagePath, "package.json")
Expand Down Expand Up @@ -367,14 +382,16 @@ export function makePatch({
console.log(
`${chalk.green("✔")} Created file ${join(patchDir, patchFileName)}\n`,
)
if (createIssue) {
openIssueCreationLink({
packageDetails,
patchFileContents: diffResult.stdout.toString(),
packageVersion,
})
} else {
maybePrintIssueCreationPrompt(packageDetails, packageManager)
if (canCreateIssue) {
if (createIssue) {
openIssueCreationLink({
packageDetails,
patchFileContents: diffResult.stdout.toString(),
packageVersion,
})
} else {
maybePrintIssueCreationPrompt(vcs, packageDetails, packageManager)
}
}
} catch (e) {
console.error(e)
Expand Down

0 comments on commit b12fb0e

Please sign in to comment.