From 244d96e4f8b65345fb7e71d3b6ba6670b43d58f6 Mon Sep 17 00:00:00 2001 From: jpb06 Date: Mon, 13 May 2024 20:42:27 +0200 Subject: [PATCH] feat: switching to a generic get one page fn (#10) --- README.md | 6 ++- bun.lockb | Bin 194309 -> 196892 bytes package.json | 4 +- .../aggregators/get-pull-request-reviews.ts | 2 +- .../aggregators/get-repo-issues.ts | 2 +- .../aggregators/get-repo-pull-requests.ts | 2 +- .../aggregators/get-repositories.ts | 2 +- .../aggregators/get-user-events.ts | 2 +- .../generic/get-all-pages.effect.ts | 3 +- .../get-one-page/get-one-page.effect.ts | 38 ++++++++++++++++ .../logic/octokit-request.logic.ts | 11 +++++ .../paging/get-org-repos-page.ts | 39 +++------------- .../paging/get-pull-request-reviews-page.ts | 43 +++--------------- .../paging/get-repo-issues-page.ts | 37 ++------------- .../paging/get-repo-pull-requests-page.ts | 39 +++------------- .../paging/get-user-events-page.ts | 37 ++------------- .../paging/get-user-repos-page.ts | 39 +++------------- .../implementation/primitives/get-issue.ts | 2 +- .../primitives/get-pull-request.ts | 2 +- .../primitives/get-user-orgs.ts | 2 +- .../primitives/get-user-profile.ts | 2 +- 21 files changed, 100 insertions(+), 214 deletions(-) create mode 100644 src/layer/github/implementation/generic/get-one-page/get-one-page.effect.ts create mode 100644 src/layer/github/implementation/generic/get-one-page/logic/octokit-request.logic.ts diff --git a/README.md b/README.md index 7e06905..cd6a33f 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ const [profile, repos, orgs, events] = await Effect.runPromise( // Get user events OctokitLayer.user(username).events(), ], + // Fetch all these in parallel { concurrency: 'unbounded' }, ), Effect.provide(OctokitLayerLive), @@ -66,7 +67,7 @@ const [profile, repos, orgs, events] = await Effect.runPromise( ```typescript import { OctokitLayer, OctokitLayerLive } from 'effect-github-stats'; -const [profile, repos, orgs, events] = await Effect.runPromise( +const orgs = await Effect.runPromise( pipe( // Get organization repos OctokitLayer.org('my-org').repos(); @@ -101,6 +102,7 @@ const [issues, pulls, issue34, pull5453, pull5453Reviews] = // Get pull request #5453 reviews OctokitLayer.repo(reactRepo).pull(5453).reviews(), ], + // Fetch all these in parallel { concurrency: 'unbounded' }, ), Effect.provide(OctokitLayerLive), @@ -121,4 +123,4 @@ You can specify the `concurrency` parameter on calls doing several requests in p github.repo(repo).pulls(100); ``` -Note that github api enforces [api rate limits](https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api?apiVersion=2022-11-28#dealing-with-secondary-rate-limits). Getting too many results concurrently will cause an api rate limit. In that case, a warning will be displayed and the call will be attempted again after the time window provided by github api (typically 60 seconds). +Note that github api enforces [api rate limits](https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api?apiVersion=2022-11-28#dealing-with-secondary-rate-limits). Fetching too many results concurrently will cause an api rate limit. In that case, a warning will be displayed and the call will be attempted again after the time window provided by github api (typically 60 seconds). diff --git a/bun.lockb b/bun.lockb index b6b69f2a051c380d9d052c32351fb702807ca6a1..745823c29b0df3563b769a83e568e705ddd6bbd2 100755 GIT binary patch delta 3609 zcmc&%X;f547Jjc9lvNNxp+y=IjDjM9ins+cu1HWvWmf?~L<}P+iAJ;mH#9CFY9Zrr z95WGd5=U{y4sIcF83u8|g^1#bPFz5CT5!pz^WE-3LC=}LQ>VYax4!!7)~)Tm?)43( zd(+J_-3Mx`ddHopF>YJ(c}4NLZEIgS#g*mNeR}E60K<{FnZGmbw?$G&RJ2(^Dwbb= zbj1J*wTZtZsU#`YW11w{!cKv8hP8xsghjK?8hGj3gSjO20p9~W=?~>dQg7Jp!p1CH zniLZwNxs7*37XU-@T3ofwTE>MkR)T+i~wb}S)=E%XBKuA9;|9ZO3o&)gseML<-+oa zjRk$~mfS3y*p}d+{o&>`bt8JF~&YB%RZlL|6sp`XQSP_QS9zz)pWZg0V4X{V7%DQQ(v>))3Fwh+Hka)WGD9ZHr|IC7An;syLq&?aRX{WZ~INm)n}!P!g6zu z9m);0P%}(@hJJf>)(G`r)QJy;HHD3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Yq5xy5pSN&wafMwD2|1Q!r21)v!mP#}JLtx%T{RtQ!6Apf8~(&~FfZM<|DCP%PCT zPK@U3fN0a{nCbY3IbtUb!eNkygmwhb*%KqbnV5|56aoI7z*K{VinzcPwUgxX(C>}Z5F;V+$bhUM;hwHrHe6`g@W8HrkRY%^wA<%mZgjMsCviX z&KAz^EIE6wJMw_wvrG{b!-oG0ZO^Y9 (page: number) => }); export const getPullRequestReviews = (args: GetPullRequestReviewsArgs) => - Effect.withSpan(__filename, { + Effect.withSpan('get-pull-request-reviews', { attributes: { ...args }, })(getAllPages(getPage, args)); diff --git a/src/layer/github/implementation/aggregators/get-repo-issues.ts b/src/layer/github/implementation/aggregators/get-repo-issues.ts index 5f367bd..9637409 100644 --- a/src/layer/github/implementation/aggregators/get-repo-issues.ts +++ b/src/layer/github/implementation/aggregators/get-repo-issues.ts @@ -17,7 +17,7 @@ const getPage = (args: GetRepoIssuesArgs) => (page: number) => }); export const getRepoIssues = (args: GetRepoIssuesArgs) => - Effect.withSpan(__filename, { + Effect.withSpan('get-repo-issues', { attributes: { ...args }, })(getAllPages(getPage, args)); diff --git a/src/layer/github/implementation/aggregators/get-repo-pull-requests.ts b/src/layer/github/implementation/aggregators/get-repo-pull-requests.ts index 33bb47e..df0f3df 100644 --- a/src/layer/github/implementation/aggregators/get-repo-pull-requests.ts +++ b/src/layer/github/implementation/aggregators/get-repo-pull-requests.ts @@ -17,7 +17,7 @@ const getPage = (args: GetRepoPullRequestsArgs) => (page: number) => }); export const getRepoPullRequests = (args: GetRepoPullRequestsArgs) => - Effect.withSpan(__filename, { + Effect.withSpan('get-repo-pull-requests', { attributes: { ...args }, })(getAllPages(getPage, args)); diff --git a/src/layer/github/implementation/aggregators/get-repositories.ts b/src/layer/github/implementation/aggregators/get-repositories.ts index 23fb4c0..dcbf8c0 100644 --- a/src/layer/github/implementation/aggregators/get-repositories.ts +++ b/src/layer/github/implementation/aggregators/get-repositories.ts @@ -31,7 +31,7 @@ const getPage = .exhaustive(); export const getRepositories = (args: GetRepositoriesArgs) => - Effect.withSpan(__filename, { + Effect.withSpan('get-repositories', { attributes: { ...args }, })(getAllPages(getPage, args)); diff --git a/src/layer/github/implementation/aggregators/get-user-events.ts b/src/layer/github/implementation/aggregators/get-user-events.ts index c3a7707..705bf1a 100644 --- a/src/layer/github/implementation/aggregators/get-user-events.ts +++ b/src/layer/github/implementation/aggregators/get-user-events.ts @@ -16,7 +16,7 @@ const getPage = (args: GetUserEventsArgs) => (page: number) => }); export const getUserEvents = (args: GetUserEventsArgs) => - Effect.withSpan(__filename, { + Effect.withSpan('get-user-events', { attributes: { ...args }, })(getAllPages(getPage, args)); diff --git a/src/layer/github/implementation/generic/get-all-pages.effect.ts b/src/layer/github/implementation/generic/get-all-pages.effect.ts index 37afceb..de8a038 100644 --- a/src/layer/github/implementation/generic/get-all-pages.effect.ts +++ b/src/layer/github/implementation/generic/get-all-pages.effect.ts @@ -24,12 +24,11 @@ export const getAllPages = < getPage: GetPage, args: TArgs, ) => - Effect.withSpan(__filename, { + Effect.withSpan('get-all-pages', { attributes: { ...args }, })( Effect.gen(function* (_) { const firstPage = yield* _(getPage(args)(1)); - if (firstPage.links?.last === undefined) { return firstPage.data; } diff --git a/src/layer/github/implementation/generic/get-one-page/get-one-page.effect.ts b/src/layer/github/implementation/generic/get-one-page/get-one-page.effect.ts new file mode 100644 index 0000000..1705cf7 --- /dev/null +++ b/src/layer/github/implementation/generic/get-one-page/get-one-page.effect.ts @@ -0,0 +1,38 @@ +import { type Endpoints } from '@octokit/types'; +import { RequestParameters } from '@octokit/types/dist-types/RequestParameters'; +import { Effect, pipe } from 'effect'; + +import { handleOctokitRequestError } from '../../../../errors/handle-octokit-request-error'; +import { parseLink } from '../../../../logic/parse-link.logic'; +import { githubSourceAnalysisProvider } from '../../../../providers/github-source-analysis.provider'; +import { retryAfterSchedule } from '../../../../schedules/retry-after.schedule'; + +import { octokitRequest } from './logic/octokit-request.logic'; + +export const getOnePage = ( + span: string, + route: E, + options?: Endpoints[E]['parameters'] & RequestParameters, +) => + Effect.withSpan(span, { + attributes: { + ...options, + }, + })( + pipe( + githubSourceAnalysisProvider, + Effect.flatMap((octokit) => + pipe( + Effect.tryPromise({ + try: () => octokitRequest(octokit)(route, options), + catch: handleOctokitRequestError, + }), + Effect.retry(retryAfterSchedule), + ), + ), + Effect.map((response) => ({ + data: response.data as Endpoints[E]['response']['data'], + links: parseLink(response), + })), + ), + ); diff --git a/src/layer/github/implementation/generic/get-one-page/logic/octokit-request.logic.ts b/src/layer/github/implementation/generic/get-one-page/logic/octokit-request.logic.ts new file mode 100644 index 0000000..83ac2d4 --- /dev/null +++ b/src/layer/github/implementation/generic/get-one-page/logic/octokit-request.logic.ts @@ -0,0 +1,11 @@ +import { Octokit } from '@octokit/core'; +import { type Endpoints } from '@octokit/types'; +import { RequestParameters } from '@octokit/types/dist-types/RequestParameters'; + +export const octokitRequest = + (octokit: Octokit) => + ( + route: E, + options?: Endpoints[E]['parameters'] & RequestParameters, + ): Promise => + octokit.request(route, options as never); diff --git a/src/layer/github/implementation/paging/get-org-repos-page.ts b/src/layer/github/implementation/paging/get-org-repos-page.ts index 7f694d6..2a98b70 100644 --- a/src/layer/github/implementation/paging/get-org-repos-page.ts +++ b/src/layer/github/implementation/paging/get-org-repos-page.ts @@ -1,10 +1,5 @@ -import { Effect, pipe } from 'effect'; - import { EffectResultSuccess } from '../../../../types/effect.types'; -import { handleOctokitRequestError } from '../../../errors/handle-octokit-request-error'; -import { parseLink } from '../../../logic/parse-link.logic'; -import { githubSourceAnalysisProvider } from '../../../providers/github-source-analysis.provider'; -import { retryAfterSchedule } from '../../../schedules/retry-after.schedule'; +import { getOnePage } from '../generic/get-one-page/get-one-page.effect'; export interface GetOrgReposPageArgs { org: string; @@ -12,32 +7,10 @@ export interface GetOrgReposPageArgs { } export const getOrgReposPage = (args: GetOrgReposPageArgs) => - Effect.withSpan(__filename, { - attributes: { - ...args, - }, - })( - pipe( - githubSourceAnalysisProvider, - Effect.flatMap((octokit) => - pipe( - Effect.tryPromise({ - try: () => - octokit.request('GET /orgs/{org}/repos', { - ...args, - type: 'all', - per_page: 100, - }), - catch: handleOctokitRequestError, - }), - Effect.retry(retryAfterSchedule), - ), - ), - Effect.map((response) => ({ - data: response.data, - links: parseLink(response), - })), - ), - ); + getOnePage('get-org-repos-page', 'GET /orgs/{org}/repos', { + ...args, + type: 'all', + per_page: 100, + }); export type OrgReposPageItems = EffectResultSuccess; diff --git a/src/layer/github/implementation/paging/get-pull-request-reviews-page.ts b/src/layer/github/implementation/paging/get-pull-request-reviews-page.ts index e69b1b3..739e1a8 100644 --- a/src/layer/github/implementation/paging/get-pull-request-reviews-page.ts +++ b/src/layer/github/implementation/paging/get-pull-request-reviews-page.ts @@ -1,10 +1,5 @@ -import { Effect, pipe } from 'effect'; - import { EffectResultSuccess } from '../../../../types/effect.types'; -import { handleOctokitRequestError } from '../../../errors/handle-octokit-request-error'; -import { parseLink } from '../../../logic/parse-link.logic'; -import { githubSourceAnalysisProvider } from '../../../providers/github-source-analysis.provider'; -import { retryAfterSchedule } from '../../../schedules/retry-after.schedule'; +import { getOnePage } from '../generic/get-one-page/get-one-page.effect'; export interface GetPullRequestReviewsPageArgs { owner: string; @@ -19,40 +14,16 @@ export const getPullRequestReviewsPage = ({ pullNumber, page, }: GetPullRequestReviewsPageArgs) => - Effect.withSpan(__filename, { - attributes: { + getOnePage( + 'get-pull-request-reviews-page', + 'GET /repos/{owner}/{repo}/pulls/{pull_number}/reviews', + { owner, repo, - pullNumber, + pull_number: pullNumber, + per_page: 100, page, }, - })( - pipe( - githubSourceAnalysisProvider, - Effect.flatMap((octokit) => - pipe( - Effect.tryPromise({ - try: () => - octokit.request( - 'GET /repos/{owner}/{repo}/pulls/{pull_number}/reviews', - { - owner, - repo, - pull_number: pullNumber, - per_page: 100, - page, - }, - ), - catch: handleOctokitRequestError, - }), - Effect.retry(retryAfterSchedule), - ), - ), - Effect.map((response) => ({ - data: response.data, - links: parseLink(response), - })), - ), ); export type PullRequestReviewsPageItems = EffectResultSuccess< diff --git a/src/layer/github/implementation/paging/get-repo-issues-page.ts b/src/layer/github/implementation/paging/get-repo-issues-page.ts index d89176a..5ea94bb 100644 --- a/src/layer/github/implementation/paging/get-repo-issues-page.ts +++ b/src/layer/github/implementation/paging/get-repo-issues-page.ts @@ -1,10 +1,5 @@ -import { Effect, pipe } from 'effect'; - import { EffectResultSuccess } from '../../../..'; -import { handleOctokitRequestError } from '../../../errors/handle-octokit-request-error'; -import { parseLink } from '../../../logic/parse-link.logic'; -import { githubSourceAnalysisProvider } from '../../../providers/github-source-analysis.provider'; -import { retryAfterSchedule } from '../../../schedules/retry-after.schedule'; +import { getOnePage } from '../generic/get-one-page/get-one-page.effect'; export interface GetRepoIssuesPageArgs { owner: string; @@ -13,31 +8,9 @@ export interface GetRepoIssuesPageArgs { } export const getRepoIssuesPage = (args: GetRepoIssuesPageArgs) => - Effect.withSpan(__filename, { - attributes: { - ...args, - }, - })( - pipe( - githubSourceAnalysisProvider, - Effect.flatMap((octokit) => - pipe( - Effect.tryPromise({ - try: () => - octokit.request('GET /repos/{owner}/{repo}/issues', { - ...args, - per_page: 100, - }), - catch: handleOctokitRequestError, - }), - Effect.retry(retryAfterSchedule), - ), - ), - Effect.map((response) => ({ - data: response.data, - links: parseLink(response), - })), - ), - ); + getOnePage('get-repo-issues-page', 'GET /repos/{owner}/{repo}/issues', { + ...args, + per_page: 100, + }); export type IssuesPageItems = EffectResultSuccess; diff --git a/src/layer/github/implementation/paging/get-repo-pull-requests-page.ts b/src/layer/github/implementation/paging/get-repo-pull-requests-page.ts index e946b1c..07896d2 100644 --- a/src/layer/github/implementation/paging/get-repo-pull-requests-page.ts +++ b/src/layer/github/implementation/paging/get-repo-pull-requests-page.ts @@ -1,10 +1,5 @@ -import { pipe, Effect } from 'effect'; - import { EffectResultSuccess } from '../../../../types/effect.types'; -import { handleOctokitRequestError } from '../../../errors/handle-octokit-request-error'; -import { parseLink } from '../../../logic/parse-link.logic'; -import { githubSourceAnalysisProvider } from '../../../providers/github-source-analysis.provider'; -import { retryAfterSchedule } from '../../../schedules/retry-after.schedule'; +import { getOnePage } from '../generic/get-one-page/get-one-page.effect'; export interface GetRepoPullRequestsPageArgs { owner: string; @@ -13,33 +8,11 @@ export interface GetRepoPullRequestsPageArgs { } export const getRepoPullRequestsPage = (args: GetRepoPullRequestsPageArgs) => - Effect.withSpan(__filename, { - attributes: { - ...args, - }, - })( - pipe( - githubSourceAnalysisProvider, - Effect.flatMap((octokit) => - pipe( - Effect.tryPromise({ - try: () => - octokit.request('GET /repos/{owner}/{repo}/pulls', { - ...args, - state: 'all', - per_page: 100, - }), - catch: handleOctokitRequestError, - }), - Effect.retry(retryAfterSchedule), - ), - ), - Effect.map((response) => ({ - data: response.data, - links: parseLink(response), - })), - ), - ); + getOnePage('get-repo-pull-requests-page', 'GET /repos/{owner}/{repo}/pulls', { + ...args, + state: 'all', + per_page: 100, + }); export type RepoPullRequestsPageItems = EffectResultSuccess< typeof getRepoPullRequestsPage diff --git a/src/layer/github/implementation/paging/get-user-events-page.ts b/src/layer/github/implementation/paging/get-user-events-page.ts index 0a0f9a8..628204a 100644 --- a/src/layer/github/implementation/paging/get-user-events-page.ts +++ b/src/layer/github/implementation/paging/get-user-events-page.ts @@ -1,10 +1,5 @@ -import { Effect, pipe } from 'effect'; - import { EffectResultSuccess } from '../../../..'; -import { handleOctokitRequestError } from '../../../errors/handle-octokit-request-error'; -import { parseLink } from '../../../logic/parse-link.logic'; -import { githubSourceAnalysisProvider } from '../../../providers/github-source-analysis.provider'; -import { retryAfterSchedule } from '../../../schedules/retry-after.schedule'; +import { getOnePage } from '../generic/get-one-page/get-one-page.effect'; export interface GetUserEventsPageArgs { username: string; @@ -12,31 +7,9 @@ export interface GetUserEventsPageArgs { } export const getUserEventsPage = (args: GetUserEventsPageArgs) => - Effect.withSpan(__filename, { - attributes: { - ...args, - }, - })( - pipe( - githubSourceAnalysisProvider, - Effect.flatMap((octokit) => - pipe( - Effect.tryPromise({ - try: () => - octokit.request('GET /users/{username}/events', { - ...args, - per_page: 100, - }), - catch: handleOctokitRequestError, - }), - Effect.retry(retryAfterSchedule), - ), - ), - Effect.map((response) => ({ - data: response.data, - links: parseLink(response), - })), - ), - ); + getOnePage('get-user-events-page', 'GET /users/{username}/events', { + ...args, + per_page: 100, + }); export type EventsPageItems = EffectResultSuccess; diff --git a/src/layer/github/implementation/paging/get-user-repos-page.ts b/src/layer/github/implementation/paging/get-user-repos-page.ts index 4eeb9c5..a237ab2 100644 --- a/src/layer/github/implementation/paging/get-user-repos-page.ts +++ b/src/layer/github/implementation/paging/get-user-repos-page.ts @@ -1,10 +1,5 @@ -import { Effect, pipe } from 'effect'; - import { EffectResultSuccess } from '../../../../types/effect.types'; -import { handleOctokitRequestError } from '../../../errors/handle-octokit-request-error'; -import { parseLink } from '../../../logic/parse-link.logic'; -import { githubSourceAnalysisProvider } from '../../../providers/github-source-analysis.provider'; -import { retryAfterSchedule } from '../../../schedules/retry-after.schedule'; +import { getOnePage } from '../generic/get-one-page/get-one-page.effect'; export interface GetUserReposPageArgs { username: string; @@ -12,32 +7,10 @@ export interface GetUserReposPageArgs { } export const getUserReposPage = (args: GetUserReposPageArgs) => - Effect.withSpan(__filename, { - attributes: { - ...args, - }, - })( - pipe( - githubSourceAnalysisProvider, - Effect.flatMap((octokit) => - pipe( - Effect.tryPromise({ - try: () => - octokit.request('GET /users/{username}/repos', { - ...args, - type: 'all', - per_page: 100, - }), - catch: handleOctokitRequestError, - }), - Effect.retry(retryAfterSchedule), - ), - ), - Effect.map((response) => ({ - data: response.data, - links: parseLink(response), - })), - ), - ); + getOnePage('get-user-repos-page', 'GET /users/{username}/repos', { + ...args, + type: 'all', + per_page: 100, + }); export type UserReposPageItems = EffectResultSuccess; diff --git a/src/layer/github/implementation/primitives/get-issue.ts b/src/layer/github/implementation/primitives/get-issue.ts index f9909cb..8529ab0 100644 --- a/src/layer/github/implementation/primitives/get-issue.ts +++ b/src/layer/github/implementation/primitives/get-issue.ts @@ -12,7 +12,7 @@ export interface GetIssueArgs { } export const getIssue = ({ owner, repo, number }: GetIssueArgs) => - Effect.withSpan(__filename, { + Effect.withSpan('get-issue', { attributes: { owner, repo, number }, })( pipe( diff --git a/src/layer/github/implementation/primitives/get-pull-request.ts b/src/layer/github/implementation/primitives/get-pull-request.ts index 3f00f6f..bb71a52 100644 --- a/src/layer/github/implementation/primitives/get-pull-request.ts +++ b/src/layer/github/implementation/primitives/get-pull-request.ts @@ -12,7 +12,7 @@ export interface GetPullRequestArgs { } export const getPullRequest = ({ owner, repo, number }: GetPullRequestArgs) => - Effect.withSpan(__filename, { + Effect.withSpan('get-pull-request', { attributes: { owner, repo, number }, })( pipe( diff --git a/src/layer/github/implementation/primitives/get-user-orgs.ts b/src/layer/github/implementation/primitives/get-user-orgs.ts index 67d870b..24d5407 100644 --- a/src/layer/github/implementation/primitives/get-user-orgs.ts +++ b/src/layer/github/implementation/primitives/get-user-orgs.ts @@ -6,7 +6,7 @@ import { githubSourceAnalysisProvider } from '../../../providers/github-source-a import { retryAfterSchedule } from '../../../schedules/retry-after.schedule'; export const getUserOrgs = (username: string) => - Effect.withSpan(__filename, { + Effect.withSpan('get-user-orgs', { attributes: { username }, })( pipe( diff --git a/src/layer/github/implementation/primitives/get-user-profile.ts b/src/layer/github/implementation/primitives/get-user-profile.ts index 3e899f7..21c256e 100644 --- a/src/layer/github/implementation/primitives/get-user-profile.ts +++ b/src/layer/github/implementation/primitives/get-user-profile.ts @@ -6,7 +6,7 @@ import { githubSourceAnalysisProvider } from '../../../providers/github-source-a import { retryAfterSchedule } from '../../../schedules/retry-after.schedule'; export const getUserProfile = (username: string) => - Effect.withSpan(__filename, { + Effect.withSpan('get-user-profile', { attributes: { username }, })( pipe(