github-js-api
v0.3.1
Published
A simple JavaScript GitHub API wrapper.
Downloads
7
Readme
GitHub.JS-API
Overview
Github.JS-API is a simple JavaScript GitHub API wrapper.
Getting Started
Prerequisites
- Node
Installation
To install Github.JS-API simply run:
npm install github-js-api
in your project folder.
Running the Tests
To run the test a few changes need to be done.
- Open the
config.json
in thetests
folder - Set the owner name and the repo name of one of your private repositories
- The GitHub AuthToken can also be set in
config.json
or later as a parameter in the test command.
The tests can then be run via:
npm test
or
npm test -- --authToken=<Your GitHub Auth Token>
in case the auth token was not already set in the config.json
;
Usage
JavaScript
const GitHubApi = require('github-js-api').GitHubApi;
const gitHub = new GitHubApi();
async function printPullRequestData() {
const pullRequestData = await gitHub
.getUser('octocat')
.getRepo('Hello-World')
.getPullRequest(493)
.asJson();
console.log(pullRequestData);
}
printPullRequestData();
TypeScript
import {GitHubApi} from 'github-js-api';
class GitHubApiSample {
public gitHub: GitHubApi = new GitHubApi();
public async printPullRequestData() {
const pullRequestData: JSON = await this.gitHub
.getUser('octocat')
.getRepo('Hello-World')
.getPullRequest(493)
.asJson();
console.log(pullRequestData);
}
}
const gitHubApi: GitHubApi = new GitHubApiSample();
gitHubApi.printPullRequestData();
Documentation
GitHub
Variables
endpoint
- The GitHub api endpoint
- Type: string
- Get & Set
- Default:
https://api.github.com/
authToken
- The GitHub AuthToken
- Type: string
- Get & Set
- Default: Not set.
configService
- The service where all configs are stored
- Type: ConfigService
- Get & Set
Constructor
- GitHubApi(authToken?: string)
- Parameters
- authToken [optional]
- The GitHub AuthToken
- Type: string
- authToken [optional]
- Parameters
Functions
getOrga(orgaName: string, configService?: ConfigService): IOrga
Parameters
- orgaName
- The name of the organization
- Type: string
- configService [optional]
- A custom configService
- Type: ConfigService
- orgaName
Returns
- The created organization
- Type: IOrga
- The created organization
getUser(userName: string, configService?: ConfigService): IUser
Parameters
- userName
- The name of the user
- Type: string
- configService [optional]
- A custom configService
- Type: ConfigService
- userName
Returns
- The created user
- Type: IUser
- The created user
getLoggedInUser(): Promise
Parameters
Returns
- A Promise containing logged in user
- Type: IUser
- A Promise containing logged in user
Owner [abstract]
Constructor
- Owner(name: string, configService?: ConfigService)
- Parameters
- name
- The name of the owner
- Type: string
- configService [optional]
- A custom configService
- Type: ConfigService
- name
- Parameters
Variables
- name
- The name of the owner
- Type: string
- Get
Functions
asJson(): Promise
Parameters
- None
Returns
- A promise containing the data of the owner
- Type: JSON
- A promise containing the data of the owner
getRepo(repoName: string, configService?: ConfigService): IRepo
Parameters
- repoName
- The name of the repository
- Type: string
- configService [optional]
- A custom configService
- Type: ConfigService
- repoName
Returns
- The created repository
- Type: IRepo
- The created repository
getAllPublicRepos(configService?: configService): Promise<Array>
Parameters
- configService [optional]
- A custom configService
- Type: ConfigService
- configService [optional]
Returns
- A promise containing all created public repositories
- Type: Promise<Array>
- A promise containing all created public repositories
Orga [extends Owner]
A GitHub Organization.
Constructor
- Orga(name: string, configService?: ConfigService)
- Parameters
- name
- The name of the orga
- Type: string
- configService [optional]
- A custom configService
- Type: ConfigService
- name
- Parameters
Functions
- asOrgaData(): Promise
Parameters
- None
Returns
- A promise containing the data of the organization
- Type: IOrganizationData
- A promise containing the data of the organization
User [extends Owner]
A GitHub User.
Constructor
- User(name: string, configService?: ConfigService)
- Parameters
- name
- The name of the user
- Type: string
- configService [optional]
- A custom configService
- Type: ConfigService
- name
- Parameters
Functions
- asUserData(): Promise
Parameters
- None
Returns
- A promise containing the data of the user
- Type: IUserData
- A promise containing the data of the user
Repo
A GitHub Repository.
Constructor
- Repo(owner: IOwner, name: string, configService?: ConfigService)
- Parameters
- owner
- The owner of the repository
- Type: IOwner
- name
- The name of the repository
- Type: string
- configService [optional]
- A custom configService
- Type: ConfigService
- owner
- Parameters
Variables
name
- The name of the repository
- Type: string
- Get
owner
- The owner of the repository
- Type: IOwner
- Get
Functions
asJson(): Promise
Parameters
- None
Returns
- A promise containing the data of the repository
- Type: JSON
- A promise containing the data of the repository
asRepositoryData(): Promise
Parameters
- None
Returns
- A promise containing the data of the repository
- Type: IRepositoryData
- A promise containing the data of the repository
[static] fromData(owner: IOwner, data: JSON, configService?: ConfigService): IRepo
Parameters
- owner
- The owner of the repository
- Type: IOwner
- The owner of the repository
- data
- The data of the repository
- Type: JSON
- The data of the repository
- configService [optional]
- A custom configService
- Type: ConfigService
- owner
Returns
- The created repository
- Type: IRepo
- The created repository
getPullRequest(pullRequestNumber: number, configService?: ConfigService): IPullRequest
Parameters
- pullRequestNumber: The number of the pull request
- Type: number
- configService [optional]
- A custom configService
- Type: ConfigService
- pullRequestNumber: The number of the pull request
Returns
- The created pull request
- Type: IPullRequest
- The created pull request
getOpenPullRequests(configService?: ConfigService): Promise<Array>
Parameters
- configService [optional]
- A custom configService
- Type: ConfigService
- configService [optional]
Returns
- A promise containing all created public repositories
- Type: Promise<Array>
- A promise containing all created public repositories
Pull Request
A GitHub Pull Request.
Constructor
- PullRequest(owner: IOwner, repo: IRepo, pullRequestNumber: number, configService?: ConfigService)
- Parameters
- owner
- The owner of the repository that contains the pull request
- Type: IOwner
- repo
- The repository that contains the pull request
- Type: IRepo
- pullRequestNumber
- The number of the pull request
- Type: number
- configService [optional]
- A custom configService
- Type: ConfigService
- owner
- Parameters
Variables
number
- The number of the pull request
- Type: number
- Get
repo
- The repository containing the pull request
- Type: IRepo
- Get
owner
- The owner of the repository containing the pull request
- Type: IOwner
- Get
Functions
asJson(): Promise
Parameters
- None
Returns
- A promise containing the data of the pull request
- Type: JSON
- A promise containing the data of the pull request
asPullRequestData(): Promise
Parameters
- None
Returns
- A promise containing the data of the pull request
- Type: IPullRequestData
- A promise containing the data of the pull request
[static] fromData(owner: IOwner, repo: IRepo, data: JSON, configService?: ConfigService): Pull Request
Parameters
- owner
- The owner of the repository containing the pull request
- Type: IOwner
- repo
- The repository containing the pull request
- Type: IRepo
- data
- The data of the pull request
- Type: JSON
- configService [optional]
- A custom configService
- Type: ConfigService
- owner
Returns
- The created pull request
- Type: IPullRequest
- The created pull request
Changelog
v0.3.1
- 🐛 Add Missing Functions to Interfaces
v0.3.0
- ✨ Add getLoggedInUser
- 🐛 Fix Bug That Changed The Authtoken When Using withAuthtoken
- ✨ Add Interfaces
- ✅ Add Tests for getLoggedInUser
- ✅ ♻️ Use Interfaces in Tests
v0.2.1
- 🐛 Fix Using ConfigService for User
- 🐛 Fix Using ConfigService for Orga
v0.2.0
- ✨ Add Declarations
- ✨ Add Registry
- ♻️ Refactor ConfigService & HttpClient
v0.1.0
- ✨ Add Basic Support for Users
- ✨ Add Basic Support for Orgas
- ✨ Add Basic Support for Repos
- ✨ Add Basic Support for Pull Requests
- ✨ Add ConfigService
- ✨ Add HttpClient
- ✅ Add Tests
- 🏷 Add Types