Skip to content

Commit

Permalink
Introduces a terse commit feed view
Browse files Browse the repository at this point in the history
Single line text instead of multi line HTML. Useful if you just want to know what's going on.
  • Loading branch information
hennevogel committed Sep 7, 2021
1 parent c171afc commit 84a0f85
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 47 deletions.
29 changes: 14 additions & 15 deletions src/api/app/controllers/webui/feeds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class Webui::FeedsController < Webui::WebuiController
layout false
before_action :set_project, only: [:commits]
before_action :set_timerange, only: [:commits]

def news
@news = StatusMessage.newest.for_current_user.includes(:user).limit(5)
Expand All @@ -15,12 +16,11 @@ def latest_updates
def commits
authorize @project, :source_access?

@start = params[:starting_at].present? ? starting_at(params[:starting_at]) : 7.days.ago
@finish = params[:ending_at].present? ? ending_at(params[:ending_at]) : nil
@terse = params[:terse].present?

@commits = @project.project_log_entries.where(event_type: 'commit').where(['datetime >= ?', @start])
@commits = @commits.where(['datetime <= ?', @finish]) unless @finish.nil?
@commits = @commits.order('datetime desc')
commits = @project.project_log_entries.where(event_type: 'commit').where(['datetime >= ?', @start])
commits = commits.where(['datetime <= ?', @finish]) if @finish.present?
@commits = commits.order('datetime desc')
end

def notifications
Expand All @@ -38,15 +38,14 @@ def notifications

private

def starting_at(date)
Time.zone.parse(date)
rescue StandardError
7.days.ago
end

def ending_at(date)
Time.zone.parse(date)
rescue StandardError
nil
def set_timerange
start = params.fetch(:starting_at, 7.days.ago.to_s)
@start = Time.zone.parse(start)
finish = params['ending_at']
@finish = Time.zone.parse(finish) if finish
# Ignore params if the date string is invalid...
rescue ArgumentError
@start = 7.days.ago
@finish = nil
end
end
71 changes: 39 additions & 32 deletions src/api/app/views/webui/feeds/commits.atom.builder
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Don't ask me why atom_feed helper does not work. Reimplementing its logic
# FIXME: atom_feed helper bails out with
# ActionView::Template::Error (A document may not have multiple root nodes.)
# Reimplementing its logic...
feed_opts = { 'xml:lang' => 'en-US',
'xmlns' => 'http://www.w3.org/2005/Atom' }
schema_date = '2013-11-22'
Expand All @@ -17,40 +19,44 @@ xml.feed(feed_opts) do |feed|
user = commit.user_name
reqid = BsRequest.find(commit.bs_request_id).number if commit.bs_request_id
datetime = commit.datetime
url = ''

title = "In #{package}"
title += " (request #{reqid})" if reqid.present?
entry.title(title)
entry.content type: 'xhtml' do |xhtml|
xhtml.div do |div|
div.p commit.message
div.p 'Basic information:'
div.dl do |dl|
dl.dt 'Package'
dl.dd do |dd|
url = url_for(only_path: false, controller: 'package', action: 'rdiff', project: @project.name,
package_url = url_for(only_path: false, controller: 'package', action: 'rdiff', project: @project.name,
package: package, rev: commit.additional_info['rev'], linkrev: 'base')
dd.a package, href: url
end
dl.dt 'User'
dl.dd user
dl.dt 'Request'
if reqid
# prefer the request url
url = request_show_url(reqid)
request_url = request_show_url(reqid) if reqid.present?

if @terse
entry.title("New commit in #{package}")
content = "Revision #{commit.additional_info['rev']}"
content += " via request #{reqid}" if reqid.present?
content += ' via service' if commit.message == 'trigger service run'
entry.content(content, type: 'text')
else
title = "New commit in #{package} (#{commit.additional_info['rev']}) by #{user}"
title += " (via #{reqid})" if reqid.present?
entry.title(title)
entry.content type: 'xhtml' do |xhtml|
xhtml.div do |div|
div.p commit.message
div.p 'Basic information:'
div.dl do |dl|
dl.dt 'Package'
dl.dd do |dd|
dd.a reqid, href: url
dd.a package, href: package_url
end
dl.dt 'User'
dl.dd user
if reqid
dl.dt 'Request'
dl.dd do |dd|
dd.a reqid, href: request_url
end
end
else
dl.dd reqid
end
end
div.p 'Additional information:'
div.dl do |dl|
commit.additional_info.each do |k, v|
dl.dt k
dl.dd v
div.p 'Additional information:'
div.dl do |dl|
commit.additional_info.each do |k, v|
dl.dt k
dl.dd v
end
end
end
end
Expand All @@ -62,7 +68,8 @@ xml.feed(feed_opts) do |feed|

entry.published(datetime.iso8601)
entry.id("tag:#{obs_host},2013-12-01:#{@project.name}/#{commit.id}")
entry.link(href: url)
entry_url = reqid.present? ? request_url : package_url
entry.link(href: entry_url)
entry.updated(datetime.iso8601)
end
end
Expand Down

0 comments on commit 84a0f85

Please sign in to comment.