1515package conventionalcommits
1616
1717import (
18+ "encoding/json"
1819 "fmt"
1920 "log/slog"
2021 "regexp"
@@ -28,25 +29,39 @@ import (
2829// See https://www.conventionalcommits.org/en/v1.0.0/ for details.
2930type ConventionalCommit struct {
3031 // Type is the type of change (e.g., "feat", "fix", "docs").
31- Type string
32- // Scope is the scope of the change.
33- Scope string
34- // Description is the short summary of the change.
35- Description string
32+ Type string `yaml:"type" json:"type"`
33+ // Subject is the short summary of the change.
34+ Subject string `yaml:"subject" json:"subject"`
3635 // Body is the long-form description of the change.
37- Body string
36+ Body string `yaml:"body" json:"body"`
3837 // LibraryID is the library ID the commit associated with.
39- LibraryID string
38+ LibraryID string `yaml:"-" json:"-"`
39+ // Scope is the scope of the change.
40+ Scope string `yaml:"-" json:"-"`
4041 // Footers contain metadata (e.g,"BREAKING CHANGE", "Reviewed-by").
41- Footers map [string ]string
42+ Footers map [string ]string `yaml:"-" json:"-"`
4243 // IsBreaking indicates if the commit introduces a breaking change.
43- IsBreaking bool
44+ IsBreaking bool `yaml:"-" json:"-"`
4445 // IsNested indicates if the commit is a nested commit.
45- IsNested bool
46+ IsNested bool `yaml:"-" json:"-"`
4647 // SHA is the full commit hash.
47- SHA string
48+ SHA string `yaml:"-" json:"-"`
4849 // When is the timestamp of the commit.
49- When time.Time
50+ When time.Time `yaml:"-" json:"-"`
51+ }
52+
53+ // MarshalJSON implements a custom JSON marshaler for ConventionalCommit.
54+ func (c * ConventionalCommit ) MarshalJSON () ([]byte , error ) {
55+ type Alias ConventionalCommit
56+ return json .Marshal (& struct {
57+ * Alias
58+ PiperCLNumber string `json:"piper_cl_number,omitempty"`
59+ SourceCommitHash string `json:"source_commit_hash,omitempty"`
60+ }{
61+ Alias : (* Alias )(c ),
62+ PiperCLNumber : c .Footers ["PiperOrigin-RevId" ],
63+ SourceCommitHash : c .Footers ["git-commit-hash" ],
64+ })
5065}
5166
5267const breakingChangeKey = "BREAKING CHANGE"
@@ -260,15 +275,15 @@ func parseSimpleCommit(commitPart commitPart, commit *gitrepo.Commit, libraryID
260275 footers , footerIsBreaking := parseFooters (footerLines )
261276
262277 return & ConventionalCommit {
263- Type : header .Type ,
264- Scope : header .Scope ,
265- Description : header .Description ,
266- Body : strings .TrimSpace (strings .Join (bodyLines , "\n " )),
267- LibraryID : libraryID ,
268- Footers : footers ,
269- IsBreaking : header .IsBreaking || footerIsBreaking ,
270- IsNested : commitPart .isNested ,
271- SHA : commit .Hash .String (),
272- When : commit .When ,
278+ Type : header .Type ,
279+ Scope : header .Scope ,
280+ Subject : header .Description ,
281+ Body : strings .TrimSpace (strings .Join (bodyLines , "\n " )),
282+ LibraryID : libraryID ,
283+ Footers : footers ,
284+ IsBreaking : header .IsBreaking || footerIsBreaking ,
285+ IsNested : commitPart .isNested ,
286+ SHA : commit .Hash .String (),
287+ When : commit .When ,
273288 }, nil
274289}
0 commit comments