@frontender-magazine/github-sdk

1.2.2 • Public • Published

Github API SDK

JavaScript SDK for Github API. Contain only requests I actually need.

Bages

Travis Codecov branch

Documentation

Table of Contents

ErrorServerResponse

Custom error message for abstract server response

Parameters

  • statusCode number http status code
  • statusText string http status code text
  • message (string | null) error details (optional, default null)

GitHubSDK

SDK for GitHub API

Parameters

  • token string github app token

upload

Uload file to repository

Parameters

  • props Object upload props
    • props.owner string organization or user name
    • props.repo string repository name
    • props.path string relative file path with file name in it
    • props.message string commit message
    • props.content string base64 encoded content
    • props.branch string name of the branch (optional, default 'master')

Examples

Upload binary file

import fs from 'fs';
import GitHubSDK from '@frontender-magazine/github-sdk';
(async()=>{
  try {
    const github = new GitHubSDK('b8f921864bd9a9fb6585b10e6534baa37c4d45fe');
    const image = fs.readFileSync('/path/image.jpg', 'base64');
    const content = await github.upload({
      owner: 'FrontenderMagazine',
      repo: 'article',
      path: 'images/image.jpg',
      message: 'Uploaded image.jpg',
      content: image,
    });
  } catch (error) {
    console.log(error.message);
  }
})();

Upload text file

import { Base64 } from 'js-base64';
import GitHubSDK from '@frontender-magazine/github-sdk';
(async()=>{
  try {
    const github = new GitHubSDK('b8f921864bd9a9fb6585b10e6534baa37c4d45fe');
    const readme = Base64.btoa('# Title');
    const content = await github.upload({
      owner: 'FrontenderMagazine',
      repo: 'article',
      path: 'README.md',
      message: 'Uploaded README.md',
      content: readme,
    });
  } catch (error) {
    console.log(error.message);
  }
})();

Returns Promise<Content> uploaded content data

create

Create repository in the organization

Parameters

  • props Object Options
    • props.name string Repository name
    • props.description string Repository description (optional, default null)
    • props.homepage string Link to some related resourse (optional, default null)
    • props.org string? Organization name

Examples

Create repository

import GitHubSDK from '@frontender-magazine/github-sdk';
(async()=>{
  try {
    const github = new GitHubSDK('b8f921864bd9a9fb6585b10e6534baa37c4d45fe');
    const results = await github.create({
      name: 'owning-the-role-of-the-front-end-developer',
      description: 'Owning the Role of the Front-End Developer',
      homepage: 'http://alistapart.com/article/owning-the-role-of-the-front-end-developer',
      org: 'FrontenderMagazine',
    });
  } catch (error) {
    console.log(error.message);
  }
})();

Returns Promise<Repository> Repository object

searchForUsers

Search for users

Parameters

Examples

Search for users

import GitHubSDK from '@frontender-magazine/github-sdk';
(async()=>{
  try {
    const github = new GitHubSDK('b8f921864bd9a9fb6585b10e6534baa37c4d45fe');
    const results = await github.searchForUsers(['octocat', 'silentimp']);
  } catch (error) {
    console.log(error.message);
  }
})();

Returns Promise<Users> array of users

searchForUser

Search for user

Parameters

  • keyword String login to search

Examples

Search for user

import GitHubSDK from '@frontender-magazine/github-sdk';
(async()=>{
  try {
    const github = new GitHubSDK('b8f921864bd9a9fb6585b10e6534baa37c4d45fe');
    const details = await github.searchForUser('octocat');
  } catch (error) {
    console.log(error.message);
  }
})();

Returns Promise<User> user

getUser

Get user details

Parameters

Examples

Get user details

import GitHubSDK from '@frontender-magazine/github-sdk';
(async()=>{
  try {
    const github = new GitHubSDK('b8f921864bd9a9fb6585b10e6534baa37c4d45fe');
    const details = await github.getUser('octocat');
  } catch (error) {
    console.log(error.message);
  }
})();

Returns Promise<User> — user representation

User

User object

Type: User

Content

Content object

Type: Content

Repository

Repository object

Type: Repository

Package Sidebar

Install

npm i @frontender-magazine/github-sdk

Weekly Downloads

1

Version

1.2.2

License

CC-BY-4.0

Unpacked Size

52.4 kB

Total Files

24

Last publish

Collaborators

  • silentimp