Skip to content

Instantly share code, notes, and snippets.

@disksing
Last active January 15, 2020 07:26
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 disksing/5eb3b9740cf1921e044fed4b58b08d35 to your computer and use it in GitHub Desktop.
Save disksing/5eb3b9740cf1921e044fed4b58b08d35 to your computer and use it in GitHub Desktop.
Google App script for Gmail to add tags for GitHub notifications
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