Skip to content

Commit

Permalink
Correctly handle empty pr description
Browse files Browse the repository at this point in the history
  • Loading branch information
andrcuns committed Apr 15, 2022
1 parent 2223c0a commit 5956925
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions lib/allure_report_publisher/lib/helpers/url_section_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def self.match?(urls_block)
# @param [String] pr
# @return [String]
def updated_pr_description(pr_description)
return strip_separator(body) unless pr_description
return "#{pr_description}\n\n#{body}" unless pr_description.match?(DESCRIPTION_PATTERN)

job_entries = jobs_section(pr_description)
Expand All @@ -43,10 +44,10 @@ def updated_pr_description(pr_description)
#
# @return [String]
def comment_body(pr_comment = nil)
return body.gsub("---\n", "") unless pr_comment
return strip_separator(body) unless pr_comment

job_entries = jobs_section(pr_comment)
body(job_entries).gsub("---\n", "")
strip_separator(body(job_entries))
end

attr_reader :report_url,
Expand Down Expand Up @@ -89,17 +90,6 @@ def summary_table
@summary_table = summary_type ? Helpers::Summary.get(report_path, summary_type) : nil
end

# Return updated jobs section
#
# @param [String] urls
# @return [String]
def jobs_section(urls_block)
jobs = urls_block.match(JOBS_PATTERN)[1]
return jobs.gsub(job_entry_pattern, job_entry) if jobs.match?(job_entry_pattern)

"#{jobs}\n#{job_entry}"
end

# Single job report URL entry
#
# @return [String]
Expand All @@ -120,6 +110,25 @@ def job_entry
def job_entry_pattern
@job_entry_pattern ||= /<!-- #{build_name} -->\n([\s\S]+)\n<!-- #{build_name} -->/
end

# Return updated jobs section
#
# @param [String] urls
# @return [String]
def jobs_section(urls_block)
jobs = urls_block.match(JOBS_PATTERN)[1]
return jobs.gsub(job_entry_pattern, job_entry) if jobs.match?(job_entry_pattern)

"#{jobs}\n#{job_entry}"
end

# Strip separator from allure results section
#
# @param [String] body
# @return [String]
def strip_separator(body)
body.gsub("---\n", "")
end
end
end
end

0 comments on commit 5956925

Please sign in to comment.