Export GitHub type that is returned by getOctokit in @actions/github
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.9k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
Hello guys, first thing I want to say: You have been doing an amazing job! I did a lot of GitHub actions and this libraries are amazing.
I only ask for a small type export:
Export GitHub type
In the following method:
https://github.com/actions/toolkit/blob/457303960f03375db6f033e214b9f90d79c3fe5c/packages/github/src/github.ts#L15
export function getOctokit(
token: string,
options?: OctokitOptions,
...additionalPlugins: OctokitPlugin[]
): InstanceType<typeof GitHub> {
const GitHubWithPlugins = GitHub.plugin(...additionalPlugins)
return new GitHubWithPlugins(getOctokitOptions(token, options))
}
The object returned is of type: InstanceType<typeof GitHub> and this type is not exposed.
(Unless that there is a way that I'm not aware) it is not possible to access this type.
This is needed for cases like:
async function isUserInOrg(githubInstance: any, userName:string): Promise<boolean> {
const users = await octokit.rest.orgs.listMembers({ org: "actions" });
return users.data.some((user) => user.login === userName);
}
const octokit = getOctokit(getInput("GITHUB_TOKEN", { required: true });
isUserInOrg(octokit, "Bullrich").then(is => console.log("Is @Bullrich in org?", is);
As you can see, the type any must be used because we don't have access to the type of GitHub, which makes the script unsafe 😢 .
If you want a real example of where I'm using it, you can see: https://github.com/paritytech/list-team-members/blob/main/src/index.ts#L12
In this particular case I'm doing import { GitHub } from "@actions/github/lib/utils"; but that doesn't work in all the module management systems (not working on deno for example) so it's not a valid solution.
Export type
One solution would be to expose the GitHub object, and add to the end of https://github.com/actions/toolkit/blob/main/packages/github/src/github.ts the following line:
export { GitHub };
This will allow people to call do:
import { GitHub } from "@actions/github/lib/utils";
const octokit: InstanceType<typeof GitHub> = getOctokit();
Another solution would be to get the type dynamically and expose it. But I'm afraid I'm not knowledgable on how to do that (else I would simply get the type from the object returned by getOctokit).
Thank you very much for your great work!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/github/src/github.ts at getOctokit and inspect how the package exposes its public exports. Make the returned GitHub type importable through the supported @actions/github API rather than an internal module path, then verify the example can type its octokit parameter without using any and remains compatible with Deno-style module management.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100