Commit d915085b authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'cablett-refactor-akismet-service' into 'master'

Refactor Akismet service

See merge request gitlab-org/gitlab!22651
parents c5ffcffc 78cee84a
# frozen_string_literal: true
class AkismetService
attr_accessor :owner, :text, :options
attr_accessor :text, :options
def initialize(owner, text, options = {})
@owner = owner
def initialize(owner_name, owner_email, text, options = {})
@owner_name = owner_name
@owner_email = owner_email
@text = text
@options = options
end
......@@ -16,8 +17,8 @@ class AkismetService
type: 'comment',
text: text,
created_at: DateTime.now,
author: owner.name,
author_email: owner.email,
author: owner_name,
author_email: owner_email,
referrer: options[:referrer]
}
......@@ -40,6 +41,8 @@ class AkismetService
private
attr_accessor :owner_name, :owner_email
def akismet_client
@akismet_client ||= ::Akismet::Client.new(Gitlab::CurrentSettings.akismet_api_key,
Gitlab.config.gitlab.url)
......@@ -55,8 +58,8 @@ class AkismetService
params = {
type: 'comment',
text: text,
author: owner.name,
author_email: owner.email
author: owner_name,
author_email: owner_email
}
begin
......
......@@ -18,8 +18,10 @@ class HamService
private
def akismet
user = spam_log.user
@akismet ||= AkismetService.new(
spam_log.user,
user.name,
user.email,
spam_log.text,
ip_address: spam_log.source_ip,
user_agent: spam_log.user_agent
......
......@@ -56,7 +56,8 @@ class SpamService
def akismet
@akismet ||= AkismetService.new(
spammable_owner,
spammable_owner.name,
spammable_owner.email,
spammable.spammable_text,
options
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment