Skip to content

Commit

Permalink
Notification worker uses now pkg.BuildURL (artifacthub#668)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
  • Loading branch information
tegioz authored Sep 24, 2020
1 parent 663a6f2 commit 21b6152
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
6 changes: 3 additions & 3 deletions cmd/hub/handlers/pkg/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (h *Handlers) RssFeed(w http.ResponseWriter, r *http.Request) {
Title: s.Version,
Description: fmt.Sprintf("%s %s", p.NormalizedName, s.Version),
Created: time.Unix(s.CreatedAt, 0),
Link: &feeds.Link{Href: BuildPackageURL(baseURL, p, s.Version)},
Link: &feeds.Link{Href: BuildURL(baseURL, p, s.Version)},
})
}
sort.Slice(feed.Items, func(i, j int) bool {
Expand Down Expand Up @@ -339,8 +339,8 @@ func buildSearchInput(qs url.Values) (*hub.SearchPackageInput, error) {
}, nil
}

// BuildPackageURL builds the url of a given package.
func BuildPackageURL(baseURL string, p *hub.Package, version string) string {
// BuildURL builds the url of a given package.
func BuildURL(baseURL string, p *hub.Package, version string) string {
pkgPath := fmt.Sprintf("/packages/%s/%s/%s",
hub.GetKindName(p.Repository.Kind),
p.Repository.Name,
Expand Down
2 changes: 1 addition & 1 deletion cmd/hub/handlers/pkg/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ func TestBuildPackageURL(t *testing.T) {
for _, tc := range testCases {
tc := tc
t.Run(tc.expectedPkgURL, func(t *testing.T) {
pkgURL := BuildPackageURL(baseURL, tc.p, tc.version)
pkgURL := BuildURL(baseURL, tc.p, tc.version)
assert.Equal(t, tc.expectedPkgURL, pkgURL)
})
}
Expand Down
9 changes: 2 additions & 7 deletions internal/notification/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"text/template"
"time"

"github.com/artifacthub/hub/cmd/hub/handlers/pkg"
"github.com/artifacthub/hub/internal/email"
"github.com/artifacthub/hub/internal/hub"
"github.com/artifacthub/hub/internal/util"
Expand Down Expand Up @@ -266,12 +267,6 @@ func (w *Worker) preparePkgNotificationTemplateData(
if publisher == "" {
publisher = p.Repository.UserAlias
}
packagePath := fmt.Sprintf("/packages/%s/%s/%s/%s",
hub.GetKindName(p.Repository.Kind),
p.Repository.Name,
p.NormalizedName,
e.PackageVersion,
)

return &hub.PackageNotificationTemplateData{
BaseURL: w.baseURL,
Expand All @@ -283,7 +278,7 @@ func (w *Worker) preparePkgNotificationTemplateData(
"name": p.Name,
"version": p.Version,
"logoImageID": p.LogoImageID,
"url": w.baseURL + packagePath,
"url": pkg.BuildURL(w.baseURL, p, e.PackageVersion),
"repository": map[string]interface{}{
"kind": hub.GetKindName(p.Repository.Kind),
"name": p.Repository.Name,
Expand Down

0 comments on commit 21b6152

Please sign in to comment.