Adding doc comments generated by cline

This commit is contained in:
a8trejo
2024-12-10 15:23:02 -08:00
parent 2b8e85ab52
commit 9c2634b662
4 changed files with 87 additions and 19 deletions

View File

@@ -1,14 +1,44 @@
"""
This script updates a specific version's release notes section in CHANGELOG.md with new content.
The script:
1. Takes a version number, changelog path, and new content as input from environment variables
2. Finds the section in the changelog for the specified version
3. Replaces the content between the current version header and the next version header
(or end of file if it's the latest version) with the new content
4. Writes the updated changelog back to the file
Environment Variables:
CHANGELOG_PATH: Path to the changelog file (defaults to 'CHANGELOG.md')
VERSION: The version number to update notes for
PREV_VERSION: The previous version number (optional)
NEW_CONTENT: The new content to insert for this version
"""
#!/usr/bin/env python3
import os
GITHUB_OUTPUT = os.getenv("GITHUB_OUTPUT")
CHANGELOG_PATH = os.environ.get("CHANGELOG_PATH", "CHANGELOG.md")
VERSION = os.environ['VERSION']
PREV_VERSION = os.environ.get("PREV_VERSION", "")
NEW_CONTENT = os.environ['NEW_CONTENT']
def overwrite_changelog_section(content: str):
"""Replace a specific version section in the changelog content.
Args:
content: The full changelog content as a string
Returns:
The updated changelog content with the new section
Example:
>>> content = "## 1.2.0\\nOld changes\\n## 1.1.0\\nOld changes"
>>> NEW_CONTENT = "New changes"
>>> overwrite_changelog_section(content)
'## 1.2.0\\nNew changes\\n## 1.1.0\\nOld changes'
"""
# Find the section for the specified version
version_pattern = f"## {VERSION}\n"
print(f"latest version: {VERSION}")

View File

@@ -1,3 +1,19 @@
"""
This script extracts the release notes section for a specific version from CHANGELOG.md.
The script:
1. Takes a version number and changelog path as input from environment variables
2. Finds the section in the changelog for the specified version
3. Extracts the content between the current version header and the next version header
(or end of file if it's the latest version)
4. Outputs the extracted release notes to GITHUB_OUTPUT for use in creating GitHub releases
Environment Variables:
GITHUB_OUTPUT: Path to GitHub Actions output file
CHANGELOG_PATH: Path to the changelog file (defaults to 'CHANGELOG.md')
VERSION: The version number to extract notes for
"""
#!/usr/bin/env python3
import sys
@@ -10,8 +26,17 @@ VERSION = os.environ['VERSION']
def parse_changelog_section(content: str):
"""Parse a specific version section from the changelog content.
Args:
content: The full changelog content as a string
Returns: The formatted content for this version, or None if version not found
Returns:
The formatted content for this version, or None if version not found
Example:
>>> content = "## 1.2.0\\nChanges\\n## 1.1.0\\nOld changes"
>>> parse_changelog_section(content)
'Changes\\n'
"""
# Find the section for the specified version
version_pattern = f"## {VERSION}\n"
@@ -34,5 +59,6 @@ if not formatted_content:
print(formatted_content)
# Write the extracted release notes to GITHUB_OUTPUT
with open(GITHUB_OUTPUT, "a") as gha_output:
gha_output.write(f"release-notes<<EOF\n{formatted_content}\nEOF")
gha_output.write(f"release-notes<<EOF\n{formatted_content}\nEOF")

View File

@@ -1,3 +1,9 @@
"""
This script generates a base prompt for OpenAI to create release notes.
"""
#!/usr/bin/env python3
import os
from datetime import datetime;
from pytz import timezone