Skip to content

Add types#661

Merged
wolfy1339 merged 10 commits intooctokit:mainfrom
mbg:mbg/add-types
Feb 18, 2026
Merged

Add types#661
wolfy1339 merged 10 commits intooctokit:mainfrom
mbg:mbg/add-types

Conversation

@mbg
Copy link
Contributor

@mbg mbg commented Feb 18, 2026

Adds typings throughout and resolves #43.

This should not change the behaviour of the plugin in any way.

A few notes:

  • While adding types for requestWithGraphqlErrorHandling, I was surprised to see that request is called with itself as an argument (await request(request, options)) which doesn't seem to line up with the type that request gets from octokit.hook.wrap("request", ...). I removed it and it didn't seem to break anything in the tests, but maybe I am missing some good reason why that was there before.
  • The bottleneck library doesn't appear to be maintained and, while there is a commit in the repo there which adds typings for bottleneck/light, those are unreleased. I added some minimal typings for it in this PR, but in the long-term it would probably be good to move to something that is still maintained.

Closes #492
Closes #110

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@github-actions
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@mbg mbg marked this pull request as ready for review February 18, 2026 12:59
@wolfy1339
Copy link
Member

This is definitely not the first stab at this, see #492

@wolfy1339
Copy link
Member

As for request being passed to itself, it was added as part of the following commit f10aa37

Switching away from Bottleneck would really be appreciated, but I don't know of any alternatives that offer the same functionality

@mbg
Copy link
Contributor Author

mbg commented Feb 18, 2026

This is definitely not the first stab at this, see #492

Sorry, yes, I only noticed that after I opened this PR. Would you be happy to proceed with/review this PR or do you prefer updating/merging #492?

As for request being passed to itself, it was added as part of the following commit f10aa37

Looks like the specific commit added all of requestWithGraphqlErrorHandling and there was never a version of it with just request(options). I'll have another look at this later to see if including request as a first argument makes a difference. If it does, I'll try to add a test for it, since it seems like the tests are currently passing without it.


Broadly, we are using this plugin in https://github.com/github/codeql-action and have run into some limitations for our usage that we would like to make some improvements for here, rather than just implementing something for ourselves.

@wolfy1339
Copy link
Member

I'm fine either way. Thank you for the PR.

These repositories are in dire need of some love.

Copy link
Member

@wolfy1339 wolfy1339 left a comment

Choose a reason for hiding this comment

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

Use interface declaration merging so that the types for the plugin can propogate to the Octokit constructor, and some other small points

mbg and others added 3 commits February 18, 2026 16:36
Co-authored-by: wolfy1339 <4595477+wolfy1339@users.noreply.github.com>
@wolfy1339
Copy link
Member

It looks good to me, I'll test it further a little later

@mbg
Copy link
Contributor Author

mbg commented Feb 18, 2026

While adding types for requestWithGraphqlErrorHandling, I was surprised to see that request is called with itself as an argument (await request(request, options)) which doesn't seem to line up with the type that request gets from octokit.hook.wrap("request", ...). I removed it and it didn't seem to break anything in the tests, but maybe I am missing some good reason why that was there before.

I have investigated this a bit and traced this down to a bug in the before-after-hook library. Fundamentally, the request(request, options) call is wrong, since request only expects options as argument, so the version in this PR is correct. However, currently it doesn't matter what we have here because of the bug in before-after-hook. The TL;DR: is that the same options object is passed to each wrapper. For example:

const collection = new Hooks.Collection();

async function wrappee(options) {
    console.info("In wrappee");
    console.log(options);
}

collection.wrap("test", (fn, opts) => {
    console.info("In first wrapper");
    console.log(opts);
    fn({...opts, first: true });
});

collection.wrap("test", (fn, opts) => {
    console.info("In second wrapper");
    console.log(opts);
    fn({...opts, second: true });
});

await collection("test", wrappee, {});

outputs:

In second wrapper
{}
In first wrapper
{}
In wrappee
{ first: true }

In our case, that means that it doesn't matter what we call request with because, as long as it is another wrapper, the arguments are ignored and the wrapper is called with the initial options. The responsible code in before-after-hook is https://github.com/gr2m/before-after-hook/blob/main/lib/register.js#L23-L25

This binds the initial options to every wrapper call. Only the first wrapper that was installed, which calls the initial function directly, passes its argument to it.

I have opened a PR there to fix this: gr2m/before-after-hook#125

@wolfy1339 wolfy1339 moved this from 🆕 Triage to 🏗 In progress in 🧰 Octokit Active Feb 18, 2026
@wolfy1339 wolfy1339 added the Type: Feature New feature or request label Feb 18, 2026
Copy link
Member

@wolfy1339 wolfy1339 left a comment

Choose a reason for hiding this comment

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

After testing, everything seems to work just fine

Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

thanks for taking the time, looks great to me! I'm looking at your other PR as well

Comment on lines +51 to +55
declare module "@octokit/core/types" {
interface OctokitOptions {
retry?: RetryOptions;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

love this 👍🏼

@wolfy1339 wolfy1339 merged commit e8bdeb7 into octokit:main Feb 18, 2026
7 checks passed
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in 🧰 Octokit Active Feb 18, 2026
@github-actions
Copy link

🎉 This PR is included in version 8.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

released Type: Feature New feature or request

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Remove // @ts-ignore statements

3 participants