Skip to content

Commit a4d2e3a

Browse files
committed
Add tag with original category
1 parent 87d7d82 commit a4d2e3a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

scripts/guideline_recategorization/recategorize.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import argparse
22
import sys
33
from dataclasses import asdict, dataclass
4-
from typing import Any, Generator, Iterator, Mapping, Optional, TextIO, TypedDict, Union, cast
4+
from typing import Any, Generator, Iterator, List, Mapping, Optional, TextIO, TypedDict, Union, cast
55
from pathlib import Path
66
import jsonschema
77
import json
@@ -74,14 +74,15 @@ def generate_json_patches_for_recategorization(recategorization: GuidelineRecate
7474
"""
7575
Compute as set of JSON patches to apply the recategorization to the subject Sarif file.
7676
"""
77-
def to_jsonpatch(pointer:jsonpointer.JsonPointer):
78-
standard = cast(str, pointer.get(subject)).split('/')[1]
79-
return JsonPatch(
77+
def to_jsonpatch(pointer:jsonpointer.JsonPointer) -> Iterator[JsonPatch]:
78+
obligation_tag = cast(str, pointer.get(subject))
79+
_, standard, _, category = obligation_tag.split('/')
80+
yield JsonPatch(
8081
op = 'replace',
8182
path = pointer.path,
82-
value = f'external/{standard}/obligation/{recategorization.category}'
83-
)
84-
return map(to_jsonpatch, json_path_to_pointer(recategorization_to_json_path_for_category(recategorization), subject))
83+
value = f'external/{standard}/obligation/{recategorization.category}')
84+
yield JsonPatch(op = 'add', path = pointer.path, value = f'external/{standard}/original-obligation/{category}')
85+
return (patch for pointer in json_path_to_pointer(recategorization_to_json_path_for_category(recategorization), subject) for patch in to_jsonpatch(pointer))
8586

8687

8788
def get_guideline_recategorizations(coding_standards_config: Mapping[str, Any]) -> Generator[GuidelineRecategorization, None, None]:

0 commit comments

Comments
 (0)