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

Check that workshops have a LICENSE file in root #257

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct WorkshopsController {
var warnings: [String] = []
if workshop.title == "Sample Workshop" { warnings.append("Title has not been set") }
if workshop.contributors.isEmpty { warnings.append("Contributors have not been listed") }
if !workshop.hasLicense { warnings.append("Lisence missing: The root of the workshop repo should have a LICENSE file containing the following license: \(workshop.license)") }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: Lisence ⟶ License


if warnings.isEmpty {
errorNode = El.Div[
Expand Down
22 changes: 17 additions & 5 deletions Sources/HaCWebsiteLib/Models/Workshop+init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -39,6 +40,7 @@ extension Workshop {
slidesLink = try builder.getSlidesLink()
tags = try builder.getTags()
license = try builder.getLicense()
hasLicense = try Workshop.getHasLicense(localPath: localPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This license / hasLicense thing looks a bit confusing.
Could you explain again the justification for having both the license ID in the metadata.yaml and the LICENSE text file? Maybe we should get rid of the license id

Alternatively, why not rename the license field on Workshop to licenseId

}

private static func getWorkshopId(localPath: String) throws -> String {
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/HaCWebsiteLib/Models/Workshop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public struct Workshop {
// TODO: Make a type safe version of this
let license: String

/// Whether or not the workshop repository actually contains license text in it
let hasLicense: Bool

/// The prose content that accompanies the workshop (and slides)
let notes: Markdown

Expand Down