Skip to content

Add structured JSON output for changelog - #329

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
abhinavgautam01:feature/changelog-json-261
Aug 24, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
abhinavgautam01:feature/changelog-json-261

Conversation

@abhinavgautam01

Copy link
Copy Markdown
Contributor

Closes #261

Summary

  • add --format text|json support to git pkgs changelog
  • keep text output as the default
  • return package and changelog source metadata in JSON
  • return changelog content as structured per-version entries
  • validate unsupported formats before ecosystem detection or network requests
  • ensure empty JSON results contain "entries": []

JSON Format

{
  "package": "lodash",
  "ecosystem": "npm",
  "from": "4.17.20",
  "to": "4.17.21",
  "repository": "https://github.com/lodash/lodash",
  "changelog_filename": "CHANGELOG.md",
  "entries": [
    {
      "version": "4.17.21",
      "content": "..."
    }
  ]
}

Version ranges use changelog.Parser.VersionsBetween, with an exclusive lower bound and inclusive upper bound. This also supports bounds that do not exactly match changelog headings.

Testing

Added regression coverage for:

  • complete structured changelog results
  • bounded version ranges
  • bounds between existing version headings
  • package and source metadata
  • empty entries encoded as a JSON array
  • unsupported format validation before network access

Verification

  • go build ./...
  • go mod tidy -diff
  • go test ./... -count=1
  • go test -race ./... -count=1
  • go tool golangci-lint run ./...
  • git diff --check

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds structured JSON output support to the git pkgs changelog command so changelog data can be consumed programmatically (bots/CI/release tooling) while preserving the existing text output as the default.

Changes:

  • Added --format text|json to git pkgs changelog, with early validation of unsupported formats.
  • Implemented JSON output including package/source metadata plus per-version structured changelog entries (including "entries": [] for empty results).
  • Added unit/regression tests for JSON output shape, version-bounded ranges, and unsupported format behavior; updated README usage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
README.md Documents --format json usage and clarifies text is still the default.
cmd/format_test.go Extends unsupported-format validation coverage to include the changelog command.
cmd/changelog.go Adds --format flag, JSON result structs, JSON output path, and structured entry building.
cmd/changelog_internal_test.go Adds tests for structured result building and ensures empty entries is encoded as [].

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@andrew
andrew merged commit 457f8cd into git-pkgs:main Aug 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add structured JSON output for changelog

3 participants