Skip to content

Instantly share code, notes, and snippets.

@peterkappus
Last active October 3, 2018 17:09
Show Gist options
  • Save peterkappus/b740d3d9d52ab7d15fb991c1f89cb651 to your computer and use it in GitHub Desktop.
Save peterkappus/b740d3d9d52ab7d15fb991c1f89cb651 to your computer and use it in GitHub Desktop.
Get open github pull requests in Google Sheets - Google Script
//generic function to get JSON from a github API endpoint
function getJSON(url) {
// Your github username
username = "<USERNAME>"
// Your access token (see https://github.com/settings/tokens)
password = "<ACCESS_TOKEN>"
//basic auth using access token
var options = {};
options.headers = {"Authorization": "Basic " + Utilities.base64Encode(username + ":" + password)};
//get the url provided
var response = UrlFetchApp.fetch(url, options);
//return the parsed jason
return(JSON.parse(response.getContentText()));
}
//call this function from a cell in your google sheet (or slide deck, or wherever)
function getOpenPRCount(){
//return the number of nodes in the json object (that's our PR count)
return(getJSON("https://api.github.com/repos/bbc/proteus/pulls").length);
}
// You could make other functions that grab more useful data from the github API, too! :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment