Class: GithubDeprecations::Worker
- Inherits:
-
Object
- Object
- GithubDeprecations::Worker
- Defined in:
- lib/github_deprecations.rb
Class Method Summary collapse
Instance Method Summary collapse
- #client ⇒ Object
- #create_issue(title, body) ⇒ Object
-
#create_labels ⇒ Object
Create any missing issue labels.
-
#find_issue(title) ⇒ Object
Find an existing issue with the same message.
-
#initialize(options) ⇒ Worker
constructor
A new instance of Worker.
-
#normalize_title(warning) ⇒ Object
Shorten warnings and remove common stuff.
-
#submit_issue!(event_params) ⇒ Object
Create or update an issue based on deprecation warning.
- #update_issue(issue_number, title, body) ⇒ Object
Constructor Details
#initialize(options) ⇒ Worker
Returns a new instance of Worker.
64 65 66 |
# File 'lib/github_deprecations.rb', line 64 def initialize() @options = Hashie::Mash.new() # serialization drops mash end |
Class Method Details
.perform(options, event_params) ⇒ Object
60 61 62 |
# File 'lib/github_deprecations.rb', line 60 def self.perform(, event_params) new().submit_issue!(event_params) end |
Instance Method Details
#client ⇒ Object
115 116 117 118 119 120 |
# File 'lib/github_deprecations.rb', line 115 def client @client ||= Octokit::Client.new({ :login => @options.login, :oauth_token => @options.oauth_token }) end |
#create_issue(title, body) ⇒ Object
107 108 109 |
# File 'lib/github_deprecations.rb', line 107 def create_issue(title, body) client.create_issue(@options.repo, title, body, :labels => @options.labels) end |
#create_labels ⇒ Object
Create any missing issue labels.
91 92 93 94 95 96 97 |
# File 'lib/github_deprecations.rb', line 91 def create_labels @options.labels.each do |label| client.add_label(@options.repo, label) end rescue Octokit::UnprocessableEntity => e # assume label already exists and do nothing end |
#find_issue(title) ⇒ Object
Find an existing issue with the same message.
Returns Hashie::Mash of issue if found, otherwise nil
102 103 104 105 |
# File 'lib/github_deprecations.rb', line 102 def find_issue(title) issues = client.list_issues(@options.repo, :labels => @options.labels.join(',')) issues.detect {|i| i.title == title} end |
#normalize_title(warning) ⇒ Object
Shorten warnings and remove common stuff
123 124 125 126 127 |
# File 'lib/github_deprecations.rb', line 123 def normalize_title(warning) warning. gsub(%r{DEPRECATION WARNING: ?}, ''). gsub(%r{ *\(called from.*}, '') end |
#submit_issue!(event_params) ⇒ Object
Create or update an issue based on deprecation warning.
if we wanted to be fancy calculating an edit-distance probably removes a lot of duplicates test: when title is too long, then what? what about sha-ing the title and prefixing that to the title?
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/github_deprecations.rb', line 73 def submit_issue!(event_params) # datetime objects are being serialized to string? event_params[1] = DateTime.parse(event_params[1]) event_params[2] = DateTime.parse(event_params[2]) event = ActiveSupport::Notifications::Event.new(*event_params) payload = Hashie::Mash.new(event.payload) title = normalize_title(payload[:message]) body = "```\n" + payload[:callstack].join("\n") + "\n```\n" # ghetto markdown-ify create_labels match = find_issue(title) res = match ? update_issue(match.number, title, body) : create_issue(title, body) end |
#update_issue(issue_number, title, body) ⇒ Object
111 112 113 |
# File 'lib/github_deprecations.rb', line 111 def update_issue(issue_number, title, body) client.update_issue(@options.repo, issue_number, title, body) end |