@ -71,14 +71,13 @@ class CommitGroup(enum.Enum):
def get ( cls , value : str ) - > tuple [ CommitGroup | None , str | None ] :
def get ( cls , value : str ) - > tuple [ CommitGroup | None , str | None ] :
group , _ , subgroup = ( group . strip ( ) . lower ( ) for group in value . partition ( ' / ' ) )
group , _ , subgroup = ( group . strip ( ) . lower ( ) for group in value . partition ( ' / ' ) )
result = cls . group_lookup ( ) . get ( group )
if result := cls . group_lookup ( ) . get ( group ) :
if not result :
return result , subgroup or None
if subgroup :
if subgroup :
return None , value
return None , value
subgroup = group
result = cls . subgroup_lookup ( ) . get ( subgroup )
return re sult , sub group or None
return cls . subgroup_lookup ( ) . get ( group ) , group or None
@dataclass
@dataclass
@ -136,8 +135,7 @@ class Changelog:
first = False
first = False
yield ' \n <details><summary><h3>Changelog</h3></summary> \n '
yield ' \n <details><summary><h3>Changelog</h3></summary> \n '
group = groups [ item ]
if group := groups [ item ] :
if group :
yield self . format_module ( item . value , group )
yield self . format_module ( item . value , group )
if self . _collapsible :
if self . _collapsible :
@ -253,7 +251,7 @@ class CommitRange:
''' , re.VERBOSE | re.DOTALL)
''' , re.VERBOSE | re.DOTALL)
EXTRACTOR_INDICATOR_RE = re . compile ( r ' (?:Fix|Add) \ s+Extractors? ' , re . IGNORECASE )
EXTRACTOR_INDICATOR_RE = re . compile ( r ' (?:Fix|Add) \ s+Extractors? ' , re . IGNORECASE )
REVERT_RE = re . compile ( r ' (?: \ [[^ \ ]]+ \ ] \ s+)?(?i:Revert) \ s+([ \ da-f] {40} ) ' )
REVERT_RE = re . compile ( r ' (?: \ [[^ \ ]]+ \ ] \ s+)?(?i:Revert) \ s+([ \ da-f] {40} ) ' )
FIXES_RE = re . compile ( r ' (?i: F ix(?:es)?(?:\ s+bugs?)?(?: \ s+in| \ s+for)? |Revert |Improve)\ s+([ \ da-f] {40} ) ' )
FIXES_RE = re . compile ( r ' (?i: (?:bug\ s*)?f ix(?:es)?(?:\ s+bugs?)?(?: \ s+in| \ s+for)? |Improve)\ s+([ \ da-f] {40} ) ' )
UPSTREAM_MERGE_RE = re . compile ( r ' Update to ytdl-commit-([ \ da-f]+) ' )
UPSTREAM_MERGE_RE = re . compile ( r ' Update to ytdl-commit-([ \ da-f]+) ' )
def __init__ ( self , start , end , default_author = None ) :
def __init__ ( self , start , end , default_author = None ) :
@ -287,11 +285,16 @@ class CommitRange:
short = next ( lines )
short = next ( lines )
skip = short . startswith ( ' Release ' ) or short == ' [version] update '
skip = short . startswith ( ' Release ' ) or short == ' [version] update '
fix_commitish = None
if match := self . FIXES_RE . search ( short ) :
fix_commitish = match . group ( 1 )
authors = [ default_author ] if default_author else [ ]
authors = [ default_author ] if default_author else [ ]
for line in iter ( lambda : next ( lines ) , self . COMMIT_SEPARATOR ) :
for line in iter ( lambda : next ( lines ) , self . COMMIT_SEPARATOR ) :
match = self . AUTHOR_INDICATOR_RE . match ( line )
if match := self . AUTHOR_INDICATOR_RE . match ( line ) :
if match :
authors = sorted ( map ( str . strip , line [ match . end ( ) : ] . split ( ' , ' ) ) , key = str . casefold )
authors = sorted ( map ( str . strip , line [ match . end ( ) : ] . split ( ' , ' ) ) , key = str . casefold )
if not fix_commitish and ( match := self . FIXES_RE . fullmatch ( line ) ) :
fix_commitish = match . group ( 1 )
commit = Commit ( commit_hash , short , authors )
commit = Commit ( commit_hash , short , authors )
if skip and ( self . _start or not i ) :
if skip and ( self . _start or not i ) :
@ -301,21 +304,17 @@ class CommitRange:
logger . debug ( f ' Reached Release commit, breaking: { commit } ' )
logger . debug ( f ' Reached Release commit, breaking: { commit } ' )
break
break
revert_match = self . REVERT_RE . fullmatch ( commit . short )
if match := self . REVERT_RE . fullmatch ( commit . short ) :
if revert_match :
reverts [ match . group ( 1 ) ] = commit
reverts [ revert_match . group ( 1 ) ] = commit
continue
continue
fix_match = self . FIXES_RE . search ( commit . short )
if fix_commitish :
if fix_match :
fixes [ fix_commitish ] . append ( commit )
commitish = fix_match . group ( 1 )
fixes [ commitish ] . append ( commit )
commits [ commit . hash ] = commit
commits [ commit . hash ] = commit
for commitish , revert_commit in reverts . items ( ) :
for commitish , revert_commit in reverts . items ( ) :
reverted = commits . pop ( commitish , None )
if reverted := commits . pop ( commitish , None ) :
if reverted :
logger . debug ( f ' { commitish } fully reverted { reverted } ' )
logger . debug ( f ' { commitish } fully reverted { reverted } ' )
else :
else :
commits [ revert_commit . hash ] = revert_commit
commits [ revert_commit . hash ] = revert_commit
@ -461,8 +460,7 @@ def create_changelog(args):
logger . info ( f ' Loaded { len ( commits ) } commits ' )
logger . info ( f ' Loaded { len ( commits ) } commits ' )
new_contributors = get_new_contributors ( args . contributors_path , commits )
if new_contributors := get_new_contributors ( args . contributors_path , commits ) :
if new_contributors :
if args . contributors :
if args . contributors :
write_file ( args . contributors_path , ' \n ' . join ( new_contributors ) + ' \n ' , mode = ' a ' )
write_file ( args . contributors_path , ' \n ' . join ( new_contributors ) + ' \n ' , mode = ' a ' )
logger . info ( f ' New contributors: { " , " . join ( new_contributors ) } ' )
logger . info ( f ' New contributors: { " , " . join ( new_contributors ) } ' )