-
Notifications
You must be signed in to change notification settings - Fork 14
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
Check that workshops have a LICENSE file in root #257
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ private let filePaths = ( | |
notesMarkdown: "/.hac_workshop/notes.md", | ||
examplesDirectory: "/", | ||
presenterGuide: "/.hac_workshop/presenter_guide.md", | ||
setupInstructions: "/.hac_workshop/setup_instructions.md" | ||
setupInstructions: "/.hac_workshop/setup_instructions.md", | ||
license: "/LICENSE" | ||
) | ||
|
||
private let validImageExtensions = ["jpg", "svg", "png", "gif"] | ||
|
@@ -39,6 +40,7 @@ extension Workshop { | |
slidesLink = try builder.getSlidesLink() | ||
tags = try builder.getTags() | ||
license = try builder.getLicense() | ||
hasLicense = try Workshop.getHasLicense(localPath: localPath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This license / hasLicense thing looks a bit confusing. Alternatively, why not rename the |
||
} | ||
|
||
private static func getWorkshopId(localPath: String) throws -> String { | ||
|
@@ -60,11 +62,21 @@ extension Workshop { | |
} | ||
return try Yaml.load(metadataString) | ||
} | ||
|
||
private static func getHasLicense(localPath: String) throws -> Bool { | ||
do { | ||
_ = try String(contentsOfFile: localPath + filePaths.license, encoding: .utf8) | ||
} catch { | ||
return false | ||
} | ||
return true | ||
} | ||
} | ||
|
||
private enum WorkshopError: Swift.Error { | ||
case invalidPath | ||
case missingMetadata | ||
case missingLicenseText | ||
case malformedMetadata(String) | ||
case missingPromoImageBackground | ||
case missingPromoImageForeground | ||
|
@@ -163,7 +175,7 @@ private struct WorkshopBuilder { | |
if backgroundFileNames.count < 1 { | ||
throw WorkshopError.missingPromoImageBackground | ||
} else { | ||
throw WorkshopError.multiplePromoImageBackgrounds | ||
throw WorkshopError.multiplePromoImageBackgrounds | ||
} | ||
} | ||
let backgroundFileName = backgroundFileNames[0] | ||
|
@@ -222,7 +234,7 @@ private struct WorkshopBuilder { | |
let urlString = $0["url"].string else { | ||
throw WorkshopError.malformedMetadata("Links should have a 'text' and a 'url' property") | ||
} | ||
|
||
guard let url = URL(string: urlString) else { | ||
throw WorkshopError.malformedMetadata("Links should have valid URLs") | ||
} | ||
|
@@ -235,7 +247,7 @@ private struct WorkshopBuilder { | |
guard let urlString = metadata["recording_link"].string else { | ||
return nil | ||
} | ||
|
||
guard let url = URL(string: urlString) else { | ||
throw WorkshopError.malformedMetadata("Recording link should be a valid URL") | ||
} | ||
|
@@ -247,7 +259,7 @@ private struct WorkshopBuilder { | |
guard let urlString = metadata["slides_link"].string else { | ||
return nil | ||
} | ||
|
||
guard let url = URL(string: urlString) else { | ||
throw WorkshopError.malformedMetadata("Slides link should be a valid URL") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: Lisence ⟶ License