|
| 1 | + |
| 2 | +// This source file is part of the Swift.org open source project |
| 3 | +// |
| 4 | +// Copyright (c) 2024 Apple Inc. and the Swift project authors |
| 5 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | +// |
| 7 | +// See https://swift.org/LICENSE.txt for license information |
| 8 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 9 | + |
| 10 | +import Markdown |
| 11 | +import EvolutionMetadataModel |
| 12 | + |
| 13 | +struct DiscussionExtractor: MarkupWalker, ValueExtractor { |
| 14 | + |
| 15 | + private var warnings: [Proposal.Issue] = [] |
| 16 | + private var errors: [Proposal.Issue] = [] |
| 17 | + |
| 18 | + private var discussions: [Proposal.Discussion] = [] |
| 19 | + |
| 20 | + mutating func extractValue(from sourceValues: (headerFieldsByLabel: [String : ListItem], proposalID: String)) -> ExtractionResult<[Proposal.Discussion]> { |
| 21 | + |
| 22 | + // VALIDATION ENHANCEMENT: Normalize naming to 'Review' in the source proposals. |
| 23 | + if let (_, headerField) = sourceValues.headerFieldsByLabel[["Review", "Reviews", "Decision Notes", "Decision notes"]] { |
| 24 | + visit(headerField) |
| 25 | + |
| 26 | + // VALIDATION ENHANCEMENT: Correct proposals with known issues and remove special case logic. |
| 27 | + // Currently a fair number of older proposals are missing links to discussions or do not |
| 28 | + // format discussions correctly. Those issues should be corrected in the proposals themselves. |
| 29 | + // Once all of those issues are resolved, the legacy check can be removed. |
| 30 | + if discussions.isEmpty && !Legacy.discussionExtractionFailures.contains(sourceValues.proposalID) { |
| 31 | + errors.append(ValidationIssue.discussionExtractionFailure) |
| 32 | + } |
| 33 | + } else { |
| 34 | + // VALIDATION ENHANCEMENT: Add field to proposals with missing field and remove special case logic. |
| 35 | + // 'Review' is a required field, but currently a fair number of older proposals are missing the |
| 36 | + // field for a variety of reasons. Those issues should be corrected in the proposals themselves. |
| 37 | + // Once all of those issues are resolved, the legacy check can be removed. |
| 38 | + // Note that some very early proposals may not have valid discussions be extracted. |
| 39 | + if !Legacy.missingReviewFields.contains(sourceValues.proposalID) { |
| 40 | + errors.append(ValidationIssue.missingReviewField) |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + return ExtractionResult(value: discussions, warnings: warnings, errors: errors) |
| 45 | + } |
| 46 | + |
| 47 | + // Existing proposals with known validation errors. |
| 48 | + // The listed exceptions will not generate warnings and errors for the known issues. |
| 49 | + private enum Legacy { |
| 50 | + static let missingReviewFields: Set<String> = ["SE-0001", "SE-0002", "SE-0004", "SE-0020", "SE-0051", "SE-0079", "SE-0100", "SE-0176", "SE-0177", "SE-0188", "SE-0193", "SE-0194", "SE-0196", "SE-0198", "SE-0201", "SE-0203", "SE-0205", "SE-0208", "SE-0209", "SE-0210", "SE-0212", "SE-0213", "SE-0219", "SE-0243", "SE-0245", "SE-0247", "SE-0248", "SE-0249", "SE-0250", "SE-0252", "SE-0259", "SE-0263", "SE-0268", "SE-0269", "SE-0273", "SE-0278", "SE-0284", "SE-0289", "SE-0295", "SE-0300", "SE-0303", "SE-0304", "SE-0312", "SE-0313", "SE-0317", "SE-0318", "SE-0337", "SE-0338", "SE-0341", "SE-0343", "SE-0344", "SE-0348", "SE-0350", "SE-0356", "SE-0365", "SE-0385"] |
| 51 | + |
| 52 | + static let discussionExtractionFailures: Set<String> = ["SE-0099", "SE-0363", "SE-0378", "SE-0391", "SE-0392"] |
| 53 | + } |
| 54 | + |
| 55 | + mutating func visitLink(_ link: Link) -> () { |
| 56 | + guard let linkInfo = LinkInfo(link: link) else { |
| 57 | + return |
| 58 | + } |
| 59 | + |
| 60 | + if let discussionURL = linkInfo.swiftForumsDestination { |
| 61 | + discussions.append(Proposal.Discussion(name: linkInfo.text, link: discussionURL)) |
| 62 | + } else { |
| 63 | + warnings.append(ValidationIssue.invalidDiscussionLink) |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments