Skip to content

Commit 4a776f5

Browse files
committed
updates
1 parent 00ee630 commit 4a776f5

File tree

4 files changed

+76
-35
lines changed

4 files changed

+76
-35
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,24 @@ jobs:
137137
poetry-install-options: ""
138138
- name: "Run Tests"
139139
run: "poetry run invoke pytest"
140+
changelog:
141+
if: >
142+
contains(fromJson('["develop"]'), github.base_ref) &&
143+
(github.head_ref != 'main') && (!startsWith(github.head_ref, 'release'))
144+
runs-on: "ubuntu-22.04"
145+
steps:
146+
- name: "Check out repository code"
147+
uses: "actions/checkout@v4"
148+
with:
149+
fetch-depth: "0"
150+
- name: "Setup environment"
151+
uses: "networktocode/gh-action-setup-poetry-environment@v6"
152+
with:
153+
poetry-version: "1.8.5"
154+
- name: "Check for changelog entry"
155+
run: |
156+
git fetch --no-tags origin +refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}
157+
poetry run towncrier check --compare-with origin/${{ github.base_ref }}
140158
publish_gh:
141159
needs:
142160
- "pytest"

jdiff/utils/diff_helpers.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,8 @@ def fix_deepdiff_key_names(obj: Mapping) -> Dict:
6464
result = {} # type: Dict
6565
for key, value in obj.items():
6666
key_parts = re.findall(REGEX_PATTERN_RELEVANT_KEYS, key)
67-
if (
68-
not key_parts
69-
): # If key parts can't be find, keep original key so data is not lost.
70-
key_parts = [
71-
key.replace("root", "index_element")
72-
] # replace root from DeepDiff with more meaningful name.
67+
if not key_parts: # If key parts can't be find, keep original key so data is not lost.
68+
key_parts = [key.replace("root", "index_element")] # replace root from DeepDiff with more meaningful name.
7369
partial_res = group_value(key_parts, value)
7470
dict_merger(result, partial_res)
7571
return result
@@ -85,16 +81,10 @@ def group_value(tree_list: List, value: Dict) -> Dict:
8581
def dict_merger(original_dict: Dict, dict_to_merge: Dict):
8682
"""Function to merge a dictionary (dict_to_merge) recursively into the original_dict."""
8783
for key in dict_to_merge.keys():
88-
if (
89-
key in original_dict
90-
and isinstance(original_dict[key], dict)
91-
and isinstance(dict_to_merge[key], dict)
92-
):
84+
if key in original_dict and isinstance(original_dict[key], dict) and isinstance(dict_to_merge[key], dict):
9385
dict_merger(original_dict[key], dict_to_merge[key])
9486
elif key in original_dict.keys():
95-
original_dict[key + "_dup!"] = dict_to_merge[
96-
key
97-
] # avoid overwriting existing keys.
87+
original_dict[key + "_dup!"] = dict_to_merge[key] # avoid overwriting existing keys.
9888
else:
9989
original_dict[key] = dict_to_merge[key]
10090

@@ -132,24 +122,25 @@ def set_nested_value(data, keys, value):
132122
set_nested_value(data[keys[0]], keys[1:], value)
133123

134124

125+
# {'foo': {'bar-1': 'missing', 'bar-2': 'new'}}
135126
def parse_diff(jdiff_evaluate_response, actual, intended, match_config):
136127
"""Parse jdiff evaluate result into missing and extra dictionaries."""
137128
extra = {}
138129
missing = {}
139130

140131
def process_diff(_map, extra_map, missing_map, previous_key=None):
141132
for key, value in _map.items():
142-
if (
143-
isinstance(value, dict)
144-
and "new_value" in value
145-
and "old_value" in value
146-
):
133+
print("value", value)
134+
print("type(value)", type(value))
135+
if isinstance(value, dict) and "new_value" in value and "old_value" in value:
147136
extra_map[key] = value["old_value"]
148137
missing_map[key] = value["new_value"]
149138
elif isinstance(value, str):
150139
if "missing" in value:
140+
print("missing", value)
151141
extra_map[key] = actual.get(match_config, {}).get(key)
152142
if "new" in value:
143+
print("new", value)
153144
key_chain, _ = _parse_index_element_string(key)
154145
new_value = reduce(getitem, key_chain, intended)
155146
set_nested_value(missing_map, key_chain[1::], new_value)

tests/test_diff_helpers.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@ def test_group_value():
3232
"""Tests that nested dict is recursively created."""
3333
tree_list = ["10.1.0.0", "is_enabled"]
3434
value = {"new_value": False, "old_value": True}
35-
assert group_value(tree_list, value) == {
36-
"10.1.0.0": {"is_enabled": {"new_value": False, "old_value": True}}
37-
}
35+
assert group_value(tree_list, value) == {"10.1.0.0": {"is_enabled": {"new_value": False, "old_value": True}}}
3836

3937

4038
def test_fix_deepdiff_key_names():
4139
"""Tests that deepdiff return is parsed properly."""
42-
deepdiff_object = {
43-
"root[0]['10.1.0.0']['is_enabled']": {"new_value": False, "old_value": True}
44-
}
40+
deepdiff_object = {"root[0]['10.1.0.0']['is_enabled']": {"new_value": False, "old_value": True}}
4541
assert fix_deepdiff_key_names(deepdiff_object) == {
4642
"10.1.0.0": {"is_enabled": {"new_value": False, "old_value": True}}
4743
}
@@ -50,9 +46,7 @@ def test_fix_deepdiff_key_names():
5046
def test_get_diff_iterables_items():
5147
"""Tests that deepdiff return is parsed properly."""
5248
diff_result = {
53-
"values_changed": {
54-
"root['Ethernet1'][0]['port']": {"new_value": "518", "old_value": "519"}
55-
},
49+
"values_changed": {"root['Ethernet1'][0]['port']": {"new_value": "518", "old_value": "519"}},
5650
"iterable_item_added": {
5751
"root['Ethernet3'][1]": {
5852
"hostname": "ios-xrv-unittest",
@@ -63,9 +57,7 @@ def test_get_diff_iterables_items():
6357
result = get_diff_iterables_items(diff_result)
6458

6559
assert list(dict(result).keys())[0] == "['Ethernet3']"
66-
assert list(list(dict(result).values())[0].values())[0] == [
67-
{"hostname": "ios-xrv-unittest", "port": "Gi0/0/0/0"}
68-
]
60+
assert list(list(dict(result).values())[0].values())[0] == [{"hostname": "ios-xrv-unittest", "port": "Gi0/0/0/0"}]
6961

7062

7163
index_element_case_1 = (
@@ -93,8 +85,8 @@ def test__parse_index_element_string(index_element, result):
9385
{"foo": {"bar-1": "baz1"}}, # actual
9486
{"foo": {"bar-2": "baz2"}}, # intended
9587
"foo", # match_config
96-
{"bar-1": "baz1"}, # extra
97-
{"bar-2": "baz2"}, # missing
88+
{"foo": {"bar-1": "baz1"}}, # extra
89+
{"foo": {"bar-2": "baz2"}}, # missing
9890
)
9991

10092
parse_diff_case_1 = (
@@ -190,14 +182,12 @@ def test_parse_diff(actual, intended, match_config, extra, missing): # pylint:
190182
"""Test that index_element can be unpacked."""
191183
jdiff_param_match = CheckType.create("exact_match")
192184
jdiff_evaluate_response, _ = jdiff_param_match.evaluate(actual, intended)
193-
print(jdiff_evaluate_response)
194185

195186
parsed_extra, parsed_missing = parse_diff(
196187
jdiff_evaluate_response,
197188
actual,
198189
intended,
199190
match_config,
200191
)
201-
print(parsed_extra, parsed_missing)
202192
assert parsed_extra == extra
203193
assert parsed_missing == missing

towncrier_templates.j2

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
# v{{ versiondata.version.split(".")[:2] | join(".") }} Release Notes
3+
4+
This document describes all new features and changes in the release. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5+
6+
## Release Overview
7+
8+
- Major features or milestones
9+
- Changes to compatibility with Nautobot and/or other apps, libraries etc.
10+
11+
{% if render_title %}
12+
## [v{{ versiondata.version }} ({{ versiondata.date }})](https://github.com/networktocode/{{ cookiecutter.project_slug }}/releases/tag/v{{ versiondata.version}})
13+
14+
{% endif %}
15+
{% for section, _ in sections.items() %}
16+
{% if sections[section] %}
17+
{% for category, val in definitions.items() if category in sections[section] %}
18+
{% if sections[section][category]|length != 0 %}
19+
### {{ definitions[category]['name'] }}
20+
21+
{% if definitions[category]['showcontent'] %}
22+
{% for text, values in sections[section][category].items() %}
23+
{% for item in text.split('\n') %}
24+
{% if values %}
25+
- {{ values|join(', ') }} - {{ item.strip() }}
26+
{% else %}
27+
- {{ item.strip() }}
28+
{% endif %}
29+
{% endfor %}
30+
{% endfor %}
31+
32+
{% else %}
33+
- {{ sections[section][category]['']|join(', ') }}
34+
35+
{% endif %}
36+
{% endif %}
37+
{% endfor %}
38+
{% else %}
39+
No significant changes.
40+
41+
{% endif %}
42+
{% endfor %}

0 commit comments

Comments
 (0)