Skip to content

Commit 4638947

Browse files
committed
refactor: drop unnecessary parameters + mv const to module
Release-Notes are created for a target github-repository. While there _might_ be multiple OCM-Components within the same GitHub-Repository, our Pipeline-Template does not properly support this setup. Hence, it is of virtually no value to explicitly state the OCM-Component-Name in fallback release-notes-message. Hence, drop those parameters + also refactor involved code slightly (mv limit to module-"constant", rephrase).
1 parent 6238ca3 commit 4638947

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

github/util.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io
1010
import logging
1111
import re
12+
import textwrap
1213

1314
import typing
1415
from typing import Iterable, Tuple
@@ -29,6 +30,14 @@
2930

3031
logger = logging.getLogger(__name__)
3132

33+
'''
34+
The maximum allowed length of github-release-bodies.
35+
This limit is not documented explicitly in the GitHub docs. To see it, the error returned by
36+
GitHub when creating a release with more then the allowed number of characters must be
37+
looked at.
38+
'''
39+
MAXIMUM_GITHUB_RELEASE_BODY_LENGTH = 25000
40+
3241

3342
class RepoPermission(enum.Enum):
3443
PULL = "pull"
@@ -433,23 +442,15 @@ def create_tag(
433442
tagger=author
434443
)
435444

436-
MAXIMUM_GITHUB_RELEASE_BODY_LENGTH = 25000
437-
'''The limit is not documented explicitly in the GitHub docs. To see it, the error returned by
438-
GitHub when creating a release with more then the allowed number of characters must be
439-
looked at.'''
440-
441445
def _replacement_release_notes(
442446
self,
443447
asset_url: str,
444-
component_name: str,
445-
component_version: str,
446448
):
447-
return (
448-
f'The release-notes for component **{component_name}** in version '
449-
f'**{component_version}** exceeded the maximum length of '
450-
f'{self.MAXIMUM_GITHUB_RELEASE_BODY_LENGTH} characters allowed by GitHub for '
451-
'release-bodies.\n'
452-
f'They have been uploaded as release-asset and can be found at {asset_url}.'
449+
return textwrap.dedent(
450+
f'''\
451+
Release-Notes were too long (limit: {MAXIMUM_GITHUB_RELEASE_BODY_LENGTH} octets).
452+
They were instaed uploaded as [release-asset]({asset_url}).
453+
'''
453454
)
454455

455456
RELEASE_NOTES_ASSET_NAME = 'release_notes.md'
@@ -464,7 +465,7 @@ def create_release(
464465
component_name: str=None,
465466
component_version: str=None,
466467
):
467-
if len(body) < self.MAXIMUM_GITHUB_RELEASE_BODY_LENGTH:
468+
if len(body) < MAXIMUM_GITHUB_RELEASE_BODY_LENGTH:
468469
return self.repository.create_release(
469470
tag_name=tag_name,
470471
body=body,
@@ -494,9 +495,6 @@ def create_release(
494495
release.edit(
495496
body=self._replacement_release_notes(
496497
asset_url=release_notes_asset.browser_download_url,
497-
component_name=component_name,
498-
# Fallback: use tag_name if version not explicitly given
499-
component_version=component_version or tag_name,
500498
)
501499
)
502500
return release
@@ -550,8 +548,6 @@ def promote_draft_release(
550548
draft_release.edit(
551549
body=self._replacement_release_notes(
552550
asset_url=release_notes_asset.browser_download_url,
553-
component_name=component_name,
554-
component_version=release_version,
555551
)
556552
)
557553

@@ -570,7 +566,7 @@ def update_release_notes(
570566
f"in repository {self.repository}"
571567
)
572568

573-
if len(body) < self.MAXIMUM_GITHUB_RELEASE_BODY_LENGTH:
569+
if len(body) < MAXIMUM_GITHUB_RELEASE_BODY_LENGTH:
574570
release.edit(body=body)
575571
else:
576572
release_notes_asset = next(
@@ -590,8 +586,7 @@ def update_release_notes(
590586
release.edit(
591587
body=self._replacement_release_notes(
592588
asset_url=release_notes_asset.browser_download_url,
593-
component_version=tag_name,
594-
component_name=component_name)
589+
),
595590
)
596591

597592
return release

0 commit comments

Comments
 (0)