Last active
October 3, 2018 17:09
-
-
Save peterkappus/b740d3d9d52ab7d15fb991c1f89cb651 to your computer and use it in GitHub Desktop.
Get open github pull requests in Google Sheets - Google Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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