Skip to content

Commit

Permalink
fix scripts to handle prs that are only delete (#279)
Browse files Browse the repository at this point in the history
* fix scripts to handle prs that are only delete

* final

---------

Co-authored-by: Ral G <[email protected]>
  • Loading branch information
mirii1994 and ralongit authored Nov 26, 2023
1 parent 5b75c4e commit 7d9d361
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
3 changes: 1 addition & 2 deletions _metadata_validation/get_pr_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down
18 changes: 13 additions & 5 deletions _metadata_validation/validate_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -92,15 +96,19 @@ 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(file):
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():
Expand Down
4 changes: 2 additions & 2 deletions _metadata_validation/validate_metadata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7d9d361

Please sign in to comment.