Git Product home page Git Product logo

github-sdk's Introduction

Depricated in favor of official github api

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

github-sdk's People

Contributors

silentimp avatar

Watchers

 avatar

github-sdk's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.