Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jpb06/effect-github-stats
An effect layer to interact with github api
https://github.com/jpb06/effect-github-stats
effect-layer effect-ts github-stats octokit
Last synced: about 2 months ago
JSON representation
An effect layer to interact with github api
- Host: GitHub
- URL: https://github.com/jpb06/effect-github-stats
- Owner: jpb06
- License: mit
- Created: 2024-02-08T16:08:58.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-11-01T12:05:31.000Z (2 months ago)
- Last Synced: 2024-11-01T12:06:47.503Z (2 months ago)
- Topics: effect-layer, effect-ts, github-stats, octokit
- Language: TypeScript
- Homepage:
- Size: 500 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# effect-github-stats
[![Open in Visual Studio Code](https://img.shields.io/static/v1?logo=visualstudiocode&label=&message=Open%20in%20Visual%20Studio%20Code&labelColor=2c2c32&color=007acc&logoColor=007acc)](https://github.dev/jpb06/effect-github-stats)
![npm bundle size](https://img.shields.io/bundlephobia/min/effect-github-stats)
![Github workflow](https://img.shields.io/github/actions/workflow/status/jpb06/effect-github-stats/ci.yml?branch=main&logo=github-actions&label=last%20workflow)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=jpb06_github-stats&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=jpb06_github-stats)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=jpb06_github-stats&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=jpb06_github-stats)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=jpb06_github-stats&metric=security_rating)](https://sonarcloud.io/dashboard?id=jpb06_github-stats)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=jpb06_github-stats&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=jpb06_github-stats)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=jpb06_github-stats&metric=coverage)](https://sonarcloud.io/dashboard?id=jpb06_github-stats)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=jpb06_github-stats&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=jpb06_github-stats)
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=jpb06_github-stats&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=jpb06_github-stats)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=jpb06_github-stats&metric=code_smells)](https://sonarcloud.io/dashboard?id=jpb06_github-stats)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=jpb06_github-stats&metric=bugs)](https://sonarcloud.io/summary/new_code?id=jpb06_github-stats)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=jpb06_github-stats&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=jpb06_github-stats)
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=jpb06_github-stats&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=jpb06_github-stats)
![Last commit](https://img.shields.io/github/last-commit/jpb06/effect-github-stats?logo=git)An [Effect](https://effect.website/) layer to interact with github api.
## ⚡ Access to github api
You first need to [create a github token](https://github.com/settings/tokens) with a scope related to your needs.
```bash
GITHUB_TOKEN="my-github-token"
```## ⚡ Layer Api
### 🔶 Users
```typescript
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
```typescript
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
```typescript
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:
```typescript
// 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](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).