Skip to content

Commit

Permalink
Handle patchinfo tags as arrays
Browse files Browse the repository at this point in the history
Otherwise, the loop crashes when there is only one element (not an
array).
  • Loading branch information
saraycp committed Nov 28, 2023
1 parent c78ca42 commit f7d83f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/api/app/components/patchinfo_component.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
- if @patchinfo['releasetarget'].present?
%h6 Targeted for release in the following projects
%ul
- @patchinfo['releasetarget'].each do |releasetarget|
- release_targets.each do |releasetarget|
%li
- if (project = Project.find_by_name(releasetarget['project']))
= link_to(project_show_path(project)) do
Expand All @@ -50,19 +50,19 @@
- if @patchinfo['binary'].present?
%h6 Affected binaries
%ul
- @patchinfo['binary'].each do |binary|
- binaries.each do |binary|
%li= binary

- if @patchinfo['package'].present?
%h6 Affected packages
%ul
- @patchinfo['package'].each do |package|
- packages.each do |package|
%li= package

- if @patchinfo['issue'].present?
%h6 Issues related to the patch
%ul
- @patchinfo['issue'].each do |issue_hash|
- issues.each do |issue_hash|
- if (issue = Issue.find_or_create_by_name_and_tracker(issue_hash['id'], issue_hash['tracker']))
%li
= link_to(issue.url) do
Expand Down
7 changes: 6 additions & 1 deletion src/api/app/components/patchinfo_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class PatchinfoComponent < ApplicationComponent
attr_reader :patchinfo, :path
attr_reader :patchinfo, :path, :release_targets, :binaries, :packages, :issues

CATEGORY_COLOR = { ptf: 'text-bg-danger',
security: 'text-bg-warning',
Expand All @@ -18,6 +18,11 @@ def initialize(patchinfo, path)
super
@patchinfo = Xmlhash.parse(patchinfo)
@path = path

@release_targets = [@patchinfo['releasetarget']].flatten
@binaries = [@patchinfo['binary']].flatten
@packages = [@patchinfo['package']].flatten
@issues = [@patchinfo['issue']].flatten
end

def category
Expand Down

0 comments on commit f7d83f1

Please sign in to comment.