Depricated in favor of official github api
JavaScript SDK for Github API. Contain only requests I actually need.
- ErrorServerResponse
- GitHubSDK
- upload
- create
- searchForUsers
- searchForUser
- getUser
- User
- Content
- Repository
Custom error message for abstract server response
Parameters
- statusCodenumber http status code
- statusTextstring http status code text
- message(string | null) error details (optional, default- null)
SDK for GitHub API
Parameters
- tokenstring github app token
Uload file to repository
Parameters
- propsObject upload props
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);
  }
})();- Throws ValidationError Error of fields validation
- Throws ErrorServerResponse Server error
Returns Promise<Content> uploaded content data
Create repository in the organization
Parameters
- propsObject Options
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);
  }
})();- Throws ValidationError Error of fields validation
- Throws ErrorServerResponse Server error
Returns Promise<Repository> Repository object
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);
  }
})();- Throws ValidationError Error of fields validation
- Throws ErrorServerResponse Server error
Returns Promise<Users> array of users
Search for user
Parameters
- keywordString 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);
  }
})();- Throws ValidationError Error of fields validation
- Throws ErrorServerResponse Server error
Get user details
Parameters
- loginString login
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);
  }
})();- Throws ValidationError Error of fields validation
- Throws ErrorServerResponse Server error
Returns Promise<User> — user representation
User object
Type: User
Content object
Type: Content
Repository object
Type: Repository