Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 209f97a

Browse files
committedOct 30, 2024·
First version of the script to parse git branches for our commits TAGS/prefix
1 parent d22a2e2 commit 209f97a

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#! /usr/bin/python3
2+
import subprocess
3+
import argparse
4+
from argparse import RawTextHelpFormatter
5+
6+
def get_git_log(start_sha, end_sha, prefixes):
7+
try:
8+
# Run the git log command with output format <commit hash> -- <Title>
9+
result = subprocess.run(
10+
['git', 'log', '--pretty=format:%H -- %s %s', f'{start_sha}..{end_sha}'],
11+
stdout=subprocess.PIPE,
12+
stderr=subprocess.PIPE,
13+
check=True,
14+
text=True
15+
)
16+
17+
# Split the result into lines
18+
log_lines = result.stdout.split('\n')
19+
20+
# Initialize a dictionary to hold commits by prefix
21+
commits_by_prefix = {prefix: [] for prefix in prefixes}
22+
23+
# Filter and group commits based on the prefixes
24+
for line in log_lines:
25+
for prefix in prefixes:
26+
if prefix in line:
27+
commits_by_prefix[prefix].append(line)
28+
break
29+
30+
return commits_by_prefix
31+
32+
except subprocess.CalledProcessError as e:
33+
print(f"Error running git log: {e}")
34+
return {}
35+
36+
def main():
37+
parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description="""
38+
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
39+
on the current git branch.
40+
It will then output, per prefix, the commit sha and commit Title in the following format)
41+
[PREFIX] commits:
42+
<full_commit_sha> -- <Commit_Title>
43+
""",
44+
epilog= """
45+
Post result developer actions:
46+
commits grouped under [SL-UP] shall be upstream the CSA master.
47+
commits grouped under [SL-ONLY] shall be cherry-picked to matter_sdk main branch.
48+
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.
49+
commits grouped under [CSA-PR] 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.
50+
""")
51+
parser.add_argument('start_sha', type=str, help='The starting commit SHA')
52+
parser.add_argument('end_sha', type=str, help='The ending commit SHA')
53+
54+
args = parser.parse_args()
55+
56+
start_sha = args.start_sha
57+
end_sha = args.end_sha
58+
prefixes = ["[SL-UP]", "[SL-TEMP]", "[SL-ONLY]", "[CSA-CP]"]
59+
60+
commits_by_prefix = get_git_log(start_sha, end_sha, prefixes)
61+
for prefix, commits in commits_by_prefix.items():
62+
print(f"{prefix} commits:")
63+
for commit in commits:
64+
print(commit)
65+
print()
66+
67+
if __name__ == "__main__":
68+
main()

0 commit comments

Comments
 (0)
Please sign in to comment.