-
Notifications
You must be signed in to change notification settings - Fork 2
refactor: use Node.js native type striping #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,46 +1,46 @@ | ||
| name: Node.js CI | ||
| on: | ||
| push: | ||
| branches: master | ||
| pull_request: | ||
| permissions: | ||
| contents: read | ||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| node-version: [20.x] | ||
| fail-fast: false | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 | ||
| with: | ||
| egress-policy: audit | ||
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| - name: Install dependencies | ||
| run: npm install | ||
| - name: Run tests | ||
| run: npm run test | ||
| automerge: | ||
| if: > | ||
| github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]' | ||
| needs: | ||
| - test | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Merge Dependabot PR | ||
| uses: fastify/github-action-merge-dependabot@e820d631adb1d8ab16c3b93e5afe713450884a4a # v3.11.1 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| name: Node.js CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: master | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| node-version: [24.x] | ||
| fail-fast: false | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| - name: Install dependencies | ||
| run: npm install --ignore-scripts | ||
| - name: Run tests | ||
| run: npm run test | ||
| automerge: | ||
| if: > | ||
| github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]' | ||
| needs: | ||
| - test | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Merge Dependabot PR | ||
| uses: fastify/github-action-merge-dependabot@e820d631adb1d8ab16c3b93e5afe713450884a4a # v3.11.1 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} |
This file contains hidden or 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 +1,3 @@ | ||
| package-lock=false | ||
| ignore-scripts=true | ||
| save-exact=true |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // Import Third-party Dependencies | ||
| import { request } from "undici"; | ||
| import linkHeader from "http-link-header"; | ||
| import combineAsyncIterators from "combine-async-iterators"; | ||
|
|
||
| // Import Internal Dependencies | ||
| import type { | ||
| Repository, | ||
| UserOrg | ||
| } from "./github.types.ts"; | ||
|
|
||
| // CONSTANTS | ||
| const kGithubURL = new URL("https://api.github.com/"); | ||
|
|
||
| export interface FetchOptions { | ||
| /** | ||
| * @default fetch-github-repo | ||
| */ | ||
| agent?: string; | ||
| token?: string | null; | ||
| /** | ||
| * @default users | ||
| */ | ||
| kind?: "users" | "orgs"; | ||
| /** | ||
| * Fetch the repositories of all orgs for a given user | ||
| * @default false | ||
| */ | ||
| fetchUserOrgs?: boolean; | ||
| } | ||
|
|
||
| export async function* fetchLazy( | ||
| namespace: string, | ||
| options: FetchOptions = Object.create(null) | ||
| ): AsyncIterableIterator<Repository> { | ||
| if (typeof namespace !== "string") { | ||
| throw new TypeError("namespace argument must be typeof string"); | ||
| } | ||
|
|
||
| const { | ||
| agent = "fetch-github-repo", | ||
| token = null, | ||
| kind = "users", | ||
| fetchUserOrgs = false | ||
| } = options; | ||
|
|
||
| const headers = { | ||
| "User-Agent": agent, | ||
| Accept: "application/vnd.github.v3.raw", | ||
| ...(typeof token === "string" ? { Authorization: `token ${token}` } : {}) | ||
| }; | ||
|
|
||
| let currURL: string | null = `${kind}/${namespace}/repos`; | ||
| while (currURL) { | ||
| const { body, headers: currHeaders } = await request( | ||
| new URL(currURL, kGithubURL), | ||
| { headers } | ||
| ); | ||
| yield* (await body.json() as Repository[]); | ||
|
|
||
| currURL = getNextPageUrl(currHeaders); | ||
| } | ||
|
|
||
| if (kind === "users" && fetchUserOrgs) { | ||
| const { body } = await request( | ||
| new URL(`users/${namespace}/orgs`, kGithubURL), | ||
| { headers } | ||
| ); | ||
| const data = await body.json() as UserOrg[]; | ||
|
|
||
| const iterators = data.map( | ||
| (row) => fetchLazy(row.login, { agent, token, kind: "orgs" }) | ||
| ); | ||
| for await (const repo of combineAsyncIterators(...iterators)) { | ||
| yield repo; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export async function fetch( | ||
| namespace: string, | ||
| options: FetchOptions = Object.create(null) | ||
| ): Promise<Repository[]> { | ||
| const repositories: Repository[] = []; | ||
| for await (const repo of fetchLazy(namespace, options)) { | ||
| repositories.push(repo); | ||
| } | ||
|
|
||
| return repositories; | ||
| } | ||
|
|
||
| function getNextPageUrl( | ||
| headers: Record<string, string | string[] | undefined> | ||
| ): string | null { | ||
| const linkValue = headers.link; | ||
| if (linkValue === undefined) { | ||
| return null; | ||
| } | ||
|
|
||
| const { refs } = linkHeader.parse(linkValue.toString()); | ||
|
|
||
| return refs.find( | ||
| (row) => row.rel === "next" || row.rel === "last" | ||
| )?.uri ?? null; | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| export interface Repository { | ||
| id: number; | ||
| node_id: string; | ||
| name: string; | ||
| full_name: string; | ||
| private: boolean; | ||
| owner: { | ||
| login: string; | ||
| id: number; | ||
| node_id: string; | ||
| avatar_url: string; | ||
| gravatar_id: string; | ||
| url: string; | ||
| html_url: string; | ||
| followers_url: string; | ||
| following_url: string; | ||
| gists_url: string; | ||
| starred_url: string; | ||
| subscriptions_url: string; | ||
| organizations_url: string; | ||
| repos_url: string; | ||
| events_url: string; | ||
| received_events_url: string; | ||
| type: "User" | "Organization"; | ||
| site_admin: boolean; | ||
| }; | ||
| html_url: string; | ||
| description: string; | ||
| fork: boolean; | ||
| url: string; | ||
| forks_url: string; | ||
| keys_url: string; | ||
| collaborators_url: string; | ||
| teams_url: string; | ||
| hooks_url: string; | ||
| issue_events_url: string; | ||
| events_url: string; | ||
| assignees_url: string; | ||
| branches_url: string; | ||
| tags_url: string; | ||
| blobs_url: string; | ||
| git_tags_url: string; | ||
| git_refs_url: string; | ||
| trees_url: string; | ||
| statuses_url: string; | ||
| languages_url: string; | ||
| stargazers_url: string; | ||
| contributors_url: string; | ||
| subscribers_url: string; | ||
| subscription_url: string; | ||
| commits_url: string; | ||
| git_commits_url: string; | ||
| comments_url: string; | ||
| issue_comment_url: string; | ||
| contents_url: string; | ||
| compare_url: string; | ||
| merges_url: string; | ||
| archive_url: string; | ||
| downloads_url: string; | ||
| issues_url: string; | ||
| pulls_url: string; | ||
| milestones_url: string; | ||
| notifications_url: string; | ||
| labels_url: string; | ||
| releases_url: string; | ||
| deployments_url: string; | ||
| created_at: string; | ||
| updated_at: string; | ||
| pushed_at: string; | ||
| git_url: string; | ||
| ssh_url: string; | ||
| clone_url: string; | ||
| svn_url: string; | ||
| homepage: string; | ||
| size: number; | ||
| stargazers_count: number; | ||
| watchers_count: number; | ||
| language: null | string; | ||
| has_issues: boolean; | ||
| has_projects: boolean; | ||
| has_downloads: boolean; | ||
| has_wiki: boolean; | ||
| has_pages: boolean; | ||
| forks_count: number; | ||
| mirror_url: string; | ||
| archived: boolean; | ||
| disabled: boolean; | ||
| open_issues_count: number; | ||
| license: { | ||
| key: string; | ||
| name: string; | ||
| spdx_id: string; | ||
| url: string; | ||
| node_id: string; | ||
| } | null; | ||
| forks: number; | ||
| open_issues: number; | ||
| watchers: number; | ||
| default_branch: string; | ||
| permissions?: { | ||
| admin: true; | ||
| push: true; | ||
| pull: true; | ||
| }; | ||
| } | ||
|
|
||
| export interface UserOrg { | ||
| login: string; | ||
| id: number; | ||
| node_id: string; | ||
| url: string; | ||
| repos_url: string; | ||
| events_url: string; | ||
| hooks_url: string; | ||
| issues_url: string; | ||
| members_url: string; | ||
| public_members_url: string; | ||
| avatar_url: string; | ||
| description: string; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.