Skip to content

Commit

Permalink
chore: fix a bug that caused delays in fetching duplicate release not…
Browse files Browse the repository at this point in the history
…es (#18571)
  • Loading branch information
qiancai authored Aug 14, 2024
1 parent 5bf6008 commit d7794c2
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions scripts/release_notes_update_pr_author_info_add_dup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def store_exst_rn(ext_path, version):
else:
return 0

def get_pr_info_from_github(cp_pr_link,cp_pr_title, current_pr_author):
def get_pr_info_from_github(row_number, cp_pr_link,cp_pr_title, current_pr_author):

g = Github(access_token, timeout=30)# Create a Github object with the access token
target_pr_number_existence = 1
Expand Down Expand Up @@ -103,9 +103,10 @@ def get_pr_info_from_github(cp_pr_link,cp_pr_title, current_pr_author):
pr_obj = repo_obj.get_pull(int(target_pr_number))# Get the pull request object
pr_author = pr_obj.user.login # Get the author of the pull request
except:
print("Failed to get the original PR information for this PR: " + cp_pr_link)
print(f"Row {row_number}: failed to find the non-bot author for this PR ({cp_pr_link}) created by {current_pr_author}.\n")
else:
pr_author = current_pr_author # Use the current author if the cherry-pick PR cannot be found
print(f"Row {row_number}: failed to find the non-bot author for this PR ({cp_pr_link}) created by {current_pr_author}.\n")

return(pr_author)

Expand Down Expand Up @@ -135,14 +136,24 @@ def update_pr_author_and_release_notes(excel_path):
# If pr_author is ti-chi-bot or ti-srebot
current_pr_author = row[pr_author_index]
current_formated_rn= row[pr_formated_rn_index]
pr_response = requests.get(row[pr_link_index])
if (current_pr_author in ['ti-chi-bot', 'ti-srebot']) and (pr_response.status_code == 200):
print ("Replacing the author info for row " + str(row_index) + ".")
actual_pr_author = get_pr_info_from_github(row[pr_link_index], row[pr_title_index], current_pr_author) # Get the PR author according to the cherry-pick PR
pr_author_cell = sheet.cell(row=row_index, column=pr_author_index+1, value = actual_pr_author)#Fill in the pr_author_cell
updated_formated_rn = current_formated_rn.replace("[{}](https://github.com/{}".format(current_pr_author, current_pr_author),"[{}](https://github.com/{}".format(actual_pr_author, actual_pr_author))
formated_release_note_cell = sheet.cell(row=row_index, column=pr_formated_rn_index+1, value = updated_formated_rn) # Fill in the formated_release_note_cell
current_pr_author = actual_pr_author

if (current_pr_author in ['ti-chi-bot', 'ti-srebot']):
try:
actual_pr_author = get_pr_info_from_github(str(row_index), row[pr_link_index], row[pr_title_index], current_pr_author) # Get the PR author according to the cherry-pick PR
if actual_pr_author != current_pr_author:
print ("Replacing the author info for row " + str(row_index) + ".")
pr_author_cell = sheet.cell(row=row_index, column=pr_author_index+1, value = actual_pr_author)#Fill in the pr_author_cell
updated_formated_rn = current_formated_rn.replace("[{}](https://github.com/{}".format(current_pr_author, current_pr_author),"[{}](https://github.com/{}".format(actual_pr_author, actual_pr_author))
formated_release_note_cell = sheet.cell(row=row_index, column=pr_formated_rn_index+1, value = updated_formated_rn) # Fill in the formated_release_note_cell
current_pr_author = actual_pr_author
else: # Do nothing if non-bot author is not found.
pass
except:
pr_response = requests.get(row[pr_link_index])
if pr_response.status_code != 200:
print (f"\nRow {str(row_index)}: failed to find the non-bot author for this PR ({row[pr_link_index]}) because this link cannot be accessed now.")
else:
print (f"\nRow {str(row_index)}: failed to find the non-bot author for this PR ({row[pr_link_index]}).")
else:
pass

Expand Down Expand Up @@ -232,12 +243,12 @@ def create_release_file(version, dup_notes_levels, dup_notes):
file.seek(0)
file.write(content)
file.truncate()
print(f'The v{version} release note is now created in the following directory: \n {release_file}')
print(f'\nThe v{version} release note is now created in the following directory: \n {release_file}')

if __name__ == '__main__':
note_pairs = store_exst_rn(ext_path, version)
dup_notes, dup_notes_levels = update_pr_author_and_release_notes(release_note_excel)
print ("The bot author info in the excel is now replaced with the actual authors.")
print ("\nThe bot author info in the excel is now replaced with the actual authors.")
version_parts = version.split('.')
if len(version_parts) >= 2:
create_release_file(version, dup_notes_levels, dup_notes)

0 comments on commit d7794c2

Please sign in to comment.