Skip to content
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

Proposed refactor: convert notification bodies to ERB templates #197

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions lib/ontologies_linked_data/utils/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,16 @@

def self.obofoundry_sync(missing_onts, obsolete_onts)
ui_name = LinkedData.settings.ui_name
subject = "[#{ui_name}] OBO Foundry synchronization report"
body = ''

if missing_onts.size > 0
body << "<strong>The following OBO Library ontologies are missing from #{ui_name}:</strong><br/><br/>"
missing_onts.each do |ont|
body << "<a href='#{ont['homepage']}'>#{ont['id']}</a> (#{ont['title']})<br/><br/>"
end
end

if obsolete_onts.size > 0
body << '<strong>The following OBO Library ontologies have been deprecated:</strong><br/><br/>'
obsolete_onts.each do |ont|
body << "<a href='#{ont['homepage']}'>#{ont['id']}</a> (#{ont['title']})<br/><br/>"
end
end
gem_path = Gem.loaded_specs['ontologies_linked_data'].full_gem_path
template = File.read(File.join(gem_path, 'views/emails/obofoundry_sync.erb'))

Check warning on line 110 in lib/ontologies_linked_data/utils/notifications.rb

View check run for this annotation

Codecov / codecov/patch

lib/ontologies_linked_data/utils/notifications.rb#L109-L110

Added lines #L109 - L110 were not covered by tests

if body.empty?
body << "#{ui_name} and the OBO Foundry are in sync.<br/><br/>"
end
b = binding
b.local_variable_set(:ui_name, ui_name)
b.local_variable_set(:missing_onts, missing_onts)
b.local_variable_set(:obsolete_onts, obsolete_onts)
body = ERB.new(template).result(b)

Check warning on line 116 in lib/ontologies_linked_data/utils/notifications.rb

View check run for this annotation

Codecov / codecov/patch

lib/ontologies_linked_data/utils/notifications.rb#L112-L116

Added lines #L112 - L116 were not covered by tests

Notifier.notify_mails_separately subject, body, [LinkedData.settings.email_sender]
Notifier.notify_ontoportal_admins("[#{ui_name}] OBO Foundry synchronization report", body)

Check warning on line 118 in lib/ontologies_linked_data/utils/notifications.rb

View check run for this annotation

Codecov / codecov/patch

lib/ontologies_linked_data/utils/notifications.rb#L118

Added line #L118 was not covered by tests
end

NEW_NOTE = <<EOS
Expand Down
17 changes: 17 additions & 0 deletions views/emails/obofoundry_sync.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% if missing_onts.present? %>
<strong>The following OBO Foundry ontologies are missing from <%= ui_name %>:</strong><br /><br />
<% missing_onts.each do |ont| %>
<a href="<%= ont['homepage'] %>"><%= ont['id'] %></a> (<%= ont['title'] %>)<br /><br />
<% end %>
<% end %>

<% if obsolete_onts.present? %>
<strong>The following OBO Foundry ontologies have been deprecated:</strong><br /><br />
<% obsolete_onts.each do |ont| %>
<a href="<%= ont['homepage'] %>"><%= ont['id'] %></a> (<%= ont['title'] %>)<br /><br />
<% end %>
<% end %>

<% if missing_onts.blank? && obsolete_onts.blank? %>
<%= ui_name %> and the OBO Foundry are in sync.
<% end %>