-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- 👋 Hi, thanks for sending a PR to create-typescript-app! 💖. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [x] Addresses an existing open issue: fixes #667 - [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 Replaces the end-user dependency on `gh` (the GitHub CLI) with more manual Octokit calls. It's a bit less convenient this way but is more type-safe and means users don't need to have some random GitHub utility installed to use the template. Update December 2023: this works but I don't like how the user has to either have `gh` logged in or use a `process.env.GH_TOKEN`... I'd like to find the time to look into alternatives to log the user in. Update August 2024: I don't want to procrastinate any more. This PR doesn't make things _worse_. So as long as error messages explicitly tell people to either log in with `gh` or set `process.env.GH_TOKEN`, this is fine.
- Loading branch information
1 parent
6f260c8
commit 063346e
Showing
18 changed files
with
406 additions
and
323 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import chalk from "chalk"; | ||
import { Octokit } from "octokit"; | ||
import { beforeEach, describe, expect, it, MockInstance, vi } from "vitest"; | ||
|
||
import { getGitHubUserAsAllContributor } from "./getGitHubUserAsAllContributor.js"; | ||
|
@@ -13,6 +14,11 @@ vi.mock("execa", () => ({ | |
|
||
let mockConsoleWarn: MockInstance; | ||
|
||
const createMockOctokit = (getAuthenticated: MockInstance = vi.fn()) => | ||
({ | ||
rest: { users: { getAuthenticated } }, | ||
}) as unknown as Octokit; | ||
|
||
const owner = "TestOwner"; | ||
|
||
describe("getGitHubUserAsAllContributor", () => { | ||
|
@@ -23,7 +29,8 @@ describe("getGitHubUserAsAllContributor", () => { | |
}); | ||
|
||
it("defaults to owner with a log when options.offline is true", async () => { | ||
const actual = await getGitHubUserAsAllContributor({ | ||
const octokit = createMockOctokit(); | ||
const actual = await getGitHubUserAsAllContributor(octokit, { | ||
offline: true, | ||
owner, | ||
}); | ||
|
@@ -36,23 +43,24 @@ describe("getGitHubUserAsAllContributor", () => { | |
); | ||
}); | ||
|
||
it("defaults to owner without a log when octokit is undefined", async () => { | ||
const actual = await getGitHubUserAsAllContributor(undefined, { owner }); | ||
|
||
expect(actual).toEqual(owner); | ||
expect(mockConsoleWarn).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("uses the user from gh api user when it succeeds", async () => { | ||
const login = "gh-api-user"; | ||
const octokit = createMockOctokit( | ||
vi.fn().mockResolvedValue({ data: { login } }), | ||
); | ||
|
||
mock$.mockResolvedValueOnce({ | ||
stdout: JSON.stringify({ login }), | ||
}); | ||
|
||
await getGitHubUserAsAllContributor({ owner }); | ||
await getGitHubUserAsAllContributor(octokit, { owner }); | ||
|
||
expect(mockConsoleWarn).not.toHaveBeenCalled(); | ||
expect(mock$.mock.calls).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
[ | ||
"gh api user", | ||
], | ||
], | ||
[ | ||
[ | ||
"npx -y [email protected] add ", | ||
|
@@ -67,9 +75,11 @@ describe("getGitHubUserAsAllContributor", () => { | |
}); | ||
|
||
it("defaults the user to the owner when gh api user fails", async () => { | ||
mock$.mockRejectedValueOnce({}); | ||
const octokit = createMockOctokit( | ||
vi.fn().mockRejectedValue(new Error("Oh no!")), | ||
); | ||
|
||
await getGitHubUserAsAllContributor({ owner }); | ||
await getGitHubUserAsAllContributor(octokit, { owner }); | ||
|
||
expect(mockConsoleWarn).toHaveBeenCalledWith( | ||
chalk.gray( | ||
|
@@ -78,11 +88,6 @@ describe("getGitHubUserAsAllContributor", () => { | |
); | ||
expect(mock$.mock.calls).toMatchInlineSnapshot(` | ||
[ | ||
[ | ||
[ | ||
"gh api user", | ||
], | ||
], | ||
[ | ||
[ | ||
"npx -y [email protected] add ", | ||
|
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
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
Oops, something went wrong.