# github-api-helper

> GitHub API helper

Latest version **0.0.13** (published 2023-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install github-api-helper
pnpm add github-api-helper
yarn add github-api-helper
bun add github-api-helper
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.13 |
| Published | 2023-05-01 |
| First published | 2023-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 54.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | juunini |
| Maintainers | juunini |

## Links

- npm: https://www.npmjs.com/package/github-api-helper
- Repository: https://github.com/juunini/github-api-helper-ts
- Issues: https://github.com/juunini/github-api-helper-ts/issues
- npm.io page: https://npm.io/package/github-api-helper

## Recent versions

- 0.0.13 (latest) — 2023-05-01
- 0.0.12 — 2023-05-01
- 0.0.11 — 2023-04-30
- 0.0.10 — 2023-04-30
- 0.0.9 — 2023-04-30
- 0.0.8 — 2023-04-30
- 0.0.7 — 2023-04-30
- 0.0.6 — 2023-04-27
- 0.0.5 — 2023-04-26
- 0.0.4 — 2023-04-26
- 0.0.3 — 2023-04-24
- 0.0.2 — 2023-04-23
- 0.0.1 — 2023-04-21

## README

<div align="center">

# github-api-helper

![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)
![BunJS](https://img.shields.io/badge/Bun-beige?style=for-the-badge&logo=bun&logoColor=black)
![Parcel](https://img.shields.io/badge/Parcel-deac79?style=for-the-badge&logoColor=black&logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pgo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDIwMDEwOTA0Ly9FTiI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8L2c+Cjwvc3ZnPg==)

![Version](https://img.shields.io/npm/v/github-api-helper)
[![codecov](https://codecov.io/gh/juunini/github-api-helper-ts/branch/main/graph/badge.svg?token=ZZE5D2GG05)](https://codecov.io/gh/juunini/github-api-helper-ts)
[![ESLint](https://github.com/juunini/github-api-helper-ts/actions/workflows/eslint.yaml/badge.svg)](https://github.com/juunini/github-api-helper-ts/actions/workflows/eslint.yaml)

</div>

## Install

```bash
# npm
npm install github-api-helper

# yarn
yarn add github-api-helper

# pnpm
pnpm add github-api-helper

# bun
bun add github-api-helper
```

## Usage

### OAuth

```ts
import { OAuth, loginURL } from 'github-api-helper'

const oauth = new OAuth('client_id', 'client_secret')

const githubLoginURL = oauth.loginURL
// or
// const githubLoginURL = loginURL({ clientId: 'client_id' })

oauth.access_token('code').then((response) => console.log({
  access_token: response.access_token,
  refresh_token: response.refresh_token,
}))
oauth.refresh_token('refresh_token').then((response) => console.log({
  access_token: response.access_token,
  refresh_token: response.refresh_token,
}))
```

### Commit

> Access Token(or Personal access token) must have `Contents` Read and write permission of `Repository permissions`

```ts
import { commit } from 'github-api-helper'

commit({
  owner: 'juunini',
  repo: 'test',
  branch: 'main',
  accessToken: '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',
  files: [
    {
      path: 'README.md',
      data: '# GitHub API Helper'
    },
    {
      path: 'src/index.ts',
      data: 'console.log(\'Hello World\')'
    }
  ],
  committer: {
    name: 'bot',
    email: 'noreply@example.com'
  },
  message: 'commit message'
})
  .then(console.log)
```

### Read

```ts
import { read } from 'github-api-helper'

read({
  owner: 'juunini',
  repo: 'test',
  branch: 'main', // optional
  accessToken: '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',
  path: 'README.md'
}).then((response) => {
  if (response instanceof Array) {
    // directory
  } else {
    // file
  }
})
```

### User

```ts
import { user } from 'github-api-helper'

user({ accessToken: 'accessToken' }).then(console.log)
// or
user({ id: 41536271 }).then(console.log)
```

---
_Source: https://npm.io/package/github-api-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
