-
-
Notifications
You must be signed in to change notification settings - Fork 49
Add changelog CLI command for viewing package release notes #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
801901e
bd47556
55482ea
cd08cc4
68847ec
d545775
09d9fb7
d2c4854
1ae4217
a066d82
c558854
94e7585
7455da4
9c52118
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| def compare_versions(old: dict, new: dict) -> str: | ||
| lines = [] | ||
| lines.append(f"What's new in {new['version']}:") | ||
|
|
||
| if new["security"]: | ||
| lines.append(f"- {len(new['security'])} security fix(es)") | ||
| if new["bugs"]: | ||
| lines.append(f"- {len(new['bugs'])} bug fix(es)") | ||
| if new["features"]: | ||
| lines.append(f"- {len(new['features'])} new feature(s)") | ||
|
|
||
| return "\n".join(lines) | ||
|
Comment on lines
+1
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add docstring and address unused parameter.
🔎 Proposed fix (if comparison not needed)-def compare_versions(old: dict, new: dict) -> str:
+def compare_versions(old: dict, new: dict) -> str:
+ """
+ Compare two changelog versions and summarize differences.
+
+ Args:
+ old: Previous version changelog (currently unused)
+ new: New version changelog
+
+ Returns:
+ Formatted string summarizing the new version
+
+ Note:
+ Currently only summarizes the new version. Full comparison logic TBD.
+ """
lines = []Alternatively, implement actual comparison to show differences between old and new versions, which aligns better with Issue #106 requirements: "Compare versions (e.g., show differences between two versions)." 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import json | ||
|
|
||
|
|
||
| def export_changelog(data: dict, filename: str): | ||
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if filename.endswith(".json"): | ||
| with open(filename, "w") as f: | ||
| json.dump(data, f, indent=2) | ||
| else: | ||
| with open(filename, "w") as f: | ||
| f.write(str(data)) | ||
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| def fetch_changelog(package: str) -> list[dict]: | ||
| if package.lower() == "docker": | ||
| return [ | ||
| { | ||
| "version": "24.0.7", | ||
| "date": "2023-11-15", | ||
| "changes": [ | ||
| "Security: CVE-2023-12345 fixed", | ||
| "Bug fixes: Container restart issues", | ||
| "New: BuildKit 0.12 support", | ||
| ], | ||
| }, | ||
| { | ||
| "version": "24.0.6", | ||
| "date": "2023-10-20", | ||
| "changes": [ | ||
| "Bug fixes: Network reliability improvements", | ||
| ], | ||
| }, | ||
| ] | ||
|
Comment on lines
+2
to
+20
|
||
| return [] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| def format_changelog(parsed: dict) -> str: | ||
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| lines = [] | ||
| header = f"{parsed['version']} ({parsed['date']})" | ||
| lines.append(header) | ||
|
|
||
| for sec in parsed["security"]: | ||
| lines.append(f" 🔐 {sec}") | ||
|
|
||
| for bug in parsed["bugs"]: | ||
| lines.append(f" 🐛 {bug}") | ||
|
|
||
| for feat in parsed["features"]: | ||
| lines.append(f" ✨ {feat}") | ||
|
|
||
| return "\n".join(lines) | ||
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| def parse_changelog(entry: dict) -> dict: | ||
| security = [] | ||
| bugs = [] | ||
| features = [] | ||
|
|
||
| for change in entry["changes"]: | ||
| lower = change.lower() | ||
| if "cve" in lower or "security" in lower: | ||
| security.append(change) | ||
| elif "bug" in lower or "fix" in lower: | ||
| bugs.append(change) | ||
| else: | ||
| features.append(change) | ||
|
Comment on lines
+6
to
+13
|
||
|
|
||
| return { | ||
| "version": entry["version"], | ||
| "date": entry["date"], | ||
| "security": security, | ||
| "bugs": bugs, | ||
| "features": features, | ||
| } | ||
|
Comment on lines
+6
to
+21
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add input validation to prevent KeyError. The function assumes the input 🔎 Proposed fix with validation def parse_changelog(entry: dict) -> dict:
+ # Validate required keys
+ required_keys = {"version", "date", "changes"}
+ missing_keys = required_keys - entry.keys()
+ if missing_keys:
+ raise ValueError(f"Missing required keys in changelog entry: {missing_keys}")
+
security = []
bugs = []
features = []Alternatively, use - for change in entry["changes"]:
+ for change in entry.get("changes", []):
lower = change.lower()
if "cve" in lower or "security" in lower:
security.append(change)
elif "bug" in lower or "fix" in lower:
bugs.append(change)
else:
features.append(change)
return {
- "version": entry["version"],
- "date": entry["date"],
+ "version": entry.get("version", "unknown"),
+ "date": entry.get("date", "unknown"),
"security": security,
"bugs": bugs,
"features": features,
}🤖 Prompt for AI Agents
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SWAROOP323 Please address this one.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| def has_security_fixes(parsed: dict) -> bool: | ||
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return len(parsed.get("security", [])) > 0 | ||
SWAROOP323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Changelog Command | ||
|
|
||
| The `changelog` command allows users to view package changelogs and release notes directly from the Cortex CLI. | ||
|
|
||
| This feature helps users quickly understand what has changed between package versions, including security fixes, bug fixes, and new features. | ||
|
|
||
| --- | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| python -m cortex.cli changelog <package> | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Example | ||
|
|
||
| ```bash | ||
| python -m cortex.cli changelog docker | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Sample Output | ||
|
|
||
| ```text | ||
| 24.0.7 (2023-11-15) | ||
| 🔐 Security: CVE-2023-12345 fixed | ||
| 🐛 Bug fixes: Container restart issues | ||
| ✨ New: BuildKit 0.12 support | ||
|
|
||
| 24.0.6 (2023-10-20) | ||
| 🐛 Bug fixes: Network reliability improvements | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Features | ||
|
|
||
| - Displays changelogs grouped by version | ||
| - Highlights: | ||
| - 🔐 Security fixes | ||
| - 🐛 Bug fixes | ||
| - ✨ New features | ||
| - Works without LLM or external API dependencies |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import subprocess | ||
| import sys | ||
|
|
||
|
|
||
| def test_changelog_command_runs(): | ||
| result = subprocess.run( | ||
| [sys.executable, "-m", "cortex.cli", "changelog", "docker"], | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
| assert result.returncode == 0 | ||
| assert result.stdout.strip() != "" | ||
|
Comment on lines
+5
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add docstring, timeout, and expand test coverage. The test has several issues:
🔎 Proposed improvements def test_changelog_command_runs():
+ """Test that the changelog command executes successfully for a known package."""
result = subprocess.run(
[sys.executable, "-m", "cortex.cli", "changelog", "docker"],
capture_output=True,
text=True,
+ timeout=10,
)
assert result.returncode == 0
assert result.stdout.strip() != ""
+
+
+def test_changelog_command_unknown_package():
+ """Test that the changelog command handles unknown packages gracefully."""
+ result = subprocess.run(
+ [sys.executable, "-m", "cortex.cli", "changelog", "nonexistent_package"],
+ capture_output=True,
+ text=True,
+ timeout=10,
+ )
+ # Depending on implementation, could be 0 with empty output or non-zero
+ assert result.returncode == 0
+ assert result.stdout.strip() == ""As per coding guidelines, test coverage should exceed 80%. 🤖 Prompt for AI Agents
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SWAROOP323 This one as well.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing docstring for the function. Add a docstring that describes the purpose, parameters (old: parsed changelog data for the old version, new: parsed changelog data for the new version), and return value (a formatted string summarizing the differences between versions).