Skip to content

Commit

Permalink
Title and body strings for when manifest is "" or is github repo url
Browse files Browse the repository at this point in the history
  • Loading branch information
davegaeddert committed Sep 12, 2019
1 parent 3593faf commit f8573e1
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/schema/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ func (s *Dependencies) generateTitle() string {
dep := dependencies[name]
installed := manifest.Current.Dependencies[name].Constraint
updated := dep.Constraint
return fmt.Sprintf("Update %v in %v from %v to %v", name, manifestPath, installed, updated)
inManifest := ""
if manifestPath != "" {
inManifest = fmt.Sprintf(" in %s", manifestPath)
}
return fmt.Sprintf("Update %s%s from %s to %s", dependencyNameForDisplay(name), inManifest, installed, updated)
}

// more than 1 dependency
Expand Down
24 changes: 24 additions & 0 deletions pkg/schema/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ func TestGenerateTitleWithSingleDependency(t *testing.T) {
}
}

func TestGenerateTitleWithSingleDependencyNoManifestName(t *testing.T) {
title, err := generateTitleFromFilename("./testdata/single_dependency_empty_manifest.json")
if err != nil {
t.Error(err)
}
if title != "Update dropseed/pullrequest from 0.1.0 to 0.3.0" {
t.Error("Title does not match expected: ", title)
}
}

// func TestGenerateTitleWithTwoDependencies(t *testing.T) {
// title, err := generateTitleFromFilename("./testdata/two_dependencies.json")
// if err != nil {
Expand Down Expand Up @@ -103,6 +113,20 @@ func TestGenerateBodyWithSingleDependency(t *testing.T) {
}
}

func TestGenerateBodyWithSingleDependencyEmptyManifest(t *testing.T) {
body, err := generateBodyFromFilename("./testdata/single_dependency_empty_manifest.json")
if err != nil {
t.Error(err)
}
expected, err := ioutil.ReadFile("./testdata/single_body_empty_manifest.txt")
if err != nil {
panic(err)
}
if body != string(expected) {
t.Error("Body does not match expected: ", body)
}
}

func TestGenerateBodyWithTwoDependencies(t *testing.T) {
body, err := generateBodyFromFilename("./testdata/two_dependencies.json")
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/schema/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,9 @@ func (md *ManifestDependency) Validate() error {
func (manifest *Manifest) GetSummaryLineForDependencyName(name, manifestPath string) (string, error) {
currentDependency := manifest.Current.Dependencies[name]
updatedDependency := manifest.Updated.Dependencies[name]
return fmt.Sprintf("- `%v` in `%v` from \"%v\" to \"%v\"", name, manifestPath, currentDependency.Constraint, updatedDependency.Constraint), nil
inManifest := ""
if manifestPath != "" {
inManifest = fmt.Sprintf(" in `%s`", manifestPath)
}
return fmt.Sprintf("- `%s`%s from \"%s\" to \"%s\"", dependencyNameForDisplay(name), inManifest, currentDependency.Constraint, updatedDependency.Constraint), nil
}
3 changes: 3 additions & 0 deletions pkg/schema/testdata/single_body_empty_manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The following dependencies have been updated by [dependencies.io](https://www.dependencies.io/):

- `dropseed/pullrequest` from "0.1.0" to "0.3.0"
22 changes: 22 additions & 0 deletions pkg/schema/testdata/single_dependency_empty_manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"manifests": {
"": {
"current": {
"dependencies": {
"https://github.com/dropseed/pullrequest.git": {
"source": "go",
"constraint": "0.1.0"
}
}
},
"updated": {
"dependencies": {
"https://github.com/dropseed/pullrequest.git": {
"source": "go",
"constraint": "0.3.0"
}
}
}
}
}
}
30 changes: 30 additions & 0 deletions pkg/schema/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package schema

import "strings"

func dependencyNameForDisplay(name string) string {

prefixes := []string{
"https://github.com/",
"https://gitlab.com/",
}

for _, prefix := range prefixes {
if strings.HasPrefix(name, prefix) {
name = name[len(prefix):]
}
}

suffixes := []string{
".git/",
".git",
}

for _, suffix := range suffixes {
if strings.HasSuffix(name, suffix) {
name = name[:len(name)-len(suffix)]
}
}

return name
}

0 comments on commit f8573e1

Please sign in to comment.