From 8d242e631d5a94f0ab8ff888dbaee37948d2e519 Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Fri, 1 Nov 2024 08:47:22 -0400 Subject: [PATCH 1/3] =?UTF-8?q?[SL-ONLY]=20First=20version=20of=20the=20sc?= =?UTF-8?q?ript=20to=20parse=20git=20branches=20for=20our=20commits=20TAG?= =?UTF-8?q?=E2=80=A6=20(#83)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michael Rupp <95718139+mykrupp@users.noreply.github.com> --- scripts/tools/silabs/retrieve_sl_commits.py | 68 +++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 scripts/tools/silabs/retrieve_sl_commits.py diff --git a/scripts/tools/silabs/retrieve_sl_commits.py b/scripts/tools/silabs/retrieve_sl_commits.py new file mode 100644 index 0000000000..6aa7d7c6b8 --- /dev/null +++ b/scripts/tools/silabs/retrieve_sl_commits.py @@ -0,0 +1,68 @@ +#! /usr/bin/python3 +import subprocess +import argparse +from argparse import RawTextHelpFormatter + +def get_git_log(start_sha, end_sha, prefixes): + try: + # Run the git log command with output format -- + result = subprocess.run( + ['git', 'log', '--pretty=format:%H -- %s %s', f'{start_sha}..{end_sha}'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + check=True, + text=True + ) + + # Split the result into lines + log_lines = result.stdout.split('\n') + + # Initialize a dictionary to hold commits by prefix + commits_by_prefix = {prefix: [] for prefix in prefixes} + + # Filter and group commits based on the prefixes + for line in log_lines: + for prefix in prefixes: + if prefix in line: + commits_by_prefix[prefix].append(line) + break + + return commits_by_prefix + + except subprocess.CalledProcessError as e: + print(f"Error running git log: {e}") + return {} + +def main(): + parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=""" + This script will parse git logs for our silabs prefixes ([SL-UP], [SL-TEMP], [SL-ONLY] or [CSA-CP]) between the commit SHAs provided in parameters + on the current git branch. + It will then output, per prefix, the commit sha and commit Title in the following format) + [PREFIX] commits: + <full_commit_sha> -- <Commit_Title> + """, + epilog= """ + Post result developer actions: + commits grouped under [SL-UP] shall be upstream the CSA master. + commits grouped under [SL-ONLY] shall be cherry-picked to matter_sdk main branch. + commits grouped under [SL-TEMP] must be revised. Are they still required, are they needed on main or for the next release. If they are, they need to be cherry-picked. + commits grouped under [CSA-CP] are purely informative. They already exist in CSA master and will automatically be brought to main or the new release branch through CSA master merges. + """) + parser.add_argument('start_sha', type=str, help='The starting commit SHA') + parser.add_argument('end_sha', type=str, help='The ending commit SHA') + + args = parser.parse_args() + + start_sha = args.start_sha + end_sha = args.end_sha + prefixes = ["[SL-UP]", "[SL-TEMP]", "[SL-ONLY]", "[CSA-CP]"] + + commits_by_prefix = get_git_log(start_sha, end_sha, prefixes) + for prefix, commits in commits_by_prefix.items(): + print(f"{prefix} commits:") + for commit in commits: + print(commit) + print() + +if __name__ == "__main__": + main() \ No newline at end of file From 2ce7599703a6aaf43f1e997cc73f2b6fa262f024 Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:30:25 -0500 Subject: [PATCH 2/3] add the Author to the git log output --- scripts/tools/silabs/retrieve_sl_commits.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tools/silabs/retrieve_sl_commits.py b/scripts/tools/silabs/retrieve_sl_commits.py index 6aa7d7c6b8..1d11c0cbaa 100644 --- a/scripts/tools/silabs/retrieve_sl_commits.py +++ b/scripts/tools/silabs/retrieve_sl_commits.py @@ -5,9 +5,9 @@ def get_git_log(start_sha, end_sha, prefixes): try: - # Run the git log command with output format <commit hash> -- <Title> + # Run the git log command with output format <Commit short hash> | <Author> | <Title> result = subprocess.run( - ['git', 'log', '--pretty=format:%H -- %s %s', f'{start_sha}..{end_sha}'], + ['git', 'log', '--pretty=format:%h | %an | %s %s', f'{start_sha}..{end_sha}'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, From dbdd162c81cb0a751a7b919c1efe58939c3f6225 Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Wed, 20 Nov 2024 11:21:22 -0500 Subject: [PATCH 3/3] Update scripts/tools/silabs/retrieve_sl_commits.py Co-authored-by: Ricardo Casallas <77841255+rcasallas-silabs@users.noreply.github.com> --- scripts/tools/silabs/retrieve_sl_commits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tools/silabs/retrieve_sl_commits.py b/scripts/tools/silabs/retrieve_sl_commits.py index 1d11c0cbaa..a21e2a8009 100644 --- a/scripts/tools/silabs/retrieve_sl_commits.py +++ b/scripts/tools/silabs/retrieve_sl_commits.py @@ -15,7 +15,7 @@ def get_git_log(start_sha, end_sha, prefixes): ) # Split the result into lines - log_lines = result.stdout.split('\n') + log_lines = result.stdout.splitlines() # Initialize a dictionary to hold commits by prefix commits_by_prefix = {prefix: [] for prefix in prefixes}