Skip to content

Update timestamp conversion in client #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 45 additions & 33 deletions redis_benchmarks_specification/__cli__/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,31 @@ def main():
generate_stats_cli_command_logic(args, project_name, project_version)


def trigger_tests_cli_command_logic(args, project_name, project_version):
logging.info(
"Using: {project_name} {project_version}".format(
project_name=project_name, project_version=project_version
)
)
if args.use_branch is False and args.use_tags is False:
logging.error("You must specify either --use-tags or --use-branch flag")
sys.exit(1)
def get_commits(args, repo):
total_commits = 0
commits = []
for commit in repo.iter_commits():
commit_datetime = commit.committed_datetime
if (
args.from_date
<= datetime.datetime.utcfromtimestamp(commit_datetime.timestamp())
<= args.to_date
):
if (args.last_n > 0 and total_commits < args.last_n) or args.last_n == -1:
total_commits = total_commits + 1
print(commit.summary)
commits.append(
{
"git_hash": commit.hexsha,
"git_branch": repo.active_branch.name,
"commit_summary": commit.summary,
"commit_datetime": commit_datetime,
}
)
return commits, total_commits


def get_repo(args):
redisDirPath = args.redis_repo
cleanUp = False
if redisDirPath is None:
Expand All @@ -87,35 +103,33 @@ def trigger_tests_cli_command_logic(args, project_name, project_version):
redisDirPath
)
)
return redisDirPath, cleanUp


def trigger_tests_cli_command_logic(args, project_name, project_version):
logging.info(
"Using: {project_name} {project_version}".format(
project_name=project_name, project_version=project_version
)
)

if args.use_branch is False and args.use_tags is False:
logging.error("You must specify either --use-tags or --use-branch flag")
sys.exit(1)

redisDirPath, cleanUp = get_repo(args)
repo = git.Repo(redisDirPath)

logging.info(
"Using the following timeframe: from {} to {}".format(
args.from_date, args.to_date
)
)
repo = git.Repo(redisDirPath)

commits = []
total_commits = 0
if args.use_branch:
for commit in repo.iter_commits():
commit_datetime = str(commit.committed_datetime)
if (
args.from_date
<= datetime.datetime.utcfromtimestamp(commit_datetime.timestamp())
<= args.to_date
):
if (
args.last_n > 0 and total_commits < args.last_n
) or args.last_n == -1:
total_commits = total_commits + 1
print(commit.summary)
commits.append(
{
"git_hash": commit.hexsha,
"git_branch": repo.active_branch.name,
"commit_summary": commit.summary,
"commit_datetime": commit_datetime,
}
)
commits, total_commits = get_commits(args, repo)

if args.use_tags:
tags_regexp = args.tags_regexp
if tags_regexp == ".*":
Expand All @@ -137,7 +151,6 @@ def trigger_tests_cli_command_logic(args, project_name, project_version):
)
<= args.to_date
):

try:
version.Version(tag.name)
match_obj = re.search(tags_regex_string, tag.name)
Expand Down Expand Up @@ -221,7 +234,6 @@ def trigger_tests_cli_command_logic(args, project_name, project_version):

for rep in range(0, 1):
for cdict in filtered_hash_commits:

(
result,
error_msg,
Expand Down
20 changes: 19 additions & 1 deletion utils/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
#
import argparse
import os
import git

from redis_benchmarks_specification.__cli__.args import spec_cli_args
from redis_benchmarks_specification.__cli__.cli import trigger_tests_cli_command_logic
from redis_benchmarks_specification.__cli__.cli import trigger_tests_cli_command_logic, get_commits, get_repo


def test_run_local_command_logic_oss_cluster():
Expand Down Expand Up @@ -40,3 +41,20 @@ def test_run_local_command_logic_oss_cluster():
trigger_tests_cli_command_logic(args, "tool", "v0")
except SystemExit as e:
assert e.code == 0


def test_get_commits():
parser = argparse.ArgumentParser(
description="test",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser = spec_cli_args(parser)
args = parser.parse_args(args=[])

redisDirPath, cleanUp = get_repo(args)
repo = git.Repo(redisDirPath)

try:
get_commits(args, repo)
except SystemExit as e:
assert e.code == 0