Last active
October 3, 2018 19:32
-
-
Save EddyVerbruggen/e394b07d1e2817effe551a4943fba0d4 to your computer and use it in GitHub Desktop.
Google Apps Script that adds GitHub repo and PR labels to your Gmail inbox
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 processInbox() { | |
var threads = GmailApp.search("is:unread in:inbox has:nouserlabels from:notifications@github.com newer_than:1h"); | |
for (var i = 0; i < threads.length; i++) { | |
var messages = threads[i].getMessages(); | |
for (var j = 0; j < messages.length; j++) { | |
processMessage(messages[j]); | |
} | |
} | |
} | |
function processMessage(message) { | |
var body = message.getRawContent(); | |
var subject = message.getSubject(); | |
var subjectFilter = "[EddyVerbruggen/"; // you may want to adjust this line, to filter only your own repos | |
if (subject.indexOf(subjectFilter) > -1) { | |
var repo = subject.substring(subject.indexOf("/") + 1, subject.indexOf("]")); | |
if (repo) { | |
// add the 'my-github-repo' label | |
if (!GmailApp.getUserLabelByName(repo)) { | |
GmailApp.createLabel(repo); | |
} | |
message.getThread().addLabel(GmailApp.getUserLabelByName(repo)); | |
// add the 'PR' label, if applicable | |
var isPullRequest = body.indexOf("/pull/") > -1; | |
if (isPullRequest) { | |
if (!GmailApp.getUserLabelByName("PR")) { | |
GmailApp.createLabel("PR"); | |
} | |
message.getThread().addLabel(GmailApp.getUserLabelByName("PR")); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment