Skip to content

Commit f81d695

Browse files
authored
Update timestamp conversion in client (#211)
* Update timestamp conversion in client Reverting of str converting for timestamp to avoid error 'str object has no attribute timestamp' Resolves: #209 * Refactored client, added test for get_commits * Reformatted cli.py with 'black' formatter
1 parent c8233c2 commit f81d695

File tree

2 files changed

+64
-34
lines changed

2 files changed

+64
-34
lines changed

redis_benchmarks_specification/__cli__/cli.py

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,31 @@ def main():
5555
generate_stats_cli_command_logic(args, project_name, project_version)
5656

5757

58-
def trigger_tests_cli_command_logic(args, project_name, project_version):
59-
logging.info(
60-
"Using: {project_name} {project_version}".format(
61-
project_name=project_name, project_version=project_version
62-
)
63-
)
64-
if args.use_branch is False and args.use_tags is False:
65-
logging.error("You must specify either --use-tags or --use-branch flag")
66-
sys.exit(1)
58+
def get_commits(args, repo):
59+
total_commits = 0
60+
commits = []
61+
for commit in repo.iter_commits():
62+
commit_datetime = commit.committed_datetime
63+
if (
64+
args.from_date
65+
<= datetime.datetime.utcfromtimestamp(commit_datetime.timestamp())
66+
<= args.to_date
67+
):
68+
if (args.last_n > 0 and total_commits < args.last_n) or args.last_n == -1:
69+
total_commits = total_commits + 1
70+
print(commit.summary)
71+
commits.append(
72+
{
73+
"git_hash": commit.hexsha,
74+
"git_branch": repo.active_branch.name,
75+
"commit_summary": commit.summary,
76+
"commit_datetime": commit_datetime,
77+
}
78+
)
79+
return commits, total_commits
80+
81+
82+
def get_repo(args):
6783
redisDirPath = args.redis_repo
6884
cleanUp = False
6985
if redisDirPath is None:
@@ -87,35 +103,33 @@ def trigger_tests_cli_command_logic(args, project_name, project_version):
87103
redisDirPath
88104
)
89105
)
106+
return redisDirPath, cleanUp
107+
108+
109+
def trigger_tests_cli_command_logic(args, project_name, project_version):
110+
logging.info(
111+
"Using: {project_name} {project_version}".format(
112+
project_name=project_name, project_version=project_version
113+
)
114+
)
115+
116+
if args.use_branch is False and args.use_tags is False:
117+
logging.error("You must specify either --use-tags or --use-branch flag")
118+
sys.exit(1)
119+
120+
redisDirPath, cleanUp = get_repo(args)
121+
repo = git.Repo(redisDirPath)
122+
90123
logging.info(
91124
"Using the following timeframe: from {} to {}".format(
92125
args.from_date, args.to_date
93126
)
94127
)
95-
repo = git.Repo(redisDirPath)
128+
96129
commits = []
97-
total_commits = 0
98130
if args.use_branch:
99-
for commit in repo.iter_commits():
100-
commit_datetime = str(commit.committed_datetime)
101-
if (
102-
args.from_date
103-
<= datetime.datetime.utcfromtimestamp(commit_datetime.timestamp())
104-
<= args.to_date
105-
):
106-
if (
107-
args.last_n > 0 and total_commits < args.last_n
108-
) or args.last_n == -1:
109-
total_commits = total_commits + 1
110-
print(commit.summary)
111-
commits.append(
112-
{
113-
"git_hash": commit.hexsha,
114-
"git_branch": repo.active_branch.name,
115-
"commit_summary": commit.summary,
116-
"commit_datetime": commit_datetime,
117-
}
118-
)
131+
commits, total_commits = get_commits(args, repo)
132+
119133
if args.use_tags:
120134
tags_regexp = args.tags_regexp
121135
if tags_regexp == ".*":
@@ -137,7 +151,6 @@ def trigger_tests_cli_command_logic(args, project_name, project_version):
137151
)
138152
<= args.to_date
139153
):
140-
141154
try:
142155
version.Version(tag.name)
143156
match_obj = re.search(tags_regex_string, tag.name)
@@ -221,7 +234,6 @@ def trigger_tests_cli_command_logic(args, project_name, project_version):
221234

222235
for rep in range(0, 1):
223236
for cdict in filtered_hash_commits:
224-
225237
(
226238
result,
227239
error_msg,

utils/tests/test_cli.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
#
66
import argparse
77
import os
8+
import git
89

910
from redis_benchmarks_specification.__cli__.args import spec_cli_args
10-
from redis_benchmarks_specification.__cli__.cli import trigger_tests_cli_command_logic
11+
from redis_benchmarks_specification.__cli__.cli import trigger_tests_cli_command_logic, get_commits, get_repo
1112

1213

1314
def test_run_local_command_logic_oss_cluster():
@@ -40,3 +41,20 @@ def test_run_local_command_logic_oss_cluster():
4041
trigger_tests_cli_command_logic(args, "tool", "v0")
4142
except SystemExit as e:
4243
assert e.code == 0
44+
45+
46+
def test_get_commits():
47+
parser = argparse.ArgumentParser(
48+
description="test",
49+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
50+
)
51+
parser = spec_cli_args(parser)
52+
args = parser.parse_args(args=[])
53+
54+
redisDirPath, cleanUp = get_repo(args)
55+
repo = git.Repo(redisDirPath)
56+
57+
try:
58+
get_commits(args, repo)
59+
except SystemExit as e:
60+
assert e.code == 0

0 commit comments

Comments
 (0)