From 9012eff17d97ae724588010f4f06d75d0e794898 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Tue, 17 Oct 2023 01:52:51 +0530 Subject: [PATCH 01/13] modify release-notes script Signed-off-by: Ansh Goyal --- scripts/release-notes.py | 70 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/scripts/release-notes.py b/scripts/release-notes.py index 1356f6d510c..173fd81781a 100755 --- a/scripts/release-notes.py +++ b/scripts/release-notes.py @@ -43,6 +43,17 @@ def num_commits_since_prev_tag(token, base_url): print(f"There are {num_commits} new commits since {prev_release_tag}") return num_commits +categories = { + 'CI': 'changelog:ci', + 'Feature': 'changelog:feature', + } + +def categorize_pull_request(label): + for category, prefix in categories.items(): + if label.startswith(prefix): + return category + return 'Other' # Default category if no matching prefix is found + def main(token, repo, num_commits, exclude_dependabot): accept_header = "application/vnd.github.groot-preview+json" @@ -66,6 +77,10 @@ def main(token, repo, num_commits, exclude_dependabot): print('Retrieved', len(commits), 'commits') # Load PR for each commit and print summary + print("Processing...") + category_results = {category: [] for category in categories.keys()} + other_results = [] + for commit in commits: sha = commit['sha'] author = commit['author']['login'] @@ -88,17 +103,64 @@ def main(token, repo, num_commits, exclude_dependabot): if not pulls: short_sha = sha[:7] commit_url = commit['html_url'] - print(f'* {msg} ([@{author}]({author_url}) in [{short_sha}]({commit_url}))') + # Check if the commit has changelog label + commit_labels = get_pull_request_labels(token, args.repo, pull_id) + changelog_labels = [label for label in commit_labels if label.startswith('changelog:')] + + category = 'Other' + if changelog_labels: + category = categorize_pull_request(changelog_labels[0]) + + result = f'* {msg} ([@{author}]({author_url}) in [{short_sha}]({commit_url}))' + if category == 'Other': + other_results.append(result) + else: + category_results[category].append(result) continue pull = pulls[0] pull_id = pull['number'] pull_url = pull['html_url'] msg = msg.replace(f'(#{pull_id})', '').strip() - print(f'* {msg} ([@{author}]({author_url}) in [#{pull_id}]({pull_url}))') - if skipped_dependabot: - print(f"\n(Skipped {skipped_dependabot} dependabot commit{'' if skipped_dependabot == 1 else 's'})") + # Check if the pull request has changelog label + pull_labels = get_pull_request_labels(token, args.repo, pull_id) + changelog_labels = [label for label in pull_labels if label.startswith('changelog:')] + + category = 'Other' + if changelog_labels: + category = categorize_pull_request(changelog_labels[0]) + + result = f'* {msg} ([@{author}]({author_url}) in [#{pull_id}]({pull_url}))' + if category == 'Other': + other_results.append(result) + else: + category_results[category].append(result) + + # Print categorized pull requests + for category, results in category_results.items(): + if results: + print(f'{category}:') + for result in results: + print(result) + print() + + # Print pull requests in the 'Other' category + if other_results: + print('Other:') + for result in other_results: + print(result) + + if skipped_dependabot: + print(f"\n(Skipped {skipped_dependabot} dependabot commit{'' if skipped_dependabot == 1 else 's'})") + + +def get_pull_request_labels(token, repo, pull_number): + labels_url = f"https://api.github.com/repos/jaegertracing/{repo}/issues/{pull_number}/labels" + req = Request(labels_url) + req.add_header('Authorization', f'token {token}') + labels = json.loads(urlopen(req).read()) + return [label['name'] for label in labels] if __name__ == "__main__": From 51472830913b6969059d00f6cc73d8333c1720da Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Tue, 17 Oct 2023 02:22:43 +0530 Subject: [PATCH 02/13] add markdown and other labels Signed-off-by: Ansh Goyal --- scripts/release-notes.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/release-notes.py b/scripts/release-notes.py index 173fd81781a..1423b8967cc 100755 --- a/scripts/release-notes.py +++ b/scripts/release-notes.py @@ -44,8 +44,11 @@ def num_commits_since_prev_tag(token, base_url): return num_commits categories = { - 'CI': 'changelog:ci', - 'Feature': 'changelog:feature', + '#### ⛔ Breaking Changes': 'changelog:breaking-change', + '#### New Features': 'changelog:new-feature', + '#### Bug fixes, Minor Improvements': 'changelog:bugfix-or-minor-feature', + '#### 🚧 Experimental Features': 'changelog:exprimental', + '#### CI Improvements': 'changelog:ci', } def categorize_pull_request(label): From 4f3e6cc7951ff7333abc6e67d07bdc9b83aba07b Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Tue, 17 Oct 2023 02:47:58 +0530 Subject: [PATCH 03/13] add skip and test | change to array Signed-off-by: Ansh Goyal --- scripts/gt.txt | 1 + scripts/release-notes.py | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 scripts/gt.txt diff --git a/scripts/gt.txt b/scripts/gt.txt new file mode 100644 index 00000000000..d277572767f --- /dev/null +++ b/scripts/gt.txt @@ -0,0 +1 @@ +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 \ No newline at end of file diff --git a/scripts/release-notes.py b/scripts/release-notes.py index 1423b8967cc..9a2792b017d 100755 --- a/scripts/release-notes.py +++ b/scripts/release-notes.py @@ -43,13 +43,15 @@ def num_commits_since_prev_tag(token, base_url): print(f"There are {num_commits} new commits since {prev_release_tag}") return num_commits -categories = { - '#### ⛔ Breaking Changes': 'changelog:breaking-change', - '#### New Features': 'changelog:new-feature', - '#### Bug fixes, Minor Improvements': 'changelog:bugfix-or-minor-feature', - '#### 🚧 Experimental Features': 'changelog:exprimental', - '#### CI Improvements': 'changelog:ci', - } +categories = [ + {'title': '#### ⛔ Breaking Changes', 'label': 'changelog:breaking-change'}, + {'title': '#### New Features', 'label': 'changelog:new-feature'}, + {'title': '#### Bug fixes, Minor Improvements', 'label': 'changelog:bugfix-or-minor-feature'}, + {'title': '#### 🚧 Experimental Features', 'label': 'changelog:exprimental'}, + {'title': '#### CI Improvements', 'label': 'changelog:ci'}, + {'title': '', 'label': 'changelog:test'}, + {'title': '', 'label': 'changelog:skip'} +] def categorize_pull_request(label): for category, prefix in categories.items(): @@ -81,7 +83,7 @@ def main(token, repo, num_commits, exclude_dependabot): # Load PR for each commit and print summary print("Processing...") - category_results = {category: [] for category in categories.keys()} + category_results = {category['title']: [] for category in categories} other_results = [] for commit in commits: @@ -112,7 +114,10 @@ def main(token, repo, num_commits, exclude_dependabot): category = 'Other' if changelog_labels: - category = categorize_pull_request(changelog_labels[0]) + for cat in categories: + if changelog_labels[0].startswith(cat['label']): + category = cat['title'] + break result = f'* {msg} ([@{author}]({author_url}) in [{short_sha}]({commit_url}))' if category == 'Other': @@ -132,7 +137,10 @@ def main(token, repo, num_commits, exclude_dependabot): category = 'Other' if changelog_labels: - category = categorize_pull_request(changelog_labels[0]) + for cat in categories: + if changelog_labels[0].startswith(cat['label']): + category = cat['title'] + break result = f'* {msg} ([@{author}]({author_url}) in [#{pull_id}]({pull_url}))' if category == 'Other': @@ -142,7 +150,7 @@ def main(token, repo, num_commits, exclude_dependabot): # Print categorized pull requests for category, results in category_results.items(): - if results: + if results and category: print(f'{category}:') for result in results: print(result) From a17deac23730cff72642bb1d0ab26029ea70700b Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Tue, 17 Oct 2023 02:48:12 +0530 Subject: [PATCH 04/13] add skip and test | change to array Signed-off-by: Ansh Goyal --- scripts/gt.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 scripts/gt.txt diff --git a/scripts/gt.txt b/scripts/gt.txt deleted file mode 100644 index d277572767f..00000000000 --- a/scripts/gt.txt +++ /dev/null @@ -1 +0,0 @@ -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 \ No newline at end of file From 353e023e8efd41fae1157f795c5db2270f816105 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Tue, 17 Oct 2023 02:59:17 +0530 Subject: [PATCH 05/13] add #### to Other title Signed-off-by: Ansh Goyal --- scripts/release-notes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release-notes.py b/scripts/release-notes.py index 9a2792b017d..8c70d6a45f9 100755 --- a/scripts/release-notes.py +++ b/scripts/release-notes.py @@ -158,7 +158,7 @@ def main(token, repo, num_commits, exclude_dependabot): # Print pull requests in the 'Other' category if other_results: - print('Other:') + print('#### Other:') for result in other_results: print(result) From e37c3dfd6545ca65236049e4252a0161627729fa Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Tue, 17 Oct 2023 08:51:05 +0530 Subject: [PATCH 06/13] make changes Signed-off-by: Ansh Goyal --- scripts/release-notes.py | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/scripts/release-notes.py b/scripts/release-notes.py index 8c70d6a45f9..5aa755eea75 100755 --- a/scripts/release-notes.py +++ b/scripts/release-notes.py @@ -43,21 +43,22 @@ def num_commits_since_prev_tag(token, base_url): print(f"There are {num_commits} new commits since {prev_release_tag}") return num_commits +UNCATTEGORIZED = 'Uncategorized' categories = [ {'title': '#### ⛔ Breaking Changes', 'label': 'changelog:breaking-change'}, {'title': '#### New Features', 'label': 'changelog:new-feature'}, {'title': '#### Bug fixes, Minor Improvements', 'label': 'changelog:bugfix-or-minor-feature'}, {'title': '#### 🚧 Experimental Features', 'label': 'changelog:exprimental'}, {'title': '#### CI Improvements', 'label': 'changelog:ci'}, - {'title': '', 'label': 'changelog:test'}, - {'title': '', 'label': 'changelog:skip'} + {'title': None, 'label': 'changelog:test'}, + {'title': None, 'label': 'changelog:skip'} ] def categorize_pull_request(label): for category, prefix in categories.items(): if label.startswith(prefix): return category - return 'Other' # Default category if no matching prefix is found + return UNCATTEGORIZED # Default category if no matching prefix is found def main(token, repo, num_commits, exclude_dependabot): @@ -108,22 +109,9 @@ def main(token, repo, num_commits, exclude_dependabot): if not pulls: short_sha = sha[:7] commit_url = commit['html_url'] - # Check if the commit has changelog label - commit_labels = get_pull_request_labels(token, args.repo, pull_id) - changelog_labels = [label for label in commit_labels if label.startswith('changelog:')] - - category = 'Other' - if changelog_labels: - for cat in categories: - if changelog_labels[0].startswith(cat['label']): - category = cat['title'] - break result = f'* {msg} ([@{author}]({author_url}) in [{short_sha}]({commit_url}))' - if category == 'Other': - other_results.append(result) - else: - category_results[category].append(result) + other_results.append(result) continue pull = pulls[0] @@ -135,7 +123,7 @@ def main(token, repo, num_commits, exclude_dependabot): pull_labels = get_pull_request_labels(token, args.repo, pull_id) changelog_labels = [label for label in pull_labels if label.startswith('changelog:')] - category = 'Other' + category = UNCATTEGORIZED if changelog_labels: for cat in categories: if changelog_labels[0].startswith(cat['label']): @@ -143,7 +131,7 @@ def main(token, repo, num_commits, exclude_dependabot): break result = f'* {msg} ([@{author}]({author_url}) in [#{pull_id}]({pull_url}))' - if category == 'Other': + if category == UNCATTEGORIZED: other_results.append(result) else: category_results[category].append(result) @@ -156,9 +144,9 @@ def main(token, repo, num_commits, exclude_dependabot): print(result) print() - # Print pull requests in the 'Other' category + # Print pull requests in the 'UNCATTEGORIZED' category if other_results: - print('#### Other:') + print(f'#### {UNCATTEGORIZED}:') for result in other_results: print(result) From a1ca8bdf9c8a1d275a86363f23ea36d84a79380e Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Tue, 17 Oct 2023 08:58:08 +0530 Subject: [PATCH 07/13] fix indtn Signed-off-by: Ansh Goyal --- scripts/release-notes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release-notes.py b/scripts/release-notes.py index 5aa755eea75..5d619c190e0 100755 --- a/scripts/release-notes.py +++ b/scripts/release-notes.py @@ -150,7 +150,7 @@ def main(token, repo, num_commits, exclude_dependabot): for result in other_results: print(result) - if skipped_dependabot: + if skipped_dependabot: print(f"\n(Skipped {skipped_dependabot} dependabot commit{'' if skipped_dependabot == 1 else 's'})") From 2df367006c8c9e2c0e8999e97094d191a9520876 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Tue, 17 Oct 2023 11:44:30 +0530 Subject: [PATCH 08/13] add multiple label support Signed-off-by: Ansh Goyal --- scripts/release-notes.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/scripts/release-notes.py b/scripts/release-notes.py index 5d619c190e0..37ba4c02b25 100755 --- a/scripts/release-notes.py +++ b/scripts/release-notes.py @@ -83,9 +83,9 @@ def main(token, repo, num_commits, exclude_dependabot): print('Retrieved', len(commits), 'commits') # Load PR for each commit and print summary - print("Processing...") category_results = {category['title']: [] for category in categories} other_results = [] + commits_with_multiple_labels = [] for commit in commits: sha = commit['sha'] @@ -123,6 +123,11 @@ def main(token, repo, num_commits, exclude_dependabot): pull_labels = get_pull_request_labels(token, args.repo, pull_id) changelog_labels = [label for label in pull_labels if label.startswith('changelog:')] + # Handle multiple changelog labels + if len(changelog_labels) > 1: + commits_with_multiple_labels.append((sha, pull_id, changelog_labels)) + continue + category = UNCATTEGORIZED if changelog_labels: for cat in categories: @@ -139,7 +144,7 @@ def main(token, repo, num_commits, exclude_dependabot): # Print categorized pull requests for category, results in category_results.items(): if results and category: - print(f'{category}:') + print(f'\n{category}:') for result in results: print(result) print() @@ -150,8 +155,16 @@ def main(token, repo, num_commits, exclude_dependabot): for result in other_results: print(result) + # Print warnings for commits with more than one changelog label + if commits_with_multiple_labels: + print("\nWarnings: Commits with more than one changelog label found. Please fix them:\n") + for sha, pull_id, labels in commits_with_multiple_labels: + pr_url = f"https://github.com/jaegertracing/{repo}/pull/{pull_id}" + print(f"Commit {sha} associated with multiple changelog labels: {', '.join(labels)}") + print(f"Pull Request URL: {pr_url}") + if skipped_dependabot: - print(f"\n(Skipped {skipped_dependabot} dependabot commit{'' if skipped_dependabot == 1 else 's'})") + print(f"\n(Skipped {skipped_dependabot} dependabot commit{'' if skipped_dependabot == 1 else 's'})") def get_pull_request_labels(token, repo, pull_number): From eb0102b1bb446fc7fdf28fd0056f740fed136c18 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Tue, 17 Oct 2023 11:49:52 +0530 Subject: [PATCH 09/13] fix newline Signed-off-by: Ansh Goyal --- scripts/gt.txt | 1 + scripts/release-notes.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 scripts/gt.txt diff --git a/scripts/gt.txt b/scripts/gt.txt new file mode 100644 index 00000000000..873b4f02e6f --- /dev/null +++ b/scripts/gt.txt @@ -0,0 +1 @@ +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 \ No newline at end of file diff --git a/scripts/release-notes.py b/scripts/release-notes.py index 37ba4c02b25..70469a9a2bc 100755 --- a/scripts/release-notes.py +++ b/scripts/release-notes.py @@ -142,9 +142,10 @@ def main(token, repo, num_commits, exclude_dependabot): category_results[category].append(result) # Print categorized pull requests + print() for category, results in category_results.items(): if results and category: - print(f'\n{category}:') + print(f'{category}:') for result in results: print(result) print() From e24b80b2ec6c41a83555360d7c7266df22b63bc8 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Tue, 17 Oct 2023 11:49:58 +0530 Subject: [PATCH 10/13] fix newline Signed-off-by: Ansh Goyal --- scripts/gt.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 scripts/gt.txt diff --git a/scripts/gt.txt b/scripts/gt.txt deleted file mode 100644 index 873b4f02e6f..00000000000 --- a/scripts/gt.txt +++ /dev/null @@ -1 +0,0 @@ -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 \ No newline at end of file From 6a3edd1f96244f4890f0907605d9e6e2a3dea13b Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Tue, 17 Oct 2023 12:06:44 +0530 Subject: [PATCH 11/13] fix newline Signed-off-by: Ansh Goyal --- scripts/release-notes.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/release-notes.py b/scripts/release-notes.py index 70469a9a2bc..ea6a7039b2d 100755 --- a/scripts/release-notes.py +++ b/scripts/release-notes.py @@ -162,10 +162,12 @@ def main(token, repo, num_commits, exclude_dependabot): for sha, pull_id, labels in commits_with_multiple_labels: pr_url = f"https://github.com/jaegertracing/{repo}/pull/{pull_id}" print(f"Commit {sha} associated with multiple changelog labels: {', '.join(labels)}") - print(f"Pull Request URL: {pr_url}") + print(f"Pull Request URL: {pr_url}\n") if skipped_dependabot: - print(f"\n(Skipped {skipped_dependabot} dependabot commit{'' if skipped_dependabot == 1 else 's'})") + if not commits_with_multiple_labels: + print() + print(f"(Skipped {skipped_dependabot} dependabot commit{'' if skipped_dependabot == 1 else 's'})") def get_pull_request_labels(token, repo, pull_number): From de15d68effcaae0aa6ccf3619536856fbf18d5a1 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Tue, 17 Oct 2023 23:33:55 +0530 Subject: [PATCH 12/13] make improvements Signed-off-by: Ansh Goyal --- scripts/release-notes.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/release-notes.py b/scripts/release-notes.py index ea6a7039b2d..06162eb6ee4 100755 --- a/scripts/release-notes.py +++ b/scripts/release-notes.py @@ -46,10 +46,10 @@ def num_commits_since_prev_tag(token, base_url): UNCATTEGORIZED = 'Uncategorized' categories = [ {'title': '#### ⛔ Breaking Changes', 'label': 'changelog:breaking-change'}, - {'title': '#### New Features', 'label': 'changelog:new-feature'}, - {'title': '#### Bug fixes, Minor Improvements', 'label': 'changelog:bugfix-or-minor-feature'}, + {'title': '#### ✨ New Features', 'label': 'changelog:new-feature'}, + {'title': '#### 🐞 Bug fixes, Minor Improvements', 'label': 'changelog:bugfix-or-minor-feature'}, {'title': '#### 🚧 Experimental Features', 'label': 'changelog:exprimental'}, - {'title': '#### CI Improvements', 'label': 'changelog:ci'}, + {'title': '#### 👷 CI Improvements', 'label': 'changelog:ci'}, {'title': None, 'label': 'changelog:test'}, {'title': None, 'label': 'changelog:skip'} ] @@ -155,18 +155,18 @@ def main(token, repo, num_commits, exclude_dependabot): print(f'#### {UNCATTEGORIZED}:') for result in other_results: print(result) + print() # Print warnings for commits with more than one changelog label if commits_with_multiple_labels: - print("\nWarnings: Commits with more than one changelog label found. Please fix them:\n") + print("Warnings: Commits with more than one changelog label found. Please fix them:\n") for sha, pull_id, labels in commits_with_multiple_labels: pr_url = f"https://github.com/jaegertracing/{repo}/pull/{pull_id}" print(f"Commit {sha} associated with multiple changelog labels: {', '.join(labels)}") print(f"Pull Request URL: {pr_url}\n") + print() if skipped_dependabot: - if not commits_with_multiple_labels: - print() print(f"(Skipped {skipped_dependabot} dependabot commit{'' if skipped_dependabot == 1 else 's'})") From 7d1b17cfa99de9fb07c835908738142cdf0636d2 Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Wed, 18 Oct 2023 00:18:15 +0530 Subject: [PATCH 13/13] add newline after titles Signed-off-by: Ansh Goyal --- scripts/release-notes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/release-notes.py b/scripts/release-notes.py index 06162eb6ee4..4976fa58516 100755 --- a/scripts/release-notes.py +++ b/scripts/release-notes.py @@ -145,7 +145,7 @@ def main(token, repo, num_commits, exclude_dependabot): print() for category, results in category_results.items(): if results and category: - print(f'{category}:') + print(f'{category}:\n') for result in results: print(result) print()