From c59d5e75bd4e1a747a15578b706781883869a08e Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 7 Jun 2024 10:10:51 +0200 Subject: [PATCH] updates --- _registry/ignite.apps.explorer.json | 2 +- _registry/ignite.apps.hermes.json | 2 +- _registry/ignite.apps.marketplace.json | 4 +-- _registry/ignite.apps.rollkit.json | 2 +- _registry/ignite.apps.wasm.json | 2 +- marketplace/README.md | 1 + marketplace/cmd/details.go | 3 +-- marketplace/pkg/xgithub/github.go | 36 +++++++++++++++++++++++--- marketplace/registry/details.go | 6 ++--- 9 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 marketplace/README.md diff --git a/_registry/ignite.apps.explorer.json b/_registry/ignite.apps.explorer.json index c20963d..ce962f0 100644 --- a/_registry/ignite.apps.explorer.json +++ b/_registry/ignite.apps.explorer.json @@ -14,7 +14,7 @@ "github": "jeronimoalbi" } ], - "repositoryUrl": "https://github.com/ignite/apps/explorer", + "repositoryUrl": "https://github.com/ignite/apps", "documentationUrl": "https://github.com/cosmos/gex", "license": { "name": "MIT", diff --git a/_registry/ignite.apps.hermes.json b/_registry/ignite.apps.hermes.json index 1dacf8a..50b1da9 100644 --- a/_registry/ignite.apps.hermes.json +++ b/_registry/ignite.apps.hermes.json @@ -12,7 +12,7 @@ "github": "pantani" } ], - "repositoryUrl": "https://github.com/ignite/apps/hermes", + "repositoryUrl": "https://github.com/ignite/apps", "documentationUrl": "https://github.com/ignite/apps/tree/main/hermes/README.md", "license": { "name": "MIT", diff --git a/_registry/ignite.apps.marketplace.json b/_registry/ignite.apps.marketplace.json index 48bb44a..42577d5 100644 --- a/_registry/ignite.apps.marketplace.json +++ b/_registry/ignite.apps.marketplace.json @@ -12,8 +12,8 @@ "github": "Ehsan-saradar" } ], - "repositoryUrl": "https://github.com/ignite/apps/marketplace", - "documentationUrl": "", + "repositoryUrl": "https://github.com/ignite/apps", + "documentationUrl": "https://github.com/ignite/apps/tree/main/marketplace/README.md", "license": { "name": "MIT", "url": "https://github.com/ignite/apps/blob/main/LICENSE" diff --git a/_registry/ignite.apps.rollkit.json b/_registry/ignite.apps.rollkit.json index a644b2d..6cf2733 100644 --- a/_registry/ignite.apps.rollkit.json +++ b/_registry/ignite.apps.rollkit.json @@ -12,7 +12,7 @@ "github": "julienrbrt" } ], - "repositoryUrl": "https://github.com/ignite/apps/rollkit", + "repositoryUrl": "https://github.com/ignite/apps", "documentationUrl": "https://github.com/ignite/apps/tree/main/rollkit/README.md", "license": { "name": "MIT", diff --git a/_registry/ignite.apps.wasm.json b/_registry/ignite.apps.wasm.json index 1970930..d672011 100644 --- a/_registry/ignite.apps.wasm.json +++ b/_registry/ignite.apps.wasm.json @@ -12,7 +12,7 @@ "github": "pantani" } ], - "repositoryUrl": "https://github.com/ignite/apps/wasm", + "repositoryUrl": "https://github.com/ignite/apps", "documentationUrl": "https://github.com/ignite/apps/blob/main/wasm/README.md", "license": { "name": "MIT", diff --git a/marketplace/README.md b/marketplace/README.md new file mode 100644 index 0000000..f7475c3 --- /dev/null +++ b/marketplace/README.md @@ -0,0 +1 @@ +# Marketplace App diff --git a/marketplace/cmd/details.go b/marketplace/cmd/details.go index 2d2008e..e87b589 100644 --- a/marketplace/cmd/details.go +++ b/marketplace/cmd/details.go @@ -95,8 +95,7 @@ func printAppsTable(repo *registry.AppRepositoryDetails) { printItem(w, "Ignite Version", repo.App.IgniteVersion) fmt.Fprintln(w, installaitonStyle.Render(fmt.Sprintf( - "🚀 Install via: %s", - commandStyle.Render(fmt.Sprintf("ignite app -g install %s", repo.PackageURL)), + "🚀 Install via: %s", commandStyle.Render(fmt.Sprintf("ignite app -g install %s", repo.App.PackageURL)), ))) w.Flush() diff --git a/marketplace/pkg/xgithub/github.go b/marketplace/pkg/xgithub/github.go index 49d1552..24743f9 100644 --- a/marketplace/pkg/xgithub/github.go +++ b/marketplace/pkg/xgithub/github.go @@ -12,6 +12,24 @@ type Client struct { GithubClient *github.Client } +type Options struct { + Branch string +} + +func (o *Options) toGithubOptions() *github.RepositoryContentGetOptions { + return &github.RepositoryContentGetOptions{ + Ref: o.Branch, + } +} + +type Option func(*Options) + +func WithBranch(branch string) Option { + return func(o *Options) { + o.Branch = branch + } +} + // NewClient returns a new GitHub client. func NewClient(accessToken string) *Client { gc := github.NewClient(nil) @@ -33,8 +51,13 @@ func (c *Client) GetRepository(ctx context.Context, owner, name string) (*github } // GetDirectoryFiles lists the files paths in the directory from GitHub given the repository name and the directory path. -func (c *Client) GetDirectoryFiles(ctx context.Context, owner, repo, path string) ([]string, error) { - _, dir, _, err := c.GithubClient.Repositories.GetContents(ctx, owner, repo, path, nil) +func (c *Client) GetDirectoryFiles(ctx context.Context, owner, repo, path string, opts ...Option) ([]string, error) { + options := &Options{} + for _, opt := range opts { + opt(options) + } + + _, dir, _, err := c.GithubClient.Repositories.GetContents(ctx, owner, repo, path, options.toGithubOptions()) if err != nil { return nil, err } @@ -48,8 +71,13 @@ func (c *Client) GetDirectoryFiles(ctx context.Context, owner, repo, path string } // GetFileContent gets the content of the file from GitHub given the repository name and the file path. -func (c *Client) GetFileContent(ctx context.Context, owner, repo, path string) ([]byte, error) { - file, _, _, err := c.GithubClient.Repositories.GetContents(ctx, owner, repo, path, nil) +func (c *Client) GetFileContent(ctx context.Context, owner, repo, path string, opts ...Option) ([]byte, error) { + options := &Options{} + for _, opt := range opts { + opt(options) + } + + file, _, _, err := c.GithubClient.Repositories.GetContents(ctx, owner, repo, path, options.toGithubOptions()) if err != nil { return nil, err } diff --git a/marketplace/registry/details.go b/marketplace/registry/details.go index 66f8084..0d752cb 100644 --- a/marketplace/registry/details.go +++ b/marketplace/registry/details.go @@ -23,7 +23,6 @@ var githubRepoPattern = regexp.MustCompile(`^github\.com\/([a-zA-Z0-9\-_]+)\/([a // AppRepositoryDetails represents the details of an Ignite app repository. type AppRepositoryDetails struct { - PackageURL string Name string Owner string Description string @@ -38,6 +37,7 @@ type AppRepositoryDetails struct { // AppDetails represents the details of an Ignite app. type AppDetails struct { Name string + PackageURL string Description string Path string GoVersion string @@ -64,7 +64,7 @@ func (r Querier) GetAppDetails(ctx context.Context, appName string) (*AppReposit repoOwner, repoName, err := validatePackageURL(appEntry.RepositoryURL) if err != nil { - return nil, errors.Wrap(err, "invalid package URL") + return nil, err } repo, err := r.client.GetRepository(ctx, repoOwner, repoName) @@ -90,6 +90,7 @@ func (r Querier) GetAppDetails(ctx context.Context, appName string) (*AppReposit appDetails = AppDetails{ Name: name, + PackageURL: path.Join(appEntry.RepositoryURL, info.Path), Description: info.Description, Path: info.Path, GoVersion: goMod.Go.Version, @@ -98,7 +99,6 @@ func (r Querier) GetAppDetails(ctx context.Context, appName string) (*AppReposit } result := &AppRepositoryDetails{ - PackageURL: appEntry.RepositoryURL, Name: repo.GetName(), Owner: repo.GetOwner().GetLogin(), Description: repo.GetDescription(),