|
2 | 2 |
|
3 | 3 |
|
4 | 4 | import os
|
| 5 | +from datetime import datetime, timedelta |
5 | 6 |
|
6 | 7 | import toml
|
7 | 8 | from connector_ops.utils import Connector, ConnectorLanguage # type: ignore
|
@@ -149,8 +150,68 @@ def _run(self, connector: Connector) -> CheckResult:
|
149 | 150 | )
|
150 | 151 |
|
151 | 152 |
|
| 153 | +class ValidateBreakingChangesDeadlines(MetadataCheck): |
| 154 | + """ |
| 155 | + Verify that _if_ the the most recent connector version has a breaking change, |
| 156 | + it's deadline is at least a week in the future. |
| 157 | + """ |
| 158 | + |
| 159 | + name = "Breaking change deadline should be a week in the future" |
| 160 | + description = "If the connector version has a breaking change, the deadline field must be set to at least a week in the future." |
| 161 | + runs_on_released_connectors = False |
| 162 | + minimum_days_until_deadline = 7 |
| 163 | + |
| 164 | + def _run(self, connector: Connector) -> CheckResult: |
| 165 | + |
| 166 | + # fetch the current branch version of the connector first. |
| 167 | + # we'll try and see if there are any breaking changes associated |
| 168 | + # with it next. |
| 169 | + current_version = connector.version |
| 170 | + if current_version is None: |
| 171 | + return self.fail( |
| 172 | + connector=connector, |
| 173 | + message="Can't verify breaking changes deadline: connector version is not defined.", |
| 174 | + ) |
| 175 | + |
| 176 | + breaking_changes = connector.metadata.get("releases", {}).get("breakingChanges") |
| 177 | + |
| 178 | + if not breaking_changes: |
| 179 | + return self.pass_( |
| 180 | + connector=connector, |
| 181 | + message="No breaking changes found on this connector.", |
| 182 | + ) |
| 183 | + |
| 184 | + current_version_breaking_changes = breaking_changes.get(current_version) |
| 185 | + |
| 186 | + if not current_version_breaking_changes: |
| 187 | + return self.pass_( |
| 188 | + connector=connector, |
| 189 | + message="No breaking changes found for the current version.", |
| 190 | + ) |
| 191 | + |
| 192 | + upgrade_deadline = current_version_breaking_changes.get("upgradeDeadline") |
| 193 | + |
| 194 | + if not upgrade_deadline: |
| 195 | + return self.fail( |
| 196 | + connector=connector, |
| 197 | + message=f"No upgrade deadline found for the breaking changes in {current_version}.", |
| 198 | + ) |
| 199 | + |
| 200 | + upgrade_deadline_datetime = datetime.strptime(upgrade_deadline, "%Y-%m-%d") |
| 201 | + one_week_from_now = datetime.utcnow() + timedelta(days=self.minimum_days_until_deadline) |
| 202 | + |
| 203 | + if upgrade_deadline_datetime <= one_week_from_now: |
| 204 | + return self.fail( |
| 205 | + connector=connector, |
| 206 | + message=f"The upgrade deadline for the breaking changes in {current_version} is less than {self.minimum_days_until_deadline} days from today. Please extend the deadline", |
| 207 | + ) |
| 208 | + |
| 209 | + return self.pass_(connector=connector, message="The upgrade deadline is set to at least a week in the future") |
| 210 | + |
| 211 | + |
152 | 212 | ENABLED_CHECKS = [
|
153 | 213 | ValidateMetadata(),
|
154 | 214 | CheckConnectorLanguageTag(),
|
155 | 215 | CheckConnectorCDKTag(),
|
| 216 | + ValidateBreakingChangesDeadlines(), |
156 | 217 | ]
|
0 commit comments