Skip to content

Commit b63a28b

Browse files
authored
Move getting commits by tags to separate funciton (#220)
1 parent 6580afa commit b63a28b

File tree

2 files changed

+70
-58
lines changed

2 files changed

+70
-58
lines changed

redis_benchmarks_specification/__cli__/cli.py

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def main():
5555
generate_stats_cli_command_logic(args, project_name, project_version)
5656

5757

58-
def get_commits(args, repo):
58+
def get_commits_by_branch(args, repo):
5959
total_commits = 0
6060
commits = []
6161
for commit in repo.iter_commits():
@@ -79,6 +79,62 @@ def get_commits(args, repo):
7979
return commits, total_commits
8080

8181

82+
def get_commits_by_tags(args, repo):
83+
commits = []
84+
tags_regexp = args.tags_regexp
85+
if tags_regexp == ".*":
86+
logging.info(
87+
"Acception all tags that follow semver between the timeframe. If you need further filter specify a regular expression via --tags-regexp"
88+
)
89+
else:
90+
logging.info(
91+
"Filtering all tags via a regular expression: {}".format(tags_regexp)
92+
)
93+
tags_regex_string = re.compile(tags_regexp)
94+
95+
tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime)
96+
for tag in tags:
97+
if (
98+
args.from_date
99+
<= datetime.datetime.utcfromtimestamp(
100+
tag.commit.committed_datetime.timestamp()
101+
)
102+
<= args.to_date
103+
):
104+
try:
105+
version.Version(tag.name)
106+
match_obj = re.search(tags_regex_string, tag.name)
107+
if match_obj is None:
108+
logging.info(
109+
"Skipping {} given it does not match regex {}".format(
110+
tag.name, tags_regexp
111+
)
112+
)
113+
else:
114+
git_version = tag.name
115+
commit_datetime = str(tag.commit.committed_datetime)
116+
print(
117+
"Commit summary: {}. Extract semver: {}".format(
118+
tag.commit.summary, git_version
119+
)
120+
)
121+
commits.append(
122+
{
123+
"git_hash": tag.commit.hexsha,
124+
"git_version": git_version,
125+
"commit_summary": tag.commit.summary,
126+
"commit_datetime": commit_datetime,
127+
}
128+
)
129+
except packaging.version.InvalidVersion:
130+
logging.info(
131+
"Ignoring tag {} given we were not able to extract commit or version info from it.".format(
132+
tag.name
133+
)
134+
)
135+
pass
136+
return commits
137+
82138
def get_repo(args):
83139
redisDirPath = args.redis_repo
84140
cleanUp = False
@@ -128,61 +184,10 @@ def trigger_tests_cli_command_logic(args, project_name, project_version):
128184

129185
commits = []
130186
if args.use_branch:
131-
commits, total_commits = get_commits(args, repo)
132-
187+
commits, total_commits = get_commits_by_branch(args, repo)
133188
if args.use_tags:
134-
tags_regexp = args.tags_regexp
135-
if tags_regexp == ".*":
136-
logging.info(
137-
"Acception all tags that follow semver between the timeframe. If you need further filter specify a regular expression via --tags-regexp"
138-
)
139-
else:
140-
logging.info(
141-
"Filtering all tags via a regular expression: {}".format(tags_regexp)
142-
)
143-
tags_regex_string = re.compile(tags_regexp)
189+
commtis = get_commits_by_tags(args, repo)
144190

145-
tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime)
146-
for tag in tags:
147-
if (
148-
args.from_date
149-
<= datetime.datetime.utcfromtimestamp(
150-
tag.commit.committed_datetime.timestamp()
151-
)
152-
<= args.to_date
153-
):
154-
try:
155-
version.Version(tag.name)
156-
match_obj = re.search(tags_regex_string, tag.name)
157-
if match_obj is None:
158-
logging.info(
159-
"Skipping {} given it does not match regex {}".format(
160-
tag.name, tags_regexp
161-
)
162-
)
163-
else:
164-
git_version = tag.name
165-
commit_datetime = str(tag.commit.committed_datetime)
166-
print(
167-
"Commit summary: {}. Extract semver: {}".format(
168-
tag.commit.summary, git_version
169-
)
170-
)
171-
commits.append(
172-
{
173-
"git_hash": tag.commit.hexsha,
174-
"git_version": git_version,
175-
"commit_summary": tag.commit.summary,
176-
"commit_datetime": commit_datetime,
177-
}
178-
)
179-
except packaging.version.InvalidVersion:
180-
logging.info(
181-
"Ignoring tag {} given we were not able to extract commit or version info from it.".format(
182-
tag.name
183-
)
184-
)
185-
pass
186191
by_description = "n/a"
187192
if args.use_branch:
188193
by_description = "from branch {}".format(repo.active_branch.name)

utils/tests/test_cli.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import git
99

1010
from redis_benchmarks_specification.__cli__.args import spec_cli_args
11-
from redis_benchmarks_specification.__cli__.cli import trigger_tests_cli_command_logic, get_commits, get_repo
11+
from redis_benchmarks_specification.__cli__.cli import trigger_tests_cli_command_logic, get_commits_by_branch, get_commits_by_tags, get_repo
1212

1313

1414
def test_run_local_command_logic_oss_cluster():
@@ -45,16 +45,23 @@ def test_run_local_command_logic_oss_cluster():
4545

4646
def test_get_commits():
4747
parser = argparse.ArgumentParser(
48-
description="test",
48+
description="Get commits test",
4949
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
5050
)
5151
parser = spec_cli_args(parser)
52-
args = parser.parse_args(args=[])
5352

53+
args = parser.parse_args(args=[])
5454
redisDirPath, cleanUp = get_repo(args)
5555
repo = git.Repo(redisDirPath)
5656

57+
args = parser.parse_args(args=["--use-branch", "--from-date", "2023-02-11"])
58+
try:
59+
get_commits_by_branch(args, repo)
60+
except SystemExit as e:
61+
assert e.code == 0
62+
63+
args = parser.parse_args(args=["--use-branch", "--from-date", "2023-02-11"])
5764
try:
58-
get_commits(args, repo)
65+
get_commits_by_tags(args, repo)
5966
except SystemExit as e:
6067
assert e.code == 0

0 commit comments

Comments
 (0)