From 4f6f6aa9f2f04340548f8cd1bc7305b8d4b03cc0 Mon Sep 17 00:00:00 2001 From: mirii1994 Date: Thu, 23 Nov 2023 12:41:41 +0200 Subject: [PATCH 1/2] fix scripts to handle prs that are only delete --- _metadata_validation/get_pr_files.py | 3 +-- _metadata_validation/validate_metadata.py | 16 ++++++++++++---- _metadata_validation/validate_metadata_test.py | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/_metadata_validation/get_pr_files.py b/_metadata_validation/get_pr_files.py index f1489b26..bd8e3296 100644 --- a/_metadata_validation/get_pr_files.py +++ b/_metadata_validation/get_pr_files.py @@ -26,8 +26,7 @@ def get_pr_files(): if len(files) == 0: break for file in files: - if file[status_field] != 'removed': - files_in_pr.append(file[file_name_field]) + files_in_pr.append(file[file_name_field]) page_number += 1 files_str = '' diff --git a/_metadata_validation/validate_metadata.py b/_metadata_validation/validate_metadata.py index a416d38e..141f1238 100644 --- a/_metadata_validation/validate_metadata.py +++ b/_metadata_validation/validate_metadata.py @@ -14,10 +14,14 @@ def validate_changed_files(): error_counter = 0 - changed_files = get_changed_files() + changed_files, removed_files = get_changed_files() if len(changed_files) == 0: - logger.error('Could not find changed files, exiting') - exit(1) + if len(removed_files) > 0: + logger.info('PR only deletes files') + exit(0) + else: + logger.error('Could not find changed files, exiting') + exit(1) logger.info(f'Files to scan: {changed_files}') files_to_unique_fields = get_files_to_unique_fields() if len(files_to_unique_fields) == 0: @@ -96,11 +100,15 @@ def get_changed_files(): files_str = files_str.replace(' ', '') files_arr = files_str.split(',') files_to_track = [] + removed_files = [] for file in files_arr: docs_path = os.getenv(consts.ENV_DOCS_PREFIX, consts.DOCS_PATH) + if not os.path.isfile(docs_path): + removed_files.append(file) + continue if file.startswith(docs_path) and file.endswith('.md'): files_to_track.append(file) - return files_to_track + return files_to_track, removed_files def get_files_to_unique_fields(): diff --git a/_metadata_validation/validate_metadata_test.py b/_metadata_validation/validate_metadata_test.py index 9bbffef7..9a5d3416 100644 --- a/_metadata_validation/validate_metadata_test.py +++ b/_metadata_validation/validate_metadata_test.py @@ -148,13 +148,13 @@ def test_get_files_to_ids(self): def test_get_changed_files(self): changed_set = f'{self.PATH_PREFIX}valid-sample.md' os.environ[validate_metadata.consts.ENV_FILES_TO_TRACK] = changed_set - changed_files = validate_metadata.get_changed_files() + changed_files, removed_files = validate_metadata.get_changed_files() self.assertEqual(len(changed_files), 1) self.assertEqual(changed_files[0], changed_set) def test_get_changed_files_empty(self): os.environ[validate_metadata.consts.ENV_FILES_TO_TRACK] = '' - changed_files = validate_metadata.get_changed_files() + changed_files, removed_files = validate_metadata.get_changed_files() self.assertEqual(len(changed_files), 0) def test_get_file_metadata(self): From d38d808cd29c9747a1e8b697812eb55cbbf00c76 Mon Sep 17 00:00:00 2001 From: mirii1994 Date: Thu, 23 Nov 2023 12:55:20 +0200 Subject: [PATCH 2/2] final --- _metadata_validation/validate_metadata.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_metadata_validation/validate_metadata.py b/_metadata_validation/validate_metadata.py index 141f1238..862630f7 100644 --- a/_metadata_validation/validate_metadata.py +++ b/_metadata_validation/validate_metadata.py @@ -96,14 +96,14 @@ def print_missing_fields(file_metadata): def get_changed_files(): files_str = os.getenv(consts.ENV_FILES_TO_TRACK, '') if files_str == '': - return [] + return [], [] files_str = files_str.replace(' ', '') files_arr = files_str.split(',') files_to_track = [] removed_files = [] for file in files_arr: docs_path = os.getenv(consts.ENV_DOCS_PREFIX, consts.DOCS_PATH) - if not os.path.isfile(docs_path): + if not os.path.isfile(file): removed_files.append(file) continue if file.startswith(docs_path) and file.endswith('.md'):