-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve migration owner replacements (#1078)
## PR Checklist - [x] Addresses an existing open issue: fixes #1043 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Uses a [`to` callback](https://github.com/adamreisnz/replace-in-file/#using-callbacks-for-to) to determine whether to swap out owner to `options.owner` in `"JoshuaKGoldberg"` _(always)_ or `"JoshuaKGoldberg/..."` (if the `...` is `options.repository`). Also fixes some existing edge cases around owner replacements: * Syncs up the end-of-readme attribution notice so there's only one place it's written in the templates * Uses `options.owner` and `options.repository` in `createDotGitHubFiles` instead of hardcoding `JoshuaKGoldberg/create-typescript-app`.
- Loading branch information
1 parent
df82c12
commit 4e25327
Showing
10 changed files
with
146 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { describe, expect, test } from "vitest"; | ||
|
||
import { createJoshuaKGoldbergReplacement } from "./createJoshuaKGoldbergReplacement.js"; | ||
|
||
const options = { | ||
owner: "NewOwner", | ||
repository: "new-repository", | ||
}; | ||
|
||
describe("createJoshuaKGoldbergReplacement", () => { | ||
test.each([ | ||
[`JoshuaKGoldberg`, options.owner], | ||
[ | ||
`JoshuaKGoldberg/${options.repository}`, | ||
`${options.owner}/${options.repository}`, | ||
], | ||
[`JoshuaKGoldberg/other-repository`, `JoshuaKGoldberg/other-repository`], | ||
])("%s", (before, expected) => { | ||
const [matcher, replacer] = createJoshuaKGoldbergReplacement(options); | ||
|
||
const actual = replacer(before, matcher.exec(before)?.[1]); | ||
|
||
expect(actual).toBe(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Options } from "../shared/types.js"; | ||
|
||
/** | ||
* Creates a replace-in-file replacement for JoshuaKGoldberg/... matches, | ||
* keeping repository names not being migrated (e.g. for GitHub actions). | ||
*/ | ||
export const createJoshuaKGoldbergReplacement = ( | ||
options: Pick<Options, "owner" | "repository">, | ||
) => | ||
[ | ||
/JoshuaKGoldberg(?:\/(.+))?/g, | ||
(full: string, capture: string | undefined) => | ||
capture | ||
? // If this was a "JoshuaKGoldberg/..." repository link, | ||
// swap the owner if it's the repository being migrated. | ||
capture.startsWith(options.repository) | ||
? `${options.owner}/${capture}` | ||
: full | ||
: // Otherwise it's just "JoshuaKGoldberg" standalone, | ||
// so swap to the new owner. | ||
options.owner, | ||
] as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters