From 870511c8c333ab89a87f0819e1bd91c526aeb05a Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Mon, 9 Oct 2023 12:38:45 -0700 Subject: [PATCH 1/2] Allow overriding the previous commit for a dependency Signed-off-by: Derek McGowan --- main.go | 13 ++++++++++--- template.go | 2 +- util.go | 23 ++++++++++++++++++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 85d0cdb..e2db5c7 100644 --- a/main.go +++ b/main.go @@ -58,6 +58,7 @@ type dependency struct { Sha string Previous string GitURL string + New bool } type download struct { @@ -75,6 +76,10 @@ type projectRename struct { New string `toml:"new"` } +type dependencyOverride struct { + Previous string `toml:"previous"` +} + type contributor struct { Name string Email string @@ -101,9 +106,10 @@ type release struct { //CategoryLabels []string `toml:"category_labels"` // dependency options - MatchDeps string `toml:"match_deps"` - RenameDeps map[string]projectRename `toml:"rename_deps"` - IgnoreDeps []string `toml:"ignore_deps"` + MatchDeps string `toml:"match_deps"` + RenameDeps map[string]projectRename `toml:"rename_deps"` + IgnoreDeps []string `toml:"ignore_deps"` + OverrideDeps map[string]dependencyOverride `toml:"override_deps"` // generated fields Changes []projectChange @@ -255,6 +261,7 @@ This tool should be ran from the root of the project repository for a new releas if err != nil { return err } + overrideDependencies(current, r.OverrideDeps) previous, err := parseDependencies(r.Previous) if err != nil { diff --git a/template.go b/template.go index e4afe99..238b780 100644 --- a/template.go +++ b/template.go @@ -59,7 +59,7 @@ https://github.com/{{.GithubRepo}}/issues. ### Dependency Changes {{if .Dependencies}} {{- range $dep := .Dependencies}} -* **{{$dep.Name}}** {{if $dep.Previous}}{{$dep.Previous}} -> {{$dep.Ref}}{{else}}{{$dep.Ref}} **_new_**{{end}} +* **{{$dep.Name}}** {{if $dep.New}}{{$dep.Ref}} **_new_**{{else}}{{$dep.Previous}} -> {{$dep.Ref}}{{end}} {{- end}} {{- else}} This release has no dependency changes diff --git a/util.go b/util.go index 9b21a8d..a8363d0 100644 --- a/util.go +++ b/util.go @@ -465,6 +465,20 @@ func git(args ...string) ([]byte, error) { return o, nil } +func overrideDependencies(deps []dependency, overrides map[string]dependencyOverride) { + if len(overrides) == 0 { + return + } + for i := range deps { + if or, ok := overrides[deps[i].Name]; ok { + if or.Previous != "" { + logrus.Debugf("Overrode previous version of %s to %s", deps[i].Name, or.Previous) + deps[i].Previous = or.Previous + } + } + } +} + func renameDependencies(deps []dependency, renames map[string]projectRename) { if len(renames) == 0 { return @@ -503,11 +517,18 @@ func getUpdatedDeps(previous, deps []dependency, ignored []string, cache Cache) d, ok := pm[name] if !ok { // it is a new dep and should be noted + c.New = true updated = append(updated, c) continue } // it exists, see if its updated - if d.Ref != c.Ref { + if c.Previous != "" { + // Handle previous override + if c.Previous != c.Ref { + logrus.Debugf("Override dependency: %q %s -> %s", c.Name, c.Previous, c.Ref) + updated = append(updated, c) + } + } else if d.Ref != c.Ref { if d.Sha == "" { if d.GitURL == "" { gitURL, err := resolveGitURL(name, cache) From 25e63787f6958e61cf5b2240d7c6405705c68ffa Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Mon, 9 Oct 2023 13:46:30 -0700 Subject: [PATCH 2/2] Add comments to release-tool options Signed-off-by: Derek McGowan --- main.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index e2db5c7..b9cbf8f 100644 --- a/main.go +++ b/main.go @@ -105,10 +105,17 @@ type release struct { //HighlightLabel string `toml:"highlight_label"` //CategoryLabels []string `toml:"category_labels"` - // dependency options - MatchDeps string `toml:"match_deps"` - RenameDeps map[string]projectRename `toml:"rename_deps"` - IgnoreDeps []string `toml:"ignore_deps"` + // MatchDeps provides a regex string to match dependencies to be + // included as part of the changelog. + MatchDeps string `toml:"match_deps"` + // RenameDeps provides a way to match dependencies which have been + // renamed from the old name to the new name. + RenameDeps map[string]projectRename `toml:"rename_deps"` + // IgnoreDeps are dependencies to ignore from the output. + IgnoreDeps []string `toml:"ignore_deps"` + // OverrideDeps is used to override the current dependency calculated + // from the dependency list. This can be used to set the previous version + // which could be missing for new or moved dependencies. OverrideDeps map[string]dependencyOverride `toml:"override_deps"` // generated fields