-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved text message creation process #17
- Loading branch information
Showing
8 changed files
with
232 additions
and
172 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,109 @@ | ||
module RedmineIssueAssignNotice | ||
module Formatter | ||
|
||
def create(url) | ||
if url.include? 'slack.com/' | ||
return Slack.new | ||
class Slack | ||
def escape(msg) | ||
msg.to_s.gsub("&", "&").gsub("<", "<").gsub(">", ">") | ||
end | ||
if url.include? 'office.com/' | ||
return Teams.new | ||
|
||
def change_line | ||
"\n" | ||
end | ||
|
||
if url.include? 'googleapis.com/' | ||
return GoogleChat.new | ||
def link(title, url) | ||
"<#{url}|#{escape(title)}>" | ||
end | ||
|
||
Default.new | ||
end | ||
def user_name(user) | ||
if user.nil? | ||
'_[none]_' | ||
else | ||
"_#{escape(user).gsub("_", " ")}_" | ||
end | ||
end | ||
|
||
module_function :create | ||
def mention(id) | ||
"<@#{id}>" | ||
end | ||
end | ||
|
||
class Default | ||
class Teams | ||
def escape(msg) | ||
msg.to_s.gsub("&", "&").gsub("<", "<").gsub(">", ">") | ||
msg.to_s | ||
end | ||
|
||
def change_line | ||
"\n" | ||
" \n" | ||
end | ||
|
||
def link(title, url) | ||
"<#{url}|#{escape title}>" | ||
end | ||
|
||
def mention(id) | ||
"@#{id}" | ||
"[#{escape(title).gsub("[", " ").gsub("]", " ")}](#{url})" | ||
end | ||
|
||
def user_name(user) | ||
if user.nil? | ||
'_[none]_' | ||
else | ||
"_#{escape user}_" | ||
"_#{escape(user).gsub("_", " ")}_" | ||
end | ||
end | ||
|
||
def trimming(note) | ||
if note.nil? | ||
return '' | ||
end | ||
|
||
flat = note.gsub(/\r\n|\n|\r/, ' ') | ||
if flat.length > 200 | ||
flat[0, 200] + '...' | ||
def mention(id) | ||
"@#{id}" | ||
end | ||
end | ||
|
||
class GoogleChat | ||
def escape(msg) | ||
msg.to_s.gsub("&", "&").gsub("<", "<").gsub(">", ">") | ||
end | ||
|
||
def change_line | ||
"\n" | ||
end | ||
|
||
def link(title, url) | ||
"<#{url}|#{escape(title)}>" | ||
end | ||
|
||
def user_name(user) | ||
if user.nil? | ||
'_[none]_' | ||
else | ||
flat | ||
"_#{escape(user).gsub("_", " ")}_" | ||
end | ||
end | ||
end | ||
|
||
class Slack < Default | ||
def mention(id) | ||
"<@#{id}>" | ||
"<users/#{id}>" | ||
end | ||
end | ||
|
||
class Teams < Default | ||
class Other | ||
def escape(msg) | ||
msg.to_s.gsub("&", "&").gsub("<", "<").gsub(">", ">").gsub("[", "\\[").gsub("]", "\\]") | ||
msg.to_s | ||
end | ||
|
||
def change_line | ||
" \n" | ||
"\n" | ||
end | ||
|
||
def link(title, url) | ||
"[#{escape title}](#{url})" | ||
"[#{escape(title).gsub("[", " ").gsub("]", " ")}](#{url})" | ||
end | ||
|
||
def mention(id) | ||
"@#{id}" | ||
def user_name(user) | ||
if user.nil? | ||
'_[none]_' | ||
else | ||
"_#{escape(user).gsub("_", " ")}_" | ||
end | ||
end | ||
end | ||
|
||
class GoogleChat < Default | ||
def mention(id) | ||
"<users/#{id}>" | ||
"@#{id}" | ||
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
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,49 @@ | ||
module RedmineIssueAssignNotice | ||
module MessageCreator | ||
|
||
def from(url) | ||
if url.include? 'slack.com/' | ||
return TextMessageCreator.new(Formatter::Slack.new) | ||
end | ||
|
||
if url.include? 'office.com/' | ||
return TextMessageCreator.new(Formatter::Teams.new) | ||
end | ||
|
||
if url.include? 'googleapis.com/' | ||
return TextMessageCreator.new(Formatter::GoogleChat.new) | ||
end | ||
|
||
return TextMessageCreator.new(Formatter::Other.new) | ||
end | ||
|
||
module_function :from | ||
|
||
class TextMessageCreator | ||
def initialize(formatter) | ||
@formatter = formatter | ||
end | ||
|
||
def create(issue, old_assgined_to, new_assgined_to, note, author) | ||
|
||
text = "" | ||
|
||
mention_to = MessageHelper.mention_target(new_assgined_to, author) | ||
if mention_to.present? | ||
text << @formatter.mention(mention_to) | ||
text << " " | ||
end | ||
|
||
text << "Assign changed from #{@formatter.user_name old_assgined_to} to #{@formatter.user_name new_assgined_to}" | ||
text << @formatter.change_line | ||
text << "[#{@formatter.escape issue.project}] " | ||
text << @formatter.link("#{issue.tracker} ##{issue.id}", MessageHelper.issue_url(issue)) | ||
text << " #{@formatter.escape issue.subject} (#{@formatter.escape issue.status})" | ||
text << @formatter.change_line | ||
text << @formatter.escape(MessageHelper.trimming(note)) | ||
|
||
return {:text => text} | ||
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
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
Oops, something went wrong.