Skip to content

Instantly share code, notes, and snippets.

@tpope
Created March 19, 2014 01:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpope/9633483 to your computer and use it in GitHub Desktop.
Save tpope/9633483 to your computer and use it in GitHub Desktop.
Add a gmail label to all closed issues where I the tpope last commented
require 'gmail'
require 'github_api'
require 'netrc'
require 'pry'
netrc = Netrc.read
github = Github.new(basic_auth: netrc['api.github.com'].join(':'))
Gmail.new(*netrc['imap.gmail.com']) do |gmail|
gmail.inbox.emails(from: 'github.com').each do |message|
begin
begin
_, owner, repo, type, number = *message.message_id.split(%r{[</@]})
rescue NoMethodError
# message removed from inbox since search began (?)
next
end
next unless %w(issues pull).include?(type)
repo = 'vim-fireplace' if repo == 'vim-foreplay'
issue = github.issues.get(owner, repo, number)
comment = github.issues.comments.list(owner, repo, issue_id: number, sort: 'created', direction: 'desc').first
if issue.state == 'closed' && (!comment || comment.user.login == 'tpope')
puts [owner, repo, type, number].join('/')
message.star! # doesn't seem to work
message.label('Test')
end
rescue => e
puts e.message
binding.pry
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment