Skip to content

Commit

Permalink
Generate the CHANGELOG based on the PR's target branch [skip ci] (#11867
Browse files Browse the repository at this point in the history
)

* Generate the CHANGELOG based on the PR's target branch

To fix: #11866

Generate the CHANGELOG based on the PR's target branch if the PR's project roadmap is empty.

Signed-off-by: Tim Liu <[email protected]>

* Remove the unused variable 'no_project_prs.'

We won't need the 'no_project_prs' variable because PRs will be added to the CHANGELOG.

Signed-off-by: Tim Liu <[email protected]>

* Remove project cards checking

it is no longer necessary to maintain compatibility with the old version of GitHub Projects

Signed-off-by: Tim Liu <[email protected]>

---------

Signed-off-by: Tim Liu <[email protected]>
  • Loading branch information
NvTimLiu authored Dec 13, 2024
1 parent f9dc579 commit edb7a67
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions scripts/generate-changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Copyright (c) 2020-2023, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -164,8 +164,7 @@ query ($after: String, $since: DateTime) {
"""


def process_changelog(resource_type: str, changelog: dict, releases: set, projects: set, no_project_prs: list,
token: str):
def process_changelog(resource_type: str, changelog: dict, releases: set, projects: set, token: str):
if resource_type == PULL_REQUESTS:
items = process_pr(releases=releases, token=token)
time_field = 'mergedAt'
Expand All @@ -178,14 +177,14 @@ def process_changelog(resource_type: str, changelog: dict, releases: set, projec

for item in items:
if len(item["projectItems"]["nodes"]) == 0 or not item["projectItems"]["nodes"][0]['roadmap']:
# compatibility support for project API V1
if len(item['projectCards']['nodes']) == 0:
if resource_type == PULL_REQUESTS:
if '[bot]' in item['title']:
continue # skip auto-gen PR
no_project_prs.append(item)
if resource_type == PULL_REQUESTS:
if '[bot]' in item['title']:
continue # skip auto-gen PR
# Obtain the version from the PR's target branch, e.g. branch-x.y --> x.y
ver = item['baseRefName'].replace('branch-', '')
project = f"{RELEASE} {ver}"
else:
continue
project = item['projectCards']['nodes'][0]['project']['name']
else:
ver = item["projectItems"]["nodes"][0]['roadmap']['name']
project = f"{RELEASE} {ver}"
Expand Down Expand Up @@ -309,12 +308,6 @@ def form_subsection(issues: dict, subtitle: str):
return subsection


def print_no_project_pr(no_project_prs: list):
if len(no_project_prs) != 0:
print("\nNOTE: Merged Pull Requests w/o Project:")
for pr in no_project_prs:
print(f"{pr['baseRefName']} #{pr['number']} {pr['title']} {pr['url']}")


def main(rels: str, path: str, token: str):
print('Generating changelog ...')
Expand All @@ -323,25 +316,20 @@ def main(rels: str, path: str, token: str):
changelog = {} # changelog dict
releases = {x.strip() for x in rels.split(',')}
projects = {f"{RELEASE} {rel}" for rel in releases}
no_project_prs = [] # list of merge pr w/o project

print('Processing pull requests ...')
process_changelog(resource_type=PULL_REQUESTS, changelog=changelog,
releases=releases, projects=projects,
no_project_prs=no_project_prs, token=token)
releases=releases, projects=projects, token=token)
print('Processing issues ...')
process_changelog(resource_type=ISSUES, changelog=changelog,
releases=releases, projects=projects,
no_project_prs=no_project_prs, token=token)
releases=releases, projects=projects, token=token)
# form doc
form_changelog(path=path, changelog=changelog)
except Exception as e: # pylint: disable=broad-except
print(e)
sys.exit(1)

print('Done.')
# post action
print_no_project_pr(no_project_prs=no_project_prs)


if __name__ == '__main__':
Expand Down

0 comments on commit edb7a67

Please sign in to comment.