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

WEB-6543: Updating linter file existence checker to work with subfiles #222

Merged
merged 1 commit into from
Oct 11, 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
5 changes: 4 additions & 1 deletion app/lib/linting/metadata/captions_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ def video_course_captions
def module_captions
caption_files = ModuleFile.new(file:, attributes:).file_path_list
caption_files.map do |file|
if yaml?(file)
captions_file = if yaml?(file)
load_yaml(File.read(file)).deep_symbolize_keys[:captions_file]
else
@markdown_metadata = nil
@path = file
markdown_metadata[:captions_file]
end
next unless captions_file.present?

[captions_file, file]
end.compact
end

Expand Down
18 changes: 12 additions & 6 deletions app/lib/linting/metadata/file_attribute_existence_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ module FileAttributeExistenceChecker

def file_attribute_annotations
file_path_list.map do |path|
next if relative_file_exists?(path)
if path.is_a?(Array)
relative_to = path.second
path = path.first
else
relative_to = file
end
next if relative_file_exists?(path, relative_to:)

line = missing_file_line(path)
Annotation.new(
start_line: line,
end_line: line,
absolute_path: file,
absolute_path: relative_to,
annotation_level: 'failure',
message: "`release.yaml` includes references to unknown #{file_description} file: `#{path}",
message: "`#{relative_to}` includes references to unknown #{file_description} file: `#{path}",
title: "Missing #{file_description} file"
)
end.compact
Expand All @@ -33,17 +39,17 @@ def file_description
private

# Check whether script file exists
def relative_file_exists?(path)
def relative_file_exists?(path, relative_to: nil)
# Find path relative to the release.yaml file
file_path = Pathname.new(file).dirname.join(path)
file_path = Pathname.new(relative_to || file).dirname.join(path)
# Check whether this exists
file_exists?(file_path)
end

# Search release.yaml line by line to find the file references
def missing_file_line(path)
File.readlines(file).each_with_index do |line, index|
return index + 1 if line.include?(path)
return index + 1 if line.include?(path.to_s)
end
end
end
Expand Down