effect-github-stats
v1.0.5
Published
Getting user stats from github
Downloads
21
Readme
effect-github-stats
An Effect layer to interact with github api.
⚡ 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(),
],
{ concurrency: 'unbounded' },
),
Effect.provide(OctokitLayerLive),
),
);
🔶 Organizations
import { OctokitLayer, OctokitLayerLive } from 'effect-github-stats';
const [profile, repos, orgs, events] = 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(),
],
{ 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
github.repo(repo).pulls(100),
Note that github api enforces api 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).