diff --git a/integration_tests/base_test.py b/integration_tests/base_test.py index 24a4f2800..e3886e72b 100644 --- a/integration_tests/base_test.py +++ b/integration_tests/base_test.py @@ -84,6 +84,11 @@ def _assert_results_fields(self, results, output_path): result = results[0] assert result["codemod"] == self.codemod_wrapper.id assert result["references"] == self.codemod_wrapper.references + + # TODO: once we add description for each url. + for reference in result["references"]: + assert reference["url"] == reference["description"] + assert len(result["changeset"]) == self.num_changed_files # A codemod may change multiple files. For now we will diff --git a/src/codemodder/codemods/base_codemod.py b/src/codemodder/codemods/base_codemod.py index c6393e353..014980f17 100644 --- a/src/codemodder/codemods/base_codemod.py +++ b/src/codemodder/codemods/base_codemod.py @@ -24,6 +24,18 @@ class CodemodMetadata: REVIEW_GUIDANCE: ReviewGuidance REFERENCES: list = field(default_factory=list) + # TODO: remove post_init update_references once we add description for each url. + def __post_init__(self): + object.__setattr__(self, "REFERENCES", self.update_references(self.REFERENCES)) + @staticmethod + def update_references(references): + updated_references = [] + for reference in references: + updated_reference = dict(reference) # Create a copy to avoid modifying the original dict + updated_reference['description'] = updated_reference['url'] + updated_references.append(updated_reference) + return updated_references + class BaseCodemod: # Implementation borrowed from https://stackoverflow.com/a/45250114