Takes the original lines and updates with new_content. The metadata governs how to remove the old unreleased section and where to place the new content. Args: lines: The lines from the changelog new_content: This should be placed somewhere in the lines metadata:
(
new_content: str, lines: list[str], metadata: Metadata
)
| 244 | |
| 245 | |
| 246 | def incremental_build( |
| 247 | new_content: str, lines: list[str], metadata: Metadata |
| 248 | ) -> list[str]: |
| 249 | """Takes the original lines and updates with new_content. |
| 250 | |
| 251 | The metadata governs how to remove the old unreleased section and where to place the |
| 252 | new content. |
| 253 | |
| 254 | Args: |
| 255 | lines: The lines from the changelog |
| 256 | new_content: This should be placed somewhere in the lines |
| 257 | metadata: Information about the changelog |
| 258 | |
| 259 | Returns: |
| 260 | Updated lines |
| 261 | """ |
| 262 | unreleased_start = metadata.unreleased_start |
| 263 | unreleased_end = metadata.unreleased_end |
| 264 | latest_version_position = metadata.latest_version_position |
| 265 | |
| 266 | skip = False |
| 267 | output_lines: list[str] = [] |
| 268 | for index, line in enumerate(lines): |
| 269 | if index == unreleased_start: |
| 270 | skip = True |
| 271 | elif index == unreleased_end: |
| 272 | skip = False |
| 273 | if ( |
| 274 | latest_version_position is None |
| 275 | or latest_version_position > unreleased_end |
| 276 | ): |
| 277 | continue |
| 278 | |
| 279 | if skip: |
| 280 | continue |
| 281 | |
| 282 | if index == latest_version_position: |
| 283 | output_lines.extend([new_content, "\n"]) |
| 284 | output_lines.append(line) |
| 285 | |
| 286 | if latest_version_position is not None: |
| 287 | return output_lines |
| 288 | |
| 289 | if output_lines and output_lines[-1].strip(): |
| 290 | # Ensure at least one blank line between existing and new content. |
| 291 | output_lines.append("\n") |
| 292 | output_lines.append(new_content) |
| 293 | return output_lines |
| 294 | |
| 295 | |
| 296 | def get_next_tag_name_after_version(tags: Iterable[GitTag], version: str) -> str | None: |
no outgoing calls
searching dependent graphs…