Skip to content

Move getting commits by tags to separate function #220

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 1 commit into from
Feb 26, 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
115 changes: 60 additions & 55 deletions redis_benchmarks_specification/__cli__/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main():
generate_stats_cli_command_logic(args, project_name, project_version)


def get_commits(args, repo):
def get_commits_by_branch(args, repo):
total_commits = 0
commits = []
for commit in repo.iter_commits():
Expand All @@ -73,12 +73,68 @@ def get_commits(args, repo):
"git_hash": commit.hexsha,
"git_branch": repo.active_branch.name,
"commit_summary": commit.summary,
"commit_datetime": commit_datetime,
"commit_datetime": str(commit_datetime),
}
)
return commits, total_commits


def get_commits_by_tags(args, repo):
commits = []
tags_regexp = args.tags_regexp
if tags_regexp == ".*":
logging.info(
"Acception all tags that follow semver between the timeframe. If you need further filter specify a regular expression via --tags-regexp"
)
else:
logging.info(
"Filtering all tags via a regular expression: {}".format(tags_regexp)
)
tags_regex_string = re.compile(tags_regexp)

tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime)
for tag in tags:
if (
args.from_date
<= datetime.datetime.utcfromtimestamp(
tag.commit.committed_datetime.timestamp()
)
<= args.to_date
):
try:
version.Version(tag.name)
match_obj = re.search(tags_regex_string, tag.name)
if match_obj is None:
logging.info(
"Skipping {} given it does not match regex {}".format(
tag.name, tags_regexp
)
)
else:
git_version = tag.name
commit_datetime = str(tag.commit.committed_datetime)
print(
"Commit summary: {}. Extract semver: {}".format(
tag.commit.summary, git_version
)
)
commits.append(
{
"git_hash": tag.commit.hexsha,
"git_version": git_version,
"commit_summary": tag.commit.summary,
"commit_datetime": commit_datetime,
}
)
except packaging.version.InvalidVersion:
logging.info(
"Ignoring tag {} given we were not able to extract commit or version info from it.".format(
tag.name
)
)
pass
return commits

def get_repo(args):
redisDirPath = args.redis_repo
cleanUp = False
Expand Down Expand Up @@ -128,61 +184,10 @@ def trigger_tests_cli_command_logic(args, project_name, project_version):

commits = []
if args.use_branch:
commits, total_commits = get_commits(args, repo)

commits, total_commits = get_commits_by_branch(args, repo)
if args.use_tags:
tags_regexp = args.tags_regexp
if tags_regexp == ".*":
logging.info(
"Acception all tags that follow semver between the timeframe. If you need further filter specify a regular expression via --tags-regexp"
)
else:
logging.info(
"Filtering all tags via a regular expression: {}".format(tags_regexp)
)
tags_regex_string = re.compile(tags_regexp)
commtis = get_commits_by_tags(args, repo)

tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime)
for tag in tags:
if (
args.from_date
<= datetime.datetime.utcfromtimestamp(
tag.commit.committed_datetime.timestamp()
)
<= args.to_date
):
try:
version.Version(tag.name)
match_obj = re.search(tags_regex_string, tag.name)
if match_obj is None:
logging.info(
"Skipping {} given it does not match regex {}".format(
tag.name, tags_regexp
)
)
else:
git_version = tag.name
commit_datetime = str(tag.commit.committed_datetime)
print(
"Commit summary: {}. Extract semver: {}".format(
tag.commit.summary, git_version
)
)
commits.append(
{
"git_hash": tag.commit.hexsha,
"git_version": git_version,
"commit_summary": tag.commit.summary,
"commit_datetime": commit_datetime,
}
)
except packaging.version.InvalidVersion:
logging.info(
"Ignoring tag {} given we were not able to extract commit or version info from it.".format(
tag.name
)
)
pass
by_description = "n/a"
if args.use_branch:
by_description = "from branch {}".format(repo.active_branch.name)
Expand Down
15 changes: 11 additions & 4 deletions utils/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import git

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


def test_run_local_command_logic_oss_cluster():
Expand Down Expand Up @@ -45,16 +45,23 @@ def test_run_local_command_logic_oss_cluster():

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

args = parser.parse_args(args=[])
redisDirPath, cleanUp = get_repo(args)
repo = git.Repo(redisDirPath)

args = parser.parse_args(args=["--use-branch", "--from-date", "2023-02-11"])
try:
get_commits_by_branch(args, repo)
except SystemExit as e:
assert e.code == 0

args = parser.parse_args(args=["--use-branch", "--from-date", "2023-02-11"])
try:
get_commits(args, repo)
get_commits_by_tags(args, repo)
except SystemExit as e:
assert e.code == 0