Skip to content

Instantly share code, notes, and snippets.

@mathias
Created August 30, 2024 16:02
Show Gist options
  • Save mathias/cfe4e94783b4b1286a49bb58430b0e3f to your computer and use it in GitHub Desktop.
Save mathias/cfe4e94783b4b1286a49bb58430b0e3f to your computer and use it in GitHub Desktop.
Using gmail-britta to accomplish Ben Balter's GH filters
require 'gmail-britta'
# To use: ruby filters.rb > filters.xml
# and upload the filters.xml to GMail
YOUR_NAME = "Matt Gauger" # CHANGE ME
YOUR_EMAIL = "[email protected]" # CHANGE ME
GITHUB_REASONS = [
"assign",
"author",
"ci_activity",
"comment",
"manual",
"mention",
"push",
"review_requested",
"security_alert",
"state_change",
"subscribed",
"team_mention",
"your_activity"
]
OPTS = {
me: [YOUR_EMAIL],
author: {
name: YOUR_NAME
email: YOUR_EMAIL
}
}
fs = GmailBritta.filterset(OPTS) do
GITHUB_REASONS.each do |reason|
filter {
has %W{from:([email protected]) cc:#{reason}@noreply.github.com}
label "github/#{reason}"
archive
}
end
# Service notifications -- feel free to make your own!
filter {
has %w{from:[email protected]}
label "slack"
archive
}
# Spam subjects to always archive:
subjects =
"Hand-picked music, delivered weekly.", # CHANGE ME, this is just an example!
]
filter {
has [{:or => subjects.map { |s| "subject:\"#{s}\"" }}]
archive
mark_unimportant
}
end
puts fs.generate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment