Skip to content

Commit

Permalink
expose api generate component release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Nov 17, 2022
1 parent 6b1832f commit 3890607
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 107 deletions.
3 changes: 1 addition & 2 deletions internal/commands/release_notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/go-git/go-git/v5"
"github.com/google/go-github/v40/github"
"github.com/pivotal-cf/jhanda"
"github.com/pivotal-cf/kiln/internal/component"
"github.com/pivotal-cf/kiln/internal/release"
)

Expand Down Expand Up @@ -273,7 +272,7 @@ func getGithubRemoteRepoOwnerAndName(repo *git.Repository) (string, string, erro
return "", "", fmt.Errorf("remote github URL not found for repo")
}

repoOwner, repoName, err := component.OwnerAndRepoFromGitHubURI(remoteURL)
repoOwner, repoName, err := gh.OwnerAndRepoFromURI(remoteURL)
if err != nil {
return "", "", err
}
Expand Down
7 changes: 3 additions & 4 deletions internal/commands/release_notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"
"time"

"github.com/pivotal-cf/kiln/internal/component"
"github.com/pivotal-cf/kiln/pkg/cargo"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -89,13 +88,13 @@ func TestReleaseNotes_Execute(t *testing.T) {
OS: "fruit-tree", Version: "40000.2",
},
Components: []release.ComponentData{
{Lock: cargo.ComponentLock{Name: "banana", Version: "1.2.0"}, Releases: []*github.RepositoryRelease{
{ComponentLock: cargo.ComponentLock{Name: "banana", Version: "1.2.0"}, Releases: []*github.RepositoryRelease{
{TagName: strPtr("1.2.0"), Body: strPtr("peal\nis\nyellow")},
{TagName: strPtr("1.1.1"), Body: strPtr("remove from bunch")},
}},
{Lock: cargo.ComponentLock{Name: "lemon", Version: "1.1.0"}},
{ComponentLock: cargo.ComponentLock{Name: "lemon", Version: "1.1.0"}},
},
Bumps: component.BumpList{
Bumps: cargo.BumpList{
{Name: "banana", FromVersion: "1.1.0", ToVersion: "1.2.0"},
},
}, nil
Expand Down
7 changes: 4 additions & 3 deletions internal/component/github_release_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/pivotal-cf/kiln/internal/gh"
"io"
"log"
"net/http"
Expand Down Expand Up @@ -90,7 +91,7 @@ type ReleaseByTagGetter interface {
}

func (grs GithubReleaseSource) GetGithubReleaseWithTag(ctx context.Context, s Spec) (*github.RepositoryRelease, error) {
repoOwner, repoName, err := OwnerAndRepoFromGitHubURI(s.GitHubRepository)
repoOwner, repoName, err := gh.OwnerAndRepoFromURI(s.GitHubRepository)
if err != nil {
return nil, ErrNotFound
}
Expand All @@ -117,7 +118,7 @@ func (grs GithubReleaseSource) GetLatestMatchingRelease(ctx context.Context, s S
return nil, fmt.Errorf("expected version to be a constraint")
}

repoOwner, repoName, err := OwnerAndRepoFromGitHubURI(s.GitHubRepository)
repoOwner, repoName, err := gh.OwnerAndRepoFromURI(s.GitHubRepository)
if err != nil {
return nil, ErrNotFound
}
Expand Down Expand Up @@ -221,7 +222,7 @@ func (grs GithubReleaseSource) getLockFromRelease(ctx context.Context, r *github
}

func (grs GithubReleaseSource) getReleaseSHA1(ctx context.Context, s Spec, id int64) (string, error) {
repoOwner, repoName, err := OwnerAndRepoFromGitHubURI(s.GitHubRepository)
repoOwner, repoName, err := gh.OwnerAndRepoFromURI(s.GitHubRepository)
if err != nil {
return "", fmt.Errorf("could not parse repository name: %v", err)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/component/github_release_source_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ func TestGithubReleaseSource_downloadRelease(t *testing.T) {
please.Expect(local.LocalPath).To(BeAnExistingFile(), "it finds the created asset file")
please.Expect(local.SHA1).To(Equal("3a2be7b07a1a19072bf54c95a8c4a3fe0cdb35d4"))
}

func ptr[T any](v T) *T { return &v }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package component
package gh

import (
"errors"
Expand All @@ -9,9 +9,9 @@ import (
"strings"
)

// OwnerAndRepoFromGitHubURI is from the github-release-source branch
// OwnerAndRepoFromURI is from the github-release-source branch
// once that one is merged we should that one instead of this one
func OwnerAndRepoFromGitHubURI(urlStr string) (owner, repo string, err error) {
func OwnerAndRepoFromURI(urlStr string) (owner, repo string, err error) {
defer func() {
if err != nil {
err = fmt.Errorf("failed to parse owner and repo name from URI %q: %w", urlStr, err)
Expand Down
5 changes: 3 additions & 2 deletions internal/release/fakes/releases_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions internal/release/notes_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import (
"github.com/google/go-github/v40/github"
"gopkg.in/yaml.v2"

"github.com/pivotal-cf/kiln/internal/component"
"github.com/pivotal-cf/kiln/pkg/cargo"
"github.com/pivotal-cf/kiln/pkg/history"
)

type ComponentData struct {
component.Lock
cargo.ComponentLock
Releases []*github.RepositoryRelease
}

Expand All @@ -48,7 +47,7 @@ type NotesData struct {

Issues []*github.Issue
Components []ComponentData
Bumps component.BumpList
Bumps cargo.BumpList

Stemcell cargo.Stemcell
}
Expand Down Expand Up @@ -146,7 +145,7 @@ type fetchNotesData struct {
repository *git.Repository

issuesService
releasesService component.RepositoryReleaseLister
releasesService cargo.RepositoryReleaseLister

repoOwner, repoName,
kilnfilePath,
Expand All @@ -163,7 +162,7 @@ func (r fetchNotesData) fetch(ctx context.Context) (NotesData, error) {

data := NotesData{
Version: finalVersion,
Bumps: component.CalculateBumps(finalKilnfileLock.Releases, initialKilnfileLock.Releases),
Bumps: cargo.CalculateBumps(finalKilnfileLock.Releases, initialKilnfileLock.Releases),
Stemcell: finalKilnfileLock.Stemcell,
}

Expand All @@ -179,8 +178,8 @@ func (r fetchNotesData) fetch(ctx context.Context) (NotesData, error) {

for _, c := range finalKilnfileLock.Releases {
data.Components = append(data.Components, ComponentData{
Lock: c,
Releases: data.Bumps.ForLock(c).Releases,
ComponentLock: c,
Releases: data.Bumps.ForLock(c).Releases,
})
}

Expand Down Expand Up @@ -273,11 +272,11 @@ type issuesService interface {
// The function can be tested by generating release notes for a tile with issue ids and a milestone set. The happy path
// test for Execute does not set GithubToken intentionally so this code is not triggered and Execute does not actually
// reach out to GitHub.
func (r fetchNotesData) fetchIssuesAndReleaseNotes(ctx context.Context, finalKF, wtKF cargo.Kilnfile, bumpList component.BumpList, issuesQuery IssuesQuery) ([]*github.Issue, component.BumpList, error) {
func (r fetchNotesData) fetchIssuesAndReleaseNotes(ctx context.Context, finalKF, wtKF cargo.Kilnfile, bumpList cargo.BumpList, issuesQuery IssuesQuery) ([]*github.Issue, cargo.BumpList, error) {
if r.releasesService == nil || r.issuesService == nil {
return nil, bumpList, nil
}
bumpList, err := component.ReleaseNotes(ctx, r.releasesService, setEmptyComponentGitHubRepositoryFromOtherKilnfile(finalKF, wtKF), bumpList)
bumpList, err := cargo.ReleaseNotes(ctx, r.releasesService, setEmptyComponentGitHubRepositoryFromOtherKilnfile(finalKF, wtKF), bumpList)
if err != nil {
return nil, nil, err
}
Expand Down
99 changes: 49 additions & 50 deletions internal/release/notes_page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/go-git/go-git/v5/storage/memory"
"github.com/google/go-github/v40/github"

"github.com/pivotal-cf/kiln/internal/component"
"github.com/pivotal-cf/kiln/pkg/cargo"
)

Expand Down Expand Up @@ -68,56 +67,56 @@ func TestParseNotesPage(t *testing.T) {
OS: "ubuntu-xenial", Version: "456.0",
},
Components: []ComponentData{
{Lock: component.Lock{Name: "backup-and-restore-sdk", Version: "1.18.26"}},
{Lock: component.Lock{Name: "binary-offline-buildpack", Version: "1.0.40"}},
{Lock: component.Lock{Name: "bosh-dns-aliases", Version: "0.0.3"}},
{Lock: component.Lock{Name: "bosh-system-metrics-forwarder", Version: "0.0.20"}},
{Lock: component.Lock{Name: "bpm", Version: "1.1.15"}},
{Lock: component.Lock{Name: "capi", Version: "1.84.20"}},
{Lock: component.Lock{Name: "cf-autoscaling", Version: "241"}},
{Lock: component.Lock{Name: "cf-backup-and-restore", Version: "0.0.11"}},
{Lock: component.Lock{Name: "cf-cli", Version: "1.32.0"}},
{Lock: component.Lock{Name: "cf-networking", Version: "2.40.0"}},
{Lock: component.Lock{Name: "cf-smoke-tests", Version: "40.0.134"}},
{Lock: component.Lock{Name: "cf-syslog-drain", Version: "10.2.5"}},
{Lock: component.Lock{Name: "cflinuxfs3", Version: "0.264.0"}},
{Lock: component.Lock{Name: "credhub", Version: "2.5.13"}},
{Lock: component.Lock{Name: "diego", Version: "2.53.0"}},
{Lock: component.Lock{Name: "dotnet-core-offline-buildpack", Version: "2.3.36"}},
{Lock: component.Lock{Name: "garden-runc", Version: "1.19.30"}},
{Lock: component.Lock{Name: "go-offline-buildpack", Version: "1.9.37"}},
{Lock: component.Lock{Name: "haproxy", Version: "9.6.1"}},
{Lock: component.Lock{Name: "istio", Version: "1.3.0"}},
{Lock: component.Lock{Name: "java-offline-buildpack", Version: "4.42"}},
{Lock: component.Lock{Name: "leadership-election", Version: "1.4.2"}},
{Lock: component.Lock{Name: "log-cache", Version: "2.1.17"}},
{Lock: component.Lock{Name: "loggregator-agent", Version: "3.21.18"}},
{Lock: component.Lock{Name: "loggregator", Version: "105.6.8"}},
{Lock: component.Lock{Name: "mapfs", Version: "1.2.4"}},
{Lock: component.Lock{Name: "metric-registrar", Version: "1.1.9"}},
{Lock: component.Lock{Name: "mysql-monitoring", Version: "9.7.0"}},
{Lock: component.Lock{Name: "nats", Version: "40"}},
{Lock: component.Lock{Name: "nfs-volume", Version: "2.3.10"}},
{Lock: component.Lock{Name: "nginx-offline-buildpack", Version: "1.1.32"}},
{Lock: component.Lock{Name: "nodejs-offline-buildpack", Version: "1.7.63"}},
{Lock: component.Lock{Name: "notifications-ui", Version: "39"}},
{Lock: component.Lock{Name: "notifications", Version: "62"}},
{Lock: component.Lock{Name: "php-offline-buildpack", Version: "4.4.48"}},
{Lock: component.Lock{Name: "push-apps-manager-release", Version: "670.0.29"}},
{Lock: component.Lock{Name: "push-usage-service-release", Version: "670.0.36"}},
{Lock: component.Lock{Name: "pxc", Version: "0.39.0"}},
{Lock: component.Lock{Name: "python-offline-buildpack", Version: "1.7.47"}},
{Lock: component.Lock{Name: "r-offline-buildpack", Version: "1.1.23"}},
{Lock: component.Lock{Name: "routing", Version: "0.226.0"}},
{Lock: component.Lock{Name: "ruby-offline-buildpack", Version: "1.8.48"}},
{Lock: component.Lock{Name: "silk", Version: "2.40.0"}},
{Lock: component.Lock{Name: "smb-volume", Version: "3.0.1"}},
{Lock: component.Lock{Name: "staticfile-offline-buildpack", Version: "1.5.26"}},
{Lock: component.Lock{Name: "statsd-injector", Version: "1.11.16"}},
{Lock: component.Lock{Name: "syslog", Version: "11.7.5"}},
{Lock: component.Lock{Name: "uaa", Version: "73.4.32"}},
{ComponentLock: cargo.ComponentLock{Name: "backup-and-restore-sdk", Version: "1.18.26"}},
{ComponentLock: cargo.ComponentLock{Name: "binary-offline-buildpack", Version: "1.0.40"}},
{ComponentLock: cargo.ComponentLock{Name: "bosh-dns-aliases", Version: "0.0.3"}},
{ComponentLock: cargo.ComponentLock{Name: "bosh-system-metrics-forwarder", Version: "0.0.20"}},
{ComponentLock: cargo.ComponentLock{Name: "bpm", Version: "1.1.15"}},
{ComponentLock: cargo.ComponentLock{Name: "capi", Version: "1.84.20"}},
{ComponentLock: cargo.ComponentLock{Name: "cf-autoscaling", Version: "241"}},
{ComponentLock: cargo.ComponentLock{Name: "cf-backup-and-restore", Version: "0.0.11"}},
{ComponentLock: cargo.ComponentLock{Name: "cf-cli", Version: "1.32.0"}},
{ComponentLock: cargo.ComponentLock{Name: "cf-networking", Version: "2.40.0"}},
{ComponentLock: cargo.ComponentLock{Name: "cf-smoke-tests", Version: "40.0.134"}},
{ComponentLock: cargo.ComponentLock{Name: "cf-syslog-drain", Version: "10.2.5"}},
{ComponentLock: cargo.ComponentLock{Name: "cflinuxfs3", Version: "0.264.0"}},
{ComponentLock: cargo.ComponentLock{Name: "credhub", Version: "2.5.13"}},
{ComponentLock: cargo.ComponentLock{Name: "diego", Version: "2.53.0"}},
{ComponentLock: cargo.ComponentLock{Name: "dotnet-core-offline-buildpack", Version: "2.3.36"}},
{ComponentLock: cargo.ComponentLock{Name: "garden-runc", Version: "1.19.30"}},
{ComponentLock: cargo.ComponentLock{Name: "go-offline-buildpack", Version: "1.9.37"}},
{ComponentLock: cargo.ComponentLock{Name: "haproxy", Version: "9.6.1"}},
{ComponentLock: cargo.ComponentLock{Name: "istio", Version: "1.3.0"}},
{ComponentLock: cargo.ComponentLock{Name: "java-offline-buildpack", Version: "4.42"}},
{ComponentLock: cargo.ComponentLock{Name: "leadership-election", Version: "1.4.2"}},
{ComponentLock: cargo.ComponentLock{Name: "log-cache", Version: "2.1.17"}},
{ComponentLock: cargo.ComponentLock{Name: "loggregator-agent", Version: "3.21.18"}},
{ComponentLock: cargo.ComponentLock{Name: "loggregator", Version: "105.6.8"}},
{ComponentLock: cargo.ComponentLock{Name: "mapfs", Version: "1.2.4"}},
{ComponentLock: cargo.ComponentLock{Name: "metric-registrar", Version: "1.1.9"}},
{ComponentLock: cargo.ComponentLock{Name: "mysql-monitoring", Version: "9.7.0"}},
{ComponentLock: cargo.ComponentLock{Name: "nats", Version: "40"}},
{ComponentLock: cargo.ComponentLock{Name: "nfs-volume", Version: "2.3.10"}},
{ComponentLock: cargo.ComponentLock{Name: "nginx-offline-buildpack", Version: "1.1.32"}},
{ComponentLock: cargo.ComponentLock{Name: "nodejs-offline-buildpack", Version: "1.7.63"}},
{ComponentLock: cargo.ComponentLock{Name: "notifications-ui", Version: "39"}},
{ComponentLock: cargo.ComponentLock{Name: "notifications", Version: "62"}},
{ComponentLock: cargo.ComponentLock{Name: "php-offline-buildpack", Version: "4.4.48"}},
{ComponentLock: cargo.ComponentLock{Name: "push-apps-manager-release", Version: "670.0.29"}},
{ComponentLock: cargo.ComponentLock{Name: "push-usage-service-release", Version: "670.0.36"}},
{ComponentLock: cargo.ComponentLock{Name: "pxc", Version: "0.39.0"}},
{ComponentLock: cargo.ComponentLock{Name: "python-offline-buildpack", Version: "1.7.47"}},
{ComponentLock: cargo.ComponentLock{Name: "r-offline-buildpack", Version: "1.1.23"}},
{ComponentLock: cargo.ComponentLock{Name: "routing", Version: "0.226.0"}},
{ComponentLock: cargo.ComponentLock{Name: "ruby-offline-buildpack", Version: "1.8.48"}},
{ComponentLock: cargo.ComponentLock{Name: "silk", Version: "2.40.0"}},
{ComponentLock: cargo.ComponentLock{Name: "smb-volume", Version: "3.0.1"}},
{ComponentLock: cargo.ComponentLock{Name: "staticfile-offline-buildpack", Version: "1.5.26"}},
{ComponentLock: cargo.ComponentLock{Name: "statsd-injector", Version: "1.11.16"}},
{ComponentLock: cargo.ComponentLock{Name: "syslog", Version: "11.7.5"}},
{ComponentLock: cargo.ComponentLock{Name: "uaa", Version: "73.4.32"}},
},
Bumps: component.BumpList{
Bumps: cargo.BumpList{
{Name: "backup-and-restore-sdk", ToVersion: "1.18.26"},
{Name: "bpm", ToVersion: "1.1.15"},
{Name: "capi", ToVersion: "1.84.20"},
Expand Down
2 changes: 1 addition & 1 deletion internal/release/notes_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Test_defaultReleaseNotesTemplate(t *testing.T) {
Version: semver.MustParse("0.0"),
Components: []ComponentData{
{
Lock: component.Lock{Name: "banana", Version: "1.2"},
ComponentLock: component.Lock{Name: "banana", Version: "1.2"},
Releases: []*github.RepositoryRelease{
{TagName: strPtr("1.1"), Body: strPtr("\n ")},
{TagName: strPtr("1.2"), Body: strPtr("")},
Expand Down
Loading

0 comments on commit 3890607

Please sign in to comment.