Last active
January 15, 2020 07:26
-
-
Save disksing/5eb3b9740cf1921e044fed4b58b08d35 to your computer and use it in GitHub Desktop.
Google App script for Gmail to add tags for GitHub notifications
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
function tagInbox() { | |
var now = new Date(); | |
var threads = GmailApp.getInboxThreads(); | |
for (var i = 0; i < threads.length; i++) { | |
var thread = threads[i]; | |
var messages = thread.getMessages(); | |
for (var j = messages.length-1; j >= 0; j--) { | |
var message = messages[j]; | |
if (now - message.getDate() > 30*60*1000) { // ignore mails from more than 0.5h ago. | |
break; | |
} | |
if (message.getFrom().indexOf("notifications@github.com") == -1) { // only care about github mails. | |
break; | |
} | |
GmailApp.getUserLabelByName("GitHub").addToThread(thread); | |
var body = message.getPlainBody(); | |
if (body.match(/^Merged #\d+ into [0-9a-zA-Z\.\-_]+\./) != null) { | |
GmailApp.getUserLabelByName("GitHub/Merged").addToThread(thread); | |
} | |
if (body.match(/^Closed #\d+\./) != null) { | |
GmailApp.getUserLabelByName("GitHub/Closed").addToThread(thread); | |
} | |
if (body.match(/ approved this pull request\./) != null) { | |
GmailApp.getUserLabelByName("GitHub/Approved").addToThread(thread); | |
} | |
thread.refresh(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment