Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix scripts to handle prs that are only delete #279

Merged
merged 3 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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