9
9
import io
10
10
import logging
11
11
import re
12
+ import textwrap
12
13
13
14
import typing
14
15
from typing import Iterable , Tuple
29
30
30
31
logger = logging .getLogger (__name__ )
31
32
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
+
32
41
33
42
class RepoPermission (enum .Enum ):
34
43
PULL = "pull"
@@ -433,23 +442,15 @@ def create_tag(
433
442
tagger = author
434
443
)
435
444
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
-
441
445
def _replacement_release_notes (
442
446
self ,
443
447
asset_url : str ,
444
- component_name : str ,
445
- component_version : str ,
446
448
):
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
+ '''
453
454
)
454
455
455
456
RELEASE_NOTES_ASSET_NAME = 'release_notes.md'
@@ -464,7 +465,7 @@ def create_release(
464
465
component_name : str = None ,
465
466
component_version : str = None ,
466
467
):
467
- if len (body ) < self . MAXIMUM_GITHUB_RELEASE_BODY_LENGTH :
468
+ if len (body ) < MAXIMUM_GITHUB_RELEASE_BODY_LENGTH :
468
469
return self .repository .create_release (
469
470
tag_name = tag_name ,
470
471
body = body ,
@@ -494,9 +495,6 @@ def create_release(
494
495
release .edit (
495
496
body = self ._replacement_release_notes (
496
497
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 ,
500
498
)
501
499
)
502
500
return release
@@ -550,8 +548,6 @@ def promote_draft_release(
550
548
draft_release .edit (
551
549
body = self ._replacement_release_notes (
552
550
asset_url = release_notes_asset .browser_download_url ,
553
- component_name = component_name ,
554
- component_version = release_version ,
555
551
)
556
552
)
557
553
@@ -570,7 +566,7 @@ def update_release_notes(
570
566
f"in repository { self .repository } "
571
567
)
572
568
573
- if len (body ) < self . MAXIMUM_GITHUB_RELEASE_BODY_LENGTH :
569
+ if len (body ) < MAXIMUM_GITHUB_RELEASE_BODY_LENGTH :
574
570
release .edit (body = body )
575
571
else :
576
572
release_notes_asset = next (
@@ -590,8 +586,7 @@ def update_release_notes(
590
586
release .edit (
591
587
body = self ._replacement_release_notes (
592
588
asset_url = release_notes_asset .browser_download_url ,
593
- component_version = tag_name ,
594
- component_name = component_name )
589
+ ),
595
590
)
596
591
597
592
return release
0 commit comments