Skip to content

Commit

Permalink
Add short overview for multiple updates in one manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
davegaeddert committed Jan 5, 2022
1 parent 9c0fd2f commit 6ac63f7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
4 changes: 2 additions & 2 deletions internal/runner/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func TestCommitMessageSubjectBodyTemplates(t *testing.T) {
if err := checkRender("single_dependency", "{{.SubjectAndBody}}", "Update pullrequest from 0.1.0 to 0.3.0"); err != nil {
t.Error(err)
}
if err := checkRender("two_dependencies", "{{.SubjectAndBody}}", "Update 2 dependencies from go, pip\n\n- `pullrequest` in `requirements.txt` from 0.1.0 to 0.3.0\n- `requests` in `requirements.txt` from 0.1.0 to 0.3.0"); err != nil {
if err := checkRender("two_dependencies", "{{.SubjectAndBody}}", "Update requirements.txt (pullrequest and requests)\n\n- `pullrequest` in `requirements.txt` from 0.1.0 to 0.3.0\n- `requests` in `requirements.txt` from 0.1.0 to 0.3.0"); err != nil {
t.Error(err)
}
if err := checkRender("single_lockfile", "{{.SubjectAndBody}}", "Update yarn.lock (postcss-cli, tailwindcss)\n\n- `yarn.lock` was updated (including 2 direct and 44 transitive dependencies)\n - `postcss-cli` was updated from 6.1.2 to 6.1.3\n - `tailwindcss` was updated from 1.0.1 to 1.1.2"); err != nil {
if err := checkRender("single_lockfile", "{{.SubjectAndBody}}", "Update yarn.lock (postcss-cli and tailwindcss)\n\n- `yarn.lock` was updated (including 2 direct and 44 transitive dependencies)\n - `postcss-cli` was updated from 6.1.2 to 6.1.3\n - `tailwindcss` was updated from 1.0.1 to 1.1.2"); err != nil {
t.Error(err)
}
}
20 changes: 10 additions & 10 deletions internal/schemaext/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ func TestGenerateTitleWithSingleDependencyNoManifestName(t *testing.T) {
}
}

// func TestGenerateTitleWithTwoDependencies(t *testing.T) {
// title, err := generateTitleFromFilename("./testdata/two_dependencies.json")
// if err != nil {
// t.Error(err)
// }
// if title != "Update 2 dependencies from go, pip" {
// t.Error("Title does not match expected: ", title)
// }
// }
func TestGenerateTitleWithTwoDependencies(t *testing.T) {
title, err := generateTitleFromFilename("./testdata/two_dependencies.json")
if err != nil {
t.Error(err)
}
if title != "Update requirements.txt (pullrequest and requests)" {
t.Error("Title does not match expected: ", title)
}
}

// func TestGenerateTitleNoDependencies(t *testing.T) {
// title, err := generateTitleFromFilename("./testdata/no_dependencies.json")
Expand All @@ -68,7 +68,7 @@ func TestGenerateTitleWithOneLockfile(t *testing.T) {
if err != nil {
t.Error(err)
}
if title != "Update yarn.lock (postcss-cli, tailwindcss)" {
if title != "Update yarn.lock (postcss-cli and tailwindcss)" {
t.Error("Title does not match expected: ", title)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/schemaext/lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func getShortOverviewForLockfile(lockfile *schema.Lockfile) string {
}

if len(direct.Updated) == 2 {
return fmt.Sprintf("%s, %s", direct.Updated[0], direct.Updated[1])
return fmt.Sprintf("%s and %s", direct.Updated[0], direct.Updated[1])
}

return fmt.Sprintf("%s, %s, and %d more", direct.Updated[0], direct.Updated[1], numDirect-2)
Expand Down
23 changes: 4 additions & 19 deletions internal/schemaext/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,11 @@ func TitleForDeps(s *schema.Dependencies) string {
return fmt.Sprintf("Update %s%s from %s to %s", dependencyNameForDisplay(name), inManifest, installed, updated)
}

// more than 1 dependency
// create a "set" of sources
sources := make(map[string]bool)
for _, dep := range dependencies {
source := dep.Source
sources[source] = true
}

// get the keys remaining
sourceNames := []string{}
for k := range sources {
sourceNames = append(sourceNames, k)
if shortOverview := getShortOverviewForManifest(manifest); shortOverview != "" {
return fmt.Sprintf("Update %s (%s)", manifestPath, shortOverview)
} else {
return fmt.Sprintf("Update %s", manifestPath)
}

sort.Strings(sourceNames)

// TODO if > 2 items, put an "and " in front of the last one

return fmt.Sprintf("Update %v dependencies from %v", len(dependencies), strings.Join(sourceNames, ", "))

}

// More than 1 manifest
Expand Down
22 changes: 22 additions & 0 deletions internal/schemaext/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,25 @@ func getSummaryLineForDependencyName(manifest *schema.Manifest, name, manifestPa
}
return fmt.Sprintf("- `%s`%s from %s to %s", dependencyNameForDisplay(name), inManifest, currentDependency.Constraint, updatedDependency.Constraint), nil
}

func getShortOverviewForManifest(manifest *schema.Manifest) string {
names := []string{}
for name := range manifest.Updated.Dependencies {
names = append(names, name)
}
sort.Strings(names)

if len(names) == 0 {
return ""
}

if len(names) == 1 {
return names[0]
}

if len(names) == 2 {
return fmt.Sprintf("%s and %s", names[0], names[1])
}

return fmt.Sprintf("%s, %s, and %d more", names[0], names[1], len(names)-2)
}

0 comments on commit 6ac63f7

Please sign in to comment.