|
| 1 | +// Copyright (c) 2019 Spotify AB. |
| 2 | +// |
| 3 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +// or more contributor license agreements. See the NOTICE file |
| 5 | +// distributed with this work for additional information |
| 6 | +// regarding copyright ownership. The ASF licenses this file |
| 7 | +// to you under the Apache License, Version 2.0 (the |
| 8 | +// "License"); you may not use this file except in compliance |
| 9 | +// with the License. You may obtain a copy of the License at |
| 10 | +// |
| 11 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +// |
| 13 | +// Unless required by applicable law or agreed to in writing, |
| 14 | +// software distributed under the License is distributed on an |
| 15 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +// KIND, either express or implied. See the License for the |
| 17 | +// specific language governing permissions and limitations |
| 18 | +// under the License. |
| 19 | + |
| 20 | +import Foundation |
| 21 | + |
| 22 | +extension BuildStep { |
| 23 | + |
| 24 | + func with(documentURL newDocumentURL: String) -> BuildStep { |
| 25 | + return BuildStep(type: type, |
| 26 | + machineName: machineName, |
| 27 | + buildIdentifier: buildIdentifier, |
| 28 | + identifier: identifier, |
| 29 | + parentIdentifier: parentIdentifier, |
| 30 | + domain: domain, |
| 31 | + title: title, |
| 32 | + signature: signature, |
| 33 | + startDate: startDate, |
| 34 | + endDate: endDate, |
| 35 | + startTimestamp: startTimestamp, |
| 36 | + endTimestamp: endTimestamp, |
| 37 | + duration: duration, |
| 38 | + detailStepType: detailStepType, |
| 39 | + buildStatus: buildStatus, |
| 40 | + schema: schema, |
| 41 | + subSteps: subSteps, |
| 42 | + warningCount: warningCount, |
| 43 | + errorCount: errorCount, |
| 44 | + architecture: architecture, |
| 45 | + documentURL: newDocumentURL, |
| 46 | + warnings: warnings, |
| 47 | + errors: errors, |
| 48 | + notes: notes, |
| 49 | + swiftFunctionTimes: swiftFunctionTimes) |
| 50 | + } |
| 51 | + |
| 52 | + func with(title newTitle: String) -> BuildStep { |
| 53 | + return BuildStep(type: type, |
| 54 | + machineName: machineName, |
| 55 | + buildIdentifier: buildIdentifier, |
| 56 | + identifier: identifier, |
| 57 | + parentIdentifier: parentIdentifier, |
| 58 | + domain: domain, |
| 59 | + title: newTitle, |
| 60 | + signature: signature, |
| 61 | + startDate: startDate, |
| 62 | + endDate: endDate, |
| 63 | + startTimestamp: startTimestamp, |
| 64 | + endTimestamp: endTimestamp, |
| 65 | + duration: duration, |
| 66 | + detailStepType: detailStepType, |
| 67 | + buildStatus: buildStatus, |
| 68 | + schema: schema, |
| 69 | + subSteps: subSteps, |
| 70 | + warningCount: warningCount, |
| 71 | + errorCount: errorCount, |
| 72 | + architecture: architecture, |
| 73 | + documentURL: documentURL, |
| 74 | + warnings: warnings, |
| 75 | + errors: errors, |
| 76 | + notes: notes, |
| 77 | + swiftFunctionTimes: swiftFunctionTimes) |
| 78 | + } |
| 79 | + |
| 80 | + func with(signature newSignature: String) -> BuildStep { |
| 81 | + return BuildStep(type: type, |
| 82 | + machineName: machineName, |
| 83 | + buildIdentifier: buildIdentifier, |
| 84 | + identifier: identifier, |
| 85 | + parentIdentifier: parentIdentifier, |
| 86 | + domain: domain, |
| 87 | + title: title, |
| 88 | + signature: newSignature, |
| 89 | + startDate: startDate, |
| 90 | + endDate: endDate, |
| 91 | + startTimestamp: startTimestamp, |
| 92 | + endTimestamp: endTimestamp, |
| 93 | + duration: duration, |
| 94 | + detailStepType: detailStepType, |
| 95 | + buildStatus: buildStatus, |
| 96 | + schema: schema, |
| 97 | + subSteps: subSteps, |
| 98 | + warningCount: warningCount, |
| 99 | + errorCount: errorCount, |
| 100 | + architecture: architecture, |
| 101 | + documentURL: documentURL, |
| 102 | + warnings: warnings, |
| 103 | + errors: errors, |
| 104 | + notes: notes, |
| 105 | + swiftFunctionTimes: swiftFunctionTimes) |
| 106 | + } |
| 107 | + |
| 108 | + func withFilteredNotices() -> BuildStep { |
| 109 | + let filteredNotes = filterNotices(notes) |
| 110 | + let filteredWarnings = filterNotices(warnings) |
| 111 | + let filtereredErrors = filterNotices(errors) |
| 112 | + return BuildStep(type: type, |
| 113 | + machineName: machineName, |
| 114 | + buildIdentifier: buildIdentifier, |
| 115 | + identifier: identifier, |
| 116 | + parentIdentifier: parentIdentifier, |
| 117 | + domain: domain, |
| 118 | + title: title, |
| 119 | + signature: signature, |
| 120 | + startDate: startDate, |
| 121 | + endDate: endDate, |
| 122 | + startTimestamp: startTimestamp, |
| 123 | + endTimestamp: endTimestamp, |
| 124 | + duration: duration, |
| 125 | + detailStepType: detailStepType, |
| 126 | + buildStatus: buildStatus, |
| 127 | + schema: schema, |
| 128 | + subSteps: subSteps, |
| 129 | + warningCount: filteredWarnings?.count ?? 0, |
| 130 | + errorCount: filtereredErrors?.count ?? 0, |
| 131 | + architecture: architecture, |
| 132 | + documentURL: documentURL, |
| 133 | + warnings: filteredWarnings, |
| 134 | + errors: filtereredErrors, |
| 135 | + notes: filteredNotes, |
| 136 | + swiftFunctionTimes: swiftFunctionTimes) |
| 137 | + } |
| 138 | + |
| 139 | + func with(subSteps newSubSteps: [BuildStep]) -> BuildStep { |
| 140 | + return BuildStep(type: type, |
| 141 | + machineName: machineName, |
| 142 | + buildIdentifier: buildIdentifier, |
| 143 | + identifier: identifier, |
| 144 | + parentIdentifier: parentIdentifier, |
| 145 | + domain: domain, |
| 146 | + title: title, |
| 147 | + signature: signature, |
| 148 | + startDate: startDate, |
| 149 | + endDate: endDate, |
| 150 | + startTimestamp: startTimestamp, |
| 151 | + endTimestamp: endTimestamp, |
| 152 | + duration: duration, |
| 153 | + detailStepType: detailStepType, |
| 154 | + buildStatus: buildStatus, |
| 155 | + schema: schema, |
| 156 | + subSteps: newSubSteps, |
| 157 | + warningCount: warningCount, |
| 158 | + errorCount: errorCount, |
| 159 | + architecture: architecture, |
| 160 | + documentURL: documentURL, |
| 161 | + warnings: warnings, |
| 162 | + errors: errors, |
| 163 | + notes: notes, |
| 164 | + swiftFunctionTimes: swiftFunctionTimes) |
| 165 | + } |
| 166 | + |
| 167 | + private func filterNotices(_ notices: [Notice]?) -> [Notice]? { |
| 168 | + guard let notices = notices else { |
| 169 | + return nil |
| 170 | + } |
| 171 | + return notices.filter { $0.documentURL.isEmpty || $0.documentURL == documentURL } |
| 172 | + } |
| 173 | +} |
0 commit comments