Skip to content

Refactor internal octokit usage#119

Closed
bluwy wants to merge 2 commits into
mainfrom
refactor-octokit-usage
Closed

Refactor internal octokit usage#119
bluwy wants to merge 2 commits into
mainfrom
refactor-octokit-usage

Conversation

@bluwy

@bluwy bluwy commented Jun 22, 2026

Copy link
Copy Markdown
Member

So that internally we use the complete Octokit types, which allows us to easily use the API later. The stub Octokit type is renamed as PartialOctokit with also a simplified shape. I manually tested and it's still possible to detect if .rest or .paginate is missing in the octokit instance, if they didn't set up, for example.

I decided to not export PartialOctokit still as there's not a lot of reason users would need that in practice. It's better to use the type of their own Octokit instance, and then relying on typechecking if it can be passed to our function.

Comment thread src/core.ts
message,
fileChanges,
}: CommitChangesOptions): Promise<CommitChangesResult> {
const octokit = partialOctokit as Octokit;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I preferred the previous setup - it required some manual redeclaration, but at least it didn't require casts. Even though we were not redeclaring the whole thing the compiler would still catch the type errors nicely.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with casts? It's not doing an interim as any/unknown and it should also catch type errors equally.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice, this is probably OK-ish but this certainly does allow invalid invocations through the public API. One could pass literal PartialOctokit's equivalent to our public commitChanges export and the compiler would be fine with all of that unknowns but we'd crash at runtime.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How and why would someone do that though? I don't think it's worth the effort to protect an edgecase.

If you feel strongly about this though, would you be ok if we keep the previous manual type as PartialOctokit, and keep the cast to Octokit? The initial goal here is that if internally we can use Octokit, it's easier for us to discover and work on the octokit API if we want to update in the future.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To achieve this goal you can do a "validated casting" like this:

type DeepPartial<T> =
  T extends Function
    ? T
    : T extends object
      ? { [P in keyof T]?: DeepPartial<T[P]> }
      : T;

declare function toOctokit(
  octokit: DeepPartial<Octokit>
): Octokit;

This way if our PartialOctokit stops matching the Octokit the compiler will error at toOctokit call sites. But you should still be able to freely use the return value of this casting helper and experiment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could have such validation in our tests (a type-level test would suffice) - and in the implementation we could then cast freely, without the dummy toOctokit helper

@bluwy bluwy closed this Jun 23, 2026
@bluwy bluwy deleted the refactor-octokit-usage branch June 23, 2026 14:53
@bluwy

bluwy commented Jun 23, 2026

Copy link
Copy Markdown
Member Author

Closed as I don't thing it's worth changing it now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants