Last active
March 2, 2023 21:26
-
-
Save joshareed/5706061 to your computer and use it in GitHub Desktop.
Revisions
-
Josh Reed revised this gist
Jun 4, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ //#!/usr/bin/env groovy import groovy.json.JsonSlurper import java.text.SimpleDateFormat -
Josh Reed created this gist
Jun 4, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ #!/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()