From 8fa8463cb59d0a27dedef43d6c1e77a780c8dd45 Mon Sep 17 00:00:00 2001 From: clavedeluna Date: Fri, 13 Oct 2023 09:18:55 -0300 Subject: [PATCH] make description = url automated --- integration_tests/base_test.py | 5 +++++ src/codemodder/codemods/base_codemod.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+) 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..c1092510d 100644 --- a/src/codemodder/codemods/base_codemod.py +++ b/src/codemodder/codemods/base_codemod.py @@ -24,6 +24,21 @@ 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