python-utility-scripts 1.0.14__tar.gz → 1.0.15__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/PKG-INFO +1 -1
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/polarion/polarion_set_automated.py +28 -6
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/polarion/polarion_utils.py +37 -8
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/pyproject.toml +1 -1
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/LICENSE +0 -0
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/README.md +0 -0
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/__init__.py +0 -0
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/jira_utils/README.md +0 -0
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/jira_utils/__init__.py +0 -0
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/jira_utils/jira_information.py +0 -0
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/polarion/README.md +0 -0
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/polarion/__init__.py +0 -0
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/polarion/polarion_verify_tc_requirements.py +0 -0
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/unused_code/README.md +0 -0
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/unused_code/__init__.py +0 -0
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/unused_code/unused_code.py +0 -0
- {python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/utils.py +0 -0
|
@@ -20,12 +20,22 @@ def approve_tests(polarion_project_id: str, added_ids: list[str]) -> dict[str, l
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
def remove_approved_tests(
|
|
23
|
-
polarion_project_id: str,
|
|
23
|
+
polarion_project_id: str,
|
|
24
|
+
branch: str | None = None,
|
|
25
|
+
previous_commit: str | None = None,
|
|
26
|
+
current_commit: str | None = None,
|
|
27
|
+
added_ids: list[str] | None = None,
|
|
24
28
|
) -> dict[str, list[str]]:
|
|
25
29
|
removed_polarions = {}
|
|
26
30
|
added_ids = added_ids or []
|
|
27
31
|
if removed_ids := set(
|
|
28
|
-
find_polarion_ids(
|
|
32
|
+
find_polarion_ids(
|
|
33
|
+
polarion_project_id=polarion_project_id,
|
|
34
|
+
string_to_match="removed",
|
|
35
|
+
branch=branch,
|
|
36
|
+
previous_commit=previous_commit,
|
|
37
|
+
current_commit=current_commit,
|
|
38
|
+
)
|
|
29
39
|
) - set(added_ids):
|
|
30
40
|
LOGGER.info(f"Following polarion ids were removed: {removed_ids}")
|
|
31
41
|
removed_polarions = update_polarion_ids(
|
|
@@ -43,9 +53,12 @@ def remove_approved_tests(
|
|
|
43
53
|
default=os.path.expanduser("~/.config/python-utility-scripts/config.yaml"),
|
|
44
54
|
)
|
|
45
55
|
@click.option("--project-id", "-p", help="Provide the polarion project id")
|
|
46
|
-
@click.option("--
|
|
56
|
+
@click.option("--previous-commit", "-p", help="Provide previous-commit to compare against", required=True)
|
|
57
|
+
@click.option("--current-commit", "-c", help="Provide current-commit to compare with", required=True)
|
|
47
58
|
@click.option("--verbose", default=False, is_flag=True)
|
|
48
|
-
def polarion_approve_automate(
|
|
59
|
+
def polarion_approve_automate(
|
|
60
|
+
config_file_path: str, project_id: str, previous_commit: str, current_commit: str, verbose: bool
|
|
61
|
+
) -> None:
|
|
49
62
|
if verbose:
|
|
50
63
|
LOGGER.setLevel(logging.DEBUG)
|
|
51
64
|
# since the utilities are in apps.polarion.polarion_utils, we need to change log level
|
|
@@ -56,12 +69,21 @@ def polarion_approve_automate(config_file_path: str, project_id: str, branch: st
|
|
|
56
69
|
config_file_path=config_file_path, util_name="pyutils-polarion-set-automated"
|
|
57
70
|
)
|
|
58
71
|
added_polarions = {}
|
|
59
|
-
if added_ids := find_polarion_ids(
|
|
72
|
+
if added_ids := find_polarion_ids(
|
|
73
|
+
polarion_project_id=polarion_project_id,
|
|
74
|
+
string_to_match="added",
|
|
75
|
+
branch=None,
|
|
76
|
+
previous_commit=previous_commit,
|
|
77
|
+
current_commit=current_commit,
|
|
78
|
+
):
|
|
60
79
|
added_polarions = approve_tests(polarion_project_id=polarion_project_id, added_ids=added_ids)
|
|
61
80
|
LOGGER.debug(f"Following polarion ids were marked automated and approved: {added_polarions.get('updated')}")
|
|
62
81
|
|
|
63
82
|
removed_polarions = remove_approved_tests(
|
|
64
|
-
polarion_project_id=polarion_project_id,
|
|
83
|
+
polarion_project_id=polarion_project_id,
|
|
84
|
+
added_ids=added_ids,
|
|
85
|
+
previous_commit=previous_commit,
|
|
86
|
+
current_commit=current_commit,
|
|
65
87
|
)
|
|
66
88
|
if removed_polarions.get("failed") or added_polarions.get("failed"):
|
|
67
89
|
error = "Following polarion ids updates failed."
|
{python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/polarion/polarion_utils.py
RENAMED
|
@@ -15,14 +15,28 @@ NOT_AUTOMATED = "notautomated"
|
|
|
15
15
|
APPROVED = "approved"
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
def git_diff(branch: str) -> str:
|
|
19
|
-
|
|
18
|
+
def git_diff(branch: str | None = None, current_commit: str | None = None, previous_commit: str | None = None) -> str:
|
|
19
|
+
if branch and (previous_commit or current_commit):
|
|
20
|
+
LOGGER.error("Branch and Previous or current commit are mutually exclusive command line options.")
|
|
21
|
+
sys.exit(1)
|
|
22
|
+
|
|
23
|
+
# Sanitize inputs to prevent command injection
|
|
24
|
+
if branch:
|
|
25
|
+
sanitized_branch = shlex.quote(branch)
|
|
26
|
+
diff_command = f"git diff {sanitized_branch} HEAD"
|
|
27
|
+
else:
|
|
28
|
+
sanitized_previous = shlex.quote(previous_commit) if previous_commit else ""
|
|
29
|
+
sanitized_current = shlex.quote(current_commit) if current_commit else ""
|
|
30
|
+
diff_command = f"git diff {sanitized_previous} {sanitized_current}"
|
|
31
|
+
data = subprocess.check_output(shlex.split(diff_command))
|
|
20
32
|
return data.decode()
|
|
21
33
|
|
|
22
34
|
|
|
23
|
-
def git_diff_lines(
|
|
35
|
+
def git_diff_lines(
|
|
36
|
+
branch: str | None = None, previous_commit: str | None = None, current_commit: str | None = None
|
|
37
|
+
) -> dict[str, list[str]]:
|
|
24
38
|
diff: dict[str, list[str]] = {}
|
|
25
|
-
for line in git_diff(branch=branch).splitlines():
|
|
39
|
+
for line in git_diff(branch=branch, current_commit=current_commit, previous_commit=previous_commit).splitlines():
|
|
26
40
|
LOGGER.debug(line)
|
|
27
41
|
if line.startswith("+"):
|
|
28
42
|
diff.setdefault("added", []).append(line)
|
|
@@ -43,7 +57,12 @@ def validate_polarion_requirements(
|
|
|
43
57
|
for _id in polarion_test_ids:
|
|
44
58
|
has_req = False
|
|
45
59
|
LOGGER.debug(f"Checking if {_id} verifies any requirement")
|
|
46
|
-
|
|
60
|
+
try:
|
|
61
|
+
tc = TestCase(project_id=polarion_project_id, work_item_id=_id)
|
|
62
|
+
except PyleroLibException:
|
|
63
|
+
LOGGER.error(f"{_id}: Test case not found.")
|
|
64
|
+
tests_with_missing_requirements.append(_id)
|
|
65
|
+
continue
|
|
47
66
|
for link in tc.linked_work_items:
|
|
48
67
|
try:
|
|
49
68
|
Requirement(project_id=polarion_project_id, work_item_id=link.work_item_id)
|
|
@@ -53,15 +72,25 @@ def validate_polarion_requirements(
|
|
|
53
72
|
continue
|
|
54
73
|
|
|
55
74
|
if not has_req:
|
|
56
|
-
LOGGER.error(f"{_id}:
|
|
75
|
+
LOGGER.error(f"{_id}: does not have associated requirement.")
|
|
57
76
|
tests_with_missing_requirements.append(_id)
|
|
58
77
|
return tests_with_missing_requirements
|
|
59
78
|
|
|
60
79
|
|
|
61
|
-
def find_polarion_ids(
|
|
80
|
+
def find_polarion_ids(
|
|
81
|
+
polarion_project_id: str,
|
|
82
|
+
string_to_match: str,
|
|
83
|
+
branch: str | None = None,
|
|
84
|
+
previous_commit: str | None = None,
|
|
85
|
+
current_commit: str | None = None,
|
|
86
|
+
) -> list[str]:
|
|
62
87
|
return re.findall(
|
|
63
88
|
rf"pytest.mark.polarion.*({polarion_project_id}-[0-9]+)",
|
|
64
|
-
"\n".join(
|
|
89
|
+
"\n".join(
|
|
90
|
+
git_diff_lines(branch=branch, previous_commit=previous_commit, current_commit=current_commit).get(
|
|
91
|
+
string_to_match, []
|
|
92
|
+
)
|
|
93
|
+
),
|
|
65
94
|
re.MULTILINE | re.IGNORECASE,
|
|
66
95
|
)
|
|
67
96
|
|
|
@@ -30,7 +30,7 @@ exclude = [".git", ".venv", ".mypy_cache", ".tox", "__pycache__"]
|
|
|
30
30
|
|
|
31
31
|
[tool.poetry]
|
|
32
32
|
name = "python-utility-scripts"
|
|
33
|
-
version = "1.0.
|
|
33
|
+
version = "1.0.15"
|
|
34
34
|
description = "Python utility scripts"
|
|
35
35
|
authors = ["dbasunag <dbasunag@redhat.com>"]
|
|
36
36
|
license = "Apache License 2.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/jira_utils/jira_information.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/unused_code/__init__.py
RENAMED
|
File without changes
|
{python_utility_scripts-1.0.14 → python_utility_scripts-1.0.15}/apps/unused_code/unused_code.py
RENAMED
|
File without changes
|
|
File without changes
|