@@ -61,7 +61,7 @@ def merge_contributors(original_file, new_contributors):
61
61
Side effects:
62
62
- Modifies the original XML file in-place
63
63
"""
64
- with open (original_file , 'r' ,encoding = 'utf-8' ) as f :
64
+ with open (original_file , 'r' , encoding = 'utf-8' ) as f :
65
65
original_content = f .read ()
66
66
tree = ET .fromstring (original_content )
67
67
@@ -75,7 +75,7 @@ def merge_contributors(original_file, new_contributors):
75
75
sorted_contributors = sorted (
76
76
tree .findall ('contributor' ),
77
77
# Items which don't have a name attribute are placed at the end
78
- key = lambda x : unidecode (get_last_name (x .get ('name' , '\x7F ' ))) # '\x7F' is highest ASCII value
78
+ key = lambda x : unidecode (get_last_name (x .get ('name' , '\x7F ' ))) # '\x7F' is highest ASCII value
79
79
)
80
80
81
81
for cont in tree .findall ('contributor' ):
@@ -113,12 +113,12 @@ def merge_contributors(original_file, new_contributors):
113
113
for contributor in sorted_contributors :
114
114
contrib_line = '<contributor'
115
115
for attr , value in contributor .attrib .items ():
116
- contrib_line += f'\n { attr } ="{ html .escape (value ,quote = False )} "'
116
+ contrib_line += f'\n { attr } ="{ html .escape (value , quote = False )} "'
117
117
contrib_line += '/>'
118
118
xml_lines .append (contrib_line )
119
119
xml_lines .append ('</contributors>' )
120
120
121
- with open (original_file , 'w' ,encoding = 'utf-8' ) as f :
121
+ with open (original_file , 'w' , encoding = 'utf-8' ) as f :
122
122
f .write ('\n ' .join (xml_lines ))
123
123
124
124
@@ -151,16 +151,16 @@ def fetch_real_name(github_name):
151
151
"""
152
152
url = f"https://api.github.com/users/{ github_name } "
153
153
try :
154
- res = requests .get (url ,headers = HEADERS )
154
+ res = requests .get (url , headers = HEADERS )
155
155
res .raise_for_status ()
156
156
user = res .json ()
157
157
if not user ['name' ]:
158
158
return
159
159
name_parts = user ['name' ].split ()
160
- if len (name_parts ) < 2 : # Full name is not available
160
+ if len (name_parts ) < 2 : # Full name is not available
161
161
return
162
162
git_to_name [github_name ] = user ['name' ]
163
- new_names .append ((user ['name' ],github_name ))
163
+ new_names .append ((user ['name' ], github_name ))
164
164
except Exception as e :
165
165
print (f"Failed to fetch real name for @{ github_name } : { str (e )} " )
166
166
@@ -182,11 +182,11 @@ def update_names():
182
182
fetch_real_name (c )
183
183
for tag in all_info :
184
184
for pr in all_info [tag ]:
185
- pr ['creator' ] = git_to_name .get (pr ['creator' ],f"@{ pr ['creator' ]} " )
186
- pr ['authors' ] = [git_to_name .get (a ,f"@{ a } " ) for a in pr ['authors' ]]
187
- pr ['reviewers' ] = [git_to_name .get (r ,f"@{ r } " ) for r in pr ['reviewers' ]]
188
- all_contribs = set ([git_to_name .get (c ,f"@{ c } " ) for c in all_contribs ])
189
- first_contribs = set ([git_to_name .get (c ,f"@{ c } " ) for c in first_contribs ])
185
+ pr ['creator' ] = git_to_name .get (pr ['creator' ], f"@{ pr ['creator' ]} " )
186
+ pr ['authors' ] = [git_to_name .get (a , f"@{ a } " ) for a in pr ['authors' ]]
187
+ pr ['reviewers' ] = [git_to_name .get (r , f"@{ r } " ) for r in pr ['reviewers' ]]
188
+ all_contribs = set ([git_to_name .get (c , f"@{ c } " ) for c in all_contribs ])
189
+ first_contribs = set ([git_to_name .get (c , f"@{ c } " ) for c in first_contribs ])
190
190
191
191
192
192
def get_release_data (tag ):
@@ -393,7 +393,7 @@ def save_to_file(filename, ver, date_of_release):
393
393
file .write (f"their first contribution to Sage:\n \n " )
394
394
max_name_len = max ([len (c ) for c in all_contribs ])
395
395
for c in all_contribs :
396
- file .write (f" - { c } { ' ' * (max_name_len - len (c )) + ' [First contribution]' if c in first_contribs else '' } \n " )
396
+ file .write (f" - { c } { ' ' * (max_name_len - len (c )) + ' [First contribution]' if c in first_contribs else '' } \n " )
397
397
file .write (f"\n Release manager: { RELEASE_MANAGER } \n " )
398
398
pr_count = sum ([len (all_info [tag ]) for tag in all_info ])
399
399
file .write (f"\n We merged { pr_count } pull requests in this release." )
@@ -408,6 +408,44 @@ def save_to_file(filename, ver, date_of_release):
408
408
print (f"Saved changelog to { filename } " )
409
409
410
410
411
+ def get_latest_stable_release ():
412
+ """Fetch the latest stable release tag from the API.
413
+
414
+ Returns:
415
+ str | None: The latest release tag if successful, None if the request fails
416
+ """
417
+ url = f"{ BASE_URL } /releases/latest"
418
+ try :
419
+ res = requests .get (url , headers = HEADERS )
420
+ res .raise_for_status ()
421
+ res = res .json ()
422
+ tag = res ['tag_name' ]
423
+ date = get_release_date (res )
424
+ return {"tag" : tag , "date" : date }
425
+ except Exception as e :
426
+ print (f"Failed to fetch latest stable release" , e )
427
+ return None
428
+
429
+
430
+ def update_config (ver : str , release_date : str , config_file_path : str ):
431
+ """Update version and release date in the config file.
432
+
433
+ Args:
434
+ ver (str): New version to set
435
+ release_date (str): Release date to set
436
+ config_file_path (str): Path to the config file
437
+ """
438
+ with open (config_file_path , 'r' ) as file :
439
+ content = file .read ()
440
+
441
+ content = re .sub (r'release_date:\s*".*?"' , f'release_date: "{ release_date } "' , content )
442
+ content = re .sub (r'version:\s*".*?"' , f'version: "{ ver } "' , content )
443
+ content = re .sub (r'version_src:\s*".*?"' , f'version_src: "{ ver } "' , content )
444
+
445
+ with open (config_file_path , 'w' ) as file :
446
+ file .write (content )
447
+
448
+
411
449
if __name__ == '__main__' :
412
450
parser = argparse .ArgumentParser (description = "Fetch release data from GitHub and extract PR info" )
413
451
parser .add_argument ('version' , type = str , help = "The release version (e.g., 10.1)" )
@@ -450,12 +488,15 @@ def save_to_file(filename, ver, date_of_release):
450
488
all_contribs = sorted (all_contribs , key = lambda x : (x [0 ].startswith ('@' ), x [0 ]))
451
489
if all_info :
452
490
save_to_file (filepath , ver , date_of_release )
491
+ latest_release = get_latest_stable_release ()
492
+ if latest_release :
493
+ update_config (latest_release ['tag' ], latest_release ['date' ], 'conf/config.yaml' )
453
494
else :
454
495
print ("No information found." )
455
496
exit (1 )
456
497
457
498
if new_names :
458
- merge_contributors ('conf/contributors.xml' ,new_names )
499
+ merge_contributors ('conf/contributors.xml' , new_names )
459
500
print ("Added new contributors to conf/contributors.xml" )
460
501
else :
461
502
print ("No new contributors found." )
0 commit comments