-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce SlackExplorer
#33
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
41fa185
Nest TopicExtractor to SimpleWriter
MatheusRich de667a2
Rewrite Slack::Client
MatheusRich 5a2e144
Introduce `GoldMiner::SlackExplorer`
MatheusRich d094c04
Remove unused const
MatheusRich 3ce66e8
Remove unnecessary double-caching
MatheusRich 7071784
Move GoldMiner::MessagesQuery to GoldMiner::Slack::MessagesQuery
MatheusRich dee6bd9
Improve spec
MatheusRich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module GoldMiner | ||
class BlogPost | ||
class SimpleWriter | ||
module TopicExtractor | ||
LANGUAGE_MATCHERS = { | ||
"Ruby" => ["ruby", "ruby on rails"], | ||
"Elixir" => ["elixir"], | ||
"JavaScript" => ["javascript", "js", "node", "nodejs", "yarn", "npm"], | ||
"TypeScript" => ["typescript", "ts"], | ||
"SQL" => ["sql"], | ||
"CSS" => ["css"] | ||
}.freeze | ||
TOOL_MATCHERS = { | ||
"Ruby on Rails" => ["ruby on rails"], | ||
"React" => ["react", "reactjs"], | ||
"React Native" => ["react native"], | ||
"Tailwind" => ["tailwind css", "tailwindcss", "tailwind"] | ||
} | ||
TECHNIQUE_MATCHERS = { | ||
"Refactoring" => ["refactor", "refactoring"], | ||
"Testing" => ["test", "tests", "testing"] | ||
}.freeze | ||
PARDIGM_MATCHERS = { | ||
"Functional Programming" => ["functional programming"], | ||
"OOP" => ["object oriented programming", "oop"] | ||
}.freeze | ||
OTHER_MATCHERS = { | ||
"TIL" => ["til", "today i learned", "today i learnt"], | ||
"Tip" => ["tip", "tips"] | ||
} | ||
TOPIC_MATCHERS = { | ||
**LANGUAGE_MATCHERS, | ||
**TECHNIQUE_MATCHERS, | ||
**TOOL_MATCHERS, | ||
**PARDIGM_MATCHERS, | ||
**OTHER_MATCHERS | ||
}.freeze | ||
|
||
def self.call(message_text) | ||
words = message_text.downcase.split(/\W/) | ||
sanitized_text = words.join(" ") | ||
topics = Set[] | ||
|
||
TOPIC_MATCHERS.each do |topic_label, topic_matchers| | ||
topic_matchers.each do |topic_matcher| | ||
topics << topic_label if sanitized_text.match?(/\b#{topic_matcher}\b/) | ||
end | ||
end | ||
|
||
topics.to_a | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module GoldMiner | ||
module Slack | ||
class MessagesQuery | ||
attr_reader :channel, :start_date, :topic, :reaction | ||
|
||
def initialize(channel: nil, start_date: nil, topic: nil, reaction: nil) | ||
@channel = channel | ||
@start_date = start_date | ||
@topic = topic | ||
@reaction = reaction | ||
end | ||
|
||
def on_channel(new_channel) | ||
with(channel: new_channel) | ||
end | ||
|
||
def sent_after(new_start_date) | ||
with(start_date: new_start_date) | ||
end | ||
|
||
def with_topic(new_topic) | ||
with(topic: new_topic) | ||
end | ||
|
||
def with_reaction(new_reaction) | ||
with(reaction: new_reaction) | ||
end | ||
|
||
def with(**new_attributes) | ||
old_attributes = {channel: channel, start_date: start_date, topic: topic, reaction: reaction} | ||
|
||
self.class.new(**old_attributes.merge(new_attributes)) | ||
end | ||
|
||
def to_s | ||
[ | ||
topic, | ||
channel && "in:#{channel}", | ||
start_date && "after:#{start_date}", | ||
reaction && "has::#{reaction}:" | ||
].compact.join(" ") | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require "async" | ||
|
||
module GoldMiner | ||
class SlackExplorer | ||
def initialize(slack_client, author_config) | ||
@slack = slack_client | ||
@author_config = author_config | ||
end | ||
|
||
def explore(channel, start_on:) | ||
interesting_messages = interesting_messages_query(channel, start_on) | ||
|
||
Sync do | ||
til_messages_task = Async { search_messages(interesting_messages.with_topic("TIL")) } | ||
tip_messages_task = Async { search_messages(interesting_messages.with_topic("tip")) } | ||
hand_picked_messages_task = Async { search_messages(interesting_messages.with_reaction("rupee-gold")) } | ||
|
||
merge_messages(til_messages_task, tip_messages_task, hand_picked_messages_task) | ||
end | ||
end | ||
|
||
private | ||
|
||
def interesting_messages_query(channel, start_on) | ||
Slack::MessagesQuery | ||
.new | ||
.on_channel(channel) | ||
.sent_after(Date.parse(start_on.to_s)) | ||
end | ||
|
||
def merge_messages(*search_tasks) | ||
search_tasks | ||
.flat_map { |task| task.wait.messages.matches } | ||
.uniq { |message| message[:permalink] } | ||
.map { |message| | ||
Slack::Message.new( | ||
text: message.text, | ||
author: author_of(message), | ||
permalink: message.permalink | ||
) | ||
} | ||
end | ||
|
||
def author_of(message) | ||
Slack::User.new( | ||
name: message.author_real_name, | ||
link: link_for(message.username), | ||
id: message.user, | ||
username: message.username | ||
) | ||
end | ||
|
||
def search_messages(query) | ||
@slack.search_messages(query.to_s) | ||
end | ||
|
||
def link_for(username) | ||
@author_config.link_for(username) | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be deleted from
Slack::Client
because it has been moved toSlackExplorer