Skip to content

Commit

Permalink
Revert release notes truncation logic; append bom diff to pr body
Browse files Browse the repository at this point in the history
- restore the previous behavior of truncating release notes
- the formatted diff is now appended tgo the pr body if space allows
- if the pr body limit is exceeded, the formatted diff is added to
  additional notes instead
  • Loading branch information
TuanAnh17N committed Nov 25, 2024
1 parent 84d797a commit 8d00291
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
35 changes: 18 additions & 17 deletions concourse/steps/update_component_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def _import_release_notes(
)

if not release_notes:
release_notes = pull_request_util.retrieve_pr_template_text()
release_notes = ''

return release_notes

Expand Down Expand Up @@ -540,20 +540,9 @@ def create_upgrade_pr(
additional_notes = []

pr_body = ''
if include_bom_diff:
# Split the formatted_diff if it exceeds max body length (line-by-line)
if len(formatted_diff) > max_pr_body_length:
truncated_diff = formatted_diff[:formatted_diff.find('## Component Details:')]
truncated_diff += '\n... [Component details omitted]\n'

pr_body = truncated_diff + max_body_length_exceeded_remark
else:
pr_body = formatted_diff

available_length = max_pr_body_length - len(pr_body)

if available_length < len(release_notes):
step_size = available_length - len(max_body_length_exceeded_remark)
if len(release_notes) > max_pr_body_length:
step_size = max_pr_body_length - len(max_body_length_exceeded_remark)
split_release_notes = [
release_notes[start:start + step_size]
for start in range(0, len(release_notes), step_size)
Expand All @@ -562,10 +551,22 @@ def create_upgrade_pr(
split_release_notes = [release_notes]

if len(split_release_notes) > 1:
pr_body += max_body_length_exceeded_remark
additional_notes = split_release_notes
pr_body += split_release_notes[0] + max_body_length_exceeded_remark
additional_notes = split_release_notes[1:]
else:
pr_body += '\n\n' + split_release_notes[0]
pr_body += split_release_notes[0]

if include_bom_diff:
if len(formatted_diff) <= max_pr_body_length - len(pr_body):
pr_body += '\n\n' + formatted_diff
else:
if len(formatted_diff) < max_pr_body_length:
additional_notes.append(formatted_diff)
else:
component_details_start = formatted_diff.find('## Component Details:')
additional_notes.append(formatted_diff[:component_details_start])
additional_notes.append(formatted_diff[component_details_start:])

else:
pr_body = ''
additional_notes = []
Expand Down
24 changes: 14 additions & 10 deletions test/cnudie/cnudie_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,27 @@ def test_componentdiff_to_str(cid):
names_only_right={'c'},
names_version_changed={'d'},
)
result = cnudie.util.format_component_diff(
formatted_diff = cnudie.util.format_component_diff(
component_diff=diff,
delivery_dashboard_url_view_diff=None,
delivery_dashboard_url=None,
)

max_length = 10
if len(result) > max_length:
truncated_result = result[:result.find('## Component Details:')]
truncated_result += '\n... [Component details omitted]\n'
body = truncated_result
release_notes = 'Release Notes\n' + 'A' * 500

max_pr_body_length = 100

additional_notes = []
pr_body = release_notes

if len(formatted_diff) <= max_pr_body_length - len(pr_body):
pr_body += '\n\n' + formatted_diff
else:
body = result
additional_notes.append(formatted_diff)

assert '### Added Components:' in body
assert '... [Component details omitted]' in body
assert '## Component Details:' not in body
assert len(pr_body) > max_pr_body_length, 'PR body exceeds the maximum allowed length'
assert len(additional_notes) > 0, 'additional notes should contain truncated content'
assert formatted_diff in additional_notes, 'diff should be in additional notes if truncated'


def test_iter_sorted():
Expand Down

0 comments on commit 8d00291

Please sign in to comment.