https://github.com/juunini/github-api-helper-ts
Helper using GitHub API
https://github.com/juunini/github-api-helper-ts
api github typescript
Last synced: 2 months ago
JSON representation
Helper using GitHub API
- Host: GitHub
- URL: https://github.com/juunini/github-api-helper-ts
- Owner: juunini
- License: mit
- Created: 2023-04-20T08:47:54.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-01T08:24:56.000Z (about 3 years ago)
- Last Synced: 2025-02-18T12:06:18.905Z (over 1 year ago)
- Topics: api, github, typescript
- Language: TypeScript
- Homepage:
- Size: 129 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# github-api-helper




[](https://codecov.io/gh/juunini/github-api-helper-ts)
[](https://github.com/juunini/github-api-helper-ts/actions/workflows/eslint.yaml)
## 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)
```