github-api-helper
TypeScript icon, indicating that this package has built-in type declarations

0.0.13 • Public • Published

github-api-helper

TypeScript BunJS Parcel

Version codecov ESLint

Install

# 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

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

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

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

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

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

Readme

Keywords

none

Package Sidebar

Install

npm i github-api-helper

Weekly Downloads

0

Version

0.0.13

License

MIT

Unpacked Size

56 kB

Total Files

9

Last publish

Collaborators

  • juunini