Skip to content

Instantly share code, notes, and snippets.

@shaoshing
Last active March 7, 2016 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaoshing/9c289038da95f5dab257 to your computer and use it in GitHub Desktop.
Save shaoshing/9c289038da95f5dab257 to your computer and use it in GitHub Desktop.
var HIGH_PRI = 'is%3Aopen+is%3Aissue+label%3A%22High+Pri%22',
MEDIUM_PRI = 'is%3Aopen+is%3Aissue+label%3A%22Medium+Pri%22',
LOW_PRI = 'is%3Aopen+is%3Aissue+label%3A%22Low+Pri%22',
documentID = 'GOOGLE_DOCUMENT_ID';
function getIssueCount(query, open) {
var page = UrlFetchApp.fetch('https://github.com/adobe-photoshop/spaces-design/issues?q=' + query),
content = page.getContentText(),
reg = open === false ? /(\d{1,}) Closed/ : /(\d{1,}) Open/,
count = parseInt(content.match(reg)[1]);
return count;
}
function getDate() {
var now = new Date(),
year = now.getFullYear(),
month = now.getMonth()+1,
day = now.getDate();
// To be accepted by Github, month and day must have 0 padding.
month = month < 10 ? "0" + month : month;
day = day < 10 ? "0" + day : day;
return [year, month, day].join('-');
}
function updateIssueCounts() {
var today = getDate(),
highPriCount = getIssueCount(HIGH_PRI),
mediumPriCount = getIssueCount(MEDIUM_PRI),
lowPriCount = getIssueCount(LOW_PRI),
newCount = getIssueCount('is%3Aissue++created%3A'+today),
closedCount = getIssueCount('is%3Aissue++state%3Aclosed+updated%3A'+today, false),
sheet = SpreadsheetApp.openById(documentID);
sheet.appendRow([new Date(), highPriCount, mediumPriCount, lowPriCount, newCount, closedCount]);
}
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Git Hub')
.addItem('Update Now', 'updateIssueCounts')
.addToUi();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment