Skip to content
This repository was archived by the owner on Feb 23, 2025. It is now read-only.

Latest commit

 

History

History
120 lines (93 loc) · 4.91 KB

File metadata and controls

120 lines (93 loc) · 4.91 KB

effect-github-stats

Open in Visual Studio Code npm bundle size Github workflow Last commit

An Effect layer to interact with github api.

😺 This codebase has moved to effect-octokit-layer

       

⚡ Access to github api

You first need to create a github token with a scope related to your needs.

GITHUB_TOKEN="my-github-token"

⚡ Layer Api

🔶 Users

import { OctokitLayer, OctokitLayerLive } from 'effect-github-stats';

const username = 'jpb06';

const [profile, repos, orgs, events] = await Effect.runPromise(
  pipe(
    Effect.all(
      [
        // Get user profile
        OctokitLayer.user(username).profile(),
        // Get user repos
        OctokitLayer.user(username).repos(),
        // Get user organizations
        OctokitLayer.user(username).orgs(),
        // Get user events
        OctokitLayer.user(username).events(),
      ],
      // Fetch all these in parallel
      { concurrency: 'unbounded' }
    ),
    Effect.provide(OctokitLayerLive)
  )
);

🔶 Organizations

import { OctokitLayer, OctokitLayerLive } from 'effect-github-stats';

const orgs = await Effect.runPromise(
  pipe(
    // Get organization repos
    OctokitLayer.org('my-org').repos(),
    Effect.provide(OctokitLayerLive)
  )
);

🔶 Repositories

import { RepoArgs, OctokitLayer, OctokitLayerLive } from 'effect-github-stats';

const reactRepo: RepoArgs = {
  owner: 'facebook',
  name: 'react',
};

const [issues, pulls, issue34, pull5453, pull5453Reviews] =
  await Effect.runPromise(
    pipe(
      Effect.all(
        [
          // Get all issues
          OctokitLayer.repo(reactRepo).issues(),
          // Get all pull requests
          OctokitLayer.repo(reactRepo).pulls(),
          // Get issue #34
          OctokitLayer.repo(reactRepo).issue(34),
          // Get pull request #5453 data
          OctokitLayer.repo(reactRepo).pull(5453).details(),
          // Get pull request #5453 reviews
          OctokitLayer.repo(reactRepo).pull(5453).reviews(),
        ],
        // Fetch all these in parallel
        { concurrency: 'unbounded' }
      ),
      Effect.provide(OctokitLayerLive)
    )
  );

🔶 Parallelism and resilience

🧿 Concurrency

Default: 10

You can specify the concurrency parameter on calls doing several requests in parallel (paginated data). For example:

// Will fetch the first page and then 100 pages concurrently
OctokitLayer.repo({
  owner: 'facebook',
  name: 'react',
}).pulls(100);

Note that github api enforces api 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).