Skip to content

Commit a53f3bf

Browse files
fix: prefer gh user over package.json author for owner option (#2312)
## PR Checklist - [x] Addresses an existing open issue: fixes #2311 - [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 🎁
1 parent 45d8b37 commit a53f3bf

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/options/readOwner.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ describe(readOwner, () => {
1616
expect(getPackageAuthor).not.toHaveBeenCalled();
1717
});
1818

19-
it("returns package data author when only it exists", async () => {
20-
const take = vi.fn();
21-
const name = "test-author";
19+
it("returns the gh config value when only it resolves", async () => {
20+
const user = "test-user";
21+
const take = vi.fn().mockResolvedValueOnce({ stdout: user });
2222
const getGitDefaults = vi.fn();
23-
const getPackageAuthor = vi.fn().mockResolvedValueOnce({ name });
23+
const getPackageAuthor = vi.fn();
2424

2525
const actual = await readOwner(take, getGitDefaults, getPackageAuthor);
2626

27-
expect(actual).toBe(name);
28-
expect(take).not.toHaveBeenCalled();
27+
expect(actual).toBe(user);
28+
expect(getPackageAuthor).not.toHaveBeenCalled();
2929
});
3030

31-
it("returns the gh config value when only it resolves", async () => {
32-
const user = "test-user";
33-
const take = vi.fn().mockResolvedValueOnce({ stdout: user });
31+
it("returns package data author when only it exists", async () => {
32+
const take = vi.fn().mockResolvedValueOnce({});
33+
const name = "test-author";
3434
const getGitDefaults = vi.fn();
35-
const getPackageAuthor = vi.fn().mockResolvedValueOnce({});
35+
const getPackageAuthor = vi.fn().mockResolvedValueOnce({ name });
3636

3737
const actual = await readOwner(take, getGitDefaults, getPackageAuthor);
3838

39-
expect(actual).toBe(user);
39+
expect(actual).toBe(name);
4040
});
4141

4242
it("returns undefined when no values exist", async () => {

src/options/readOwner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ export async function readOwner(
1111
) {
1212
return (
1313
(await getGitDefaults())?.organization ??
14-
(await getPackageAuthor()).name ??
1514
(
1615
await take(inputFromScript, {
1716
command: "gh config get user -h github.com",
1817
})
19-
).stdout?.toString()
18+
).stdout?.toString() ??
19+
(await getPackageAuthor()).name
2020
);
2121
}

0 commit comments

Comments
 (0)