GitHubAPI()

new GitHubAPI()

The GitHubAPI backend is a lambda function invoked via Netlify's functions system. It receives HTTP requests and conducts GitHub API calls based on the instructions in the request header and data provided in the body.

Methods

async, static checkResponseCode(response, code, method) → {Promise.<object>}

Check a response code matches one of the expected codes.
Parameters:
Name Type Default Description
response object GitHub API response.
code number | Array.<number> status code to check for.
method string GET request method.
Returns:
Promise.<object>

async, static copyFile(event) → {Promise.<Object>}

Copy a file from one repository to another, and return the copy.
Parameters:
Name Type Description
event Object
Returns:
Promise.<Object>

async, static createRepository(event) → {Object}

Create a repository on GitHub for the currently authorised user.
Parameters:
Name Type Description
event object request details.
Returns:
Object

async, static deleteFile(event) → {Object}

Delete a file via github commit.
Parameters:
Name Type Description
event object request details.
Returns:
Object

async, static findRepositories(event) → {Object}

Look up the repositories.
Parameters:
Name Type Description
event
Returns:
Object

async, static findRepositoryFiles(event) → {Object}

Find all the files in a given repository.
Parameters:
Name Type Description
event
Returns:
Object

async, static getLastBuild(event) → {Promise.<{statusText: string, body: string, statusCode: number}>}

Retrieve the build status report for the last GitHub Pages build attempt.
Parameters:
Name Type Description
event object Should have body JSON string with repository URL and GitHub access token.
Returns:
Promise.<{statusText: string, body: string, statusCode: number}>

async, static getTopics(event) → {Promise.<Object>}

Get the topics associated with a repository.
Parameters:
Name Type Description
event Object
Returns:
Promise.<Object>

async, static getUserDetails(event) → {Object}

Get the GitHub user details.
Parameters:
Name Type Description
event object request details.
Returns:
Object

async, static main(event, context, callback)

Process requests from a client.
Parameters:
Name Type Description
event object request details.
context object environment details.
callback returnResponse function to send the response to the client.

static OK(obj) → {Object}

Send an OK response.
Parameters:
Name Type Description
obj object Body content to be JSON.stringified().
Returns:
Object

async, static pullItem(event) → {Object}

Pull an item from GitHub by its URL.
Parameters:
Name Type Description
event
Returns:
Object

async, static pushFile(event) → {Object}

Replace a file with a new version via github commit.
Parameters:
Name Type Description
event object request details.
Returns:
Object

async, static redeemCode(event) → {Object}

Send a code to GitHub and request a token in exchange.
Parameters:
Name Type Description
event object request details.
Returns:
Object

async, static setTopics(event) → {Object}

Set the topics on a newly created workshop so we can check custom repository submissions' eligibility easily.
Parameters:
Name Type Description
event object request details.
Returns:
Object