Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Jun 7, 2024
1 parent 1cae9a8 commit c59d5e7
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion _registry/ignite.apps.explorer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion _registry/ignite.apps.hermes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions _registry/ignite.apps.marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion _registry/ignite.apps.rollkit.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion _registry/ignite.apps.wasm.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions marketplace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Marketplace App
3 changes: 1 addition & 2 deletions marketplace/cmd/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
36 changes: 32 additions & 4 deletions marketplace/pkg/xgithub/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions marketplace/registry/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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(),
Expand Down

0 comments on commit c59d5e7

Please sign in to comment.