-
-
Save davidpelayo/b356b67343d4a274d3ad to your computer and use it in GitHub Desktop.
Fetch list of issues from Github and draft an email
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
//#!/usr/bin/env groovy | |
import groovy.json.JsonSlurper | |
import java.text.SimpleDateFormat | |
// fetches a Github API URL and parses the result as JSON | |
def fetch(addr, params = [:]) { | |
def auth = "<personal api token>" | |
def json = new JsonSlurper() | |
return json.parse(addr.toURL().newReader(requestProperties: ["Authorization": "token ${auth}".toString(), "Accept": "application/json"])) | |
} | |
def format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'") | |
def repos = ['repo1', 'repo2', 'repo3'] | |
// the last week | |
def now = new Date() | |
def since = format.format(now - 7) | |
// start building the email body | |
def subject = "IT Summary for ${(now - 7).format('MM/dd')} - ${now.format('MM/dd')}" | |
def body = new StringBuilder() | |
body.append("\n") | |
// fetch the list of completed issues in the last week | |
body.append("Completed\n") | |
fetch("https://api.github.com/issues?filter=all&state=closed&since=${since}").findAll { it?.repository?.name in repos }.each { issue -> | |
body.append("* ${issue.title} [${issue.repository.name}]\n") | |
} | |
body.append("\n") | |
// fetch the list of current priorities (labeled 'next') | |
body.append("Current Priorities\n") | |
fetch("https://api.github.com/issues?filter=all&state=open&labels=next").findAll { it?.repository?.name in repos }.each { issue -> | |
body.append("* ${issue.title} [${issue.repository.name}]\n") | |
} | |
// create a new draft email in Mail.app | |
def applescript = """ | |
tell application "Mail" | |
make new outgoing message with properties {visible:true, subject:"${subject.replace('"', '\\"')}", content:"${body.toString().replace('"', '\\"')}"} | |
end tell | |
""" | |
["osascript", "-e", applescript].execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment