Skip to content
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

Allow overriding the previous commit for a dependency #43

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type dependency struct {
Sha string
Previous string
GitURL string
New bool
}

type download struct {
Expand All @@ -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
Expand All @@ -100,10 +105,18 @@ type release struct {
//HighlightLabel string `toml:"highlight_label"`
//CategoryLabels []string `toml:"category_labels"`

// dependency options
MatchDeps string `toml:"match_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 []string `toml:"ignore_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
Changes []projectChange
Expand Down Expand Up @@ -255,6 +268,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 {
Expand Down
2 changes: 1 addition & 1 deletion template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down