1.2.2 • Published 8 years ago
@frontender-magazine/github-sdk v1.2.2
Github API SDK
JavaScript SDK for Github API. Contain only requests I actually need.
Bages
Documentation
Table of Contents
ErrorServerResponse
Custom error message for abstract server response
Parameters
statusCodenumber http status codestatusTextstring http status code textmessage(string | null) error details (optional, defaultnull)
GitHubSDK
SDK for GitHub API
Parameters
tokenstring github app token
upload
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
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
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);
}
})();- Throws ValidationError Error of fields validation
- Throws ErrorServerResponse Server error
Returns Promise<Users> array of users
searchForUser
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
getUser
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
User object
Type: User
Content
Content object
Type: Content
Repository
Repository object
Type: Repository