-
Notifications
You must be signed in to change notification settings - Fork 2
feat(list-packages): List codesphere packages #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Copyright (c) Codesphere Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| all: false | ||
| dir: "{{.InterfaceDir}}" | ||
| force-file-write: true | ||
| filename: "mocks.go" | ||
| formatter: gofmt | ||
| log-level: info | ||
| structname: "{{.Mock}}{{.InterfaceName}}" | ||
| pkgname: "{{.SrcPackageName}}" | ||
| recursive: false | ||
| require-template-schema-exists: true | ||
| template: testify | ||
| template-schema: "{{.Template}}.schema.json" | ||
| packages: | ||
| github.com/codesphere-cloud/oms/internal/env: | ||
| config: | ||
| all: true | ||
| interfaces: | ||
| github.com/codesphere-cloud/oms/internal/portal: | ||
| config: | ||
| all: true | ||
| interfaces: | ||
| github.com/codesphere-cloud/oms/internal/util: | ||
| config: | ||
| all: true | ||
| interfaces: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package cmd_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| func TestCmd(t *testing.T) { | ||
| RegisterFailHandler(Fail) | ||
| RunSpecs(t, "Cmd Suite") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/codesphere-cloud/cs-go/pkg/io" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type ListCmd struct { | ||
| cmd *cobra.Command | ||
| } | ||
|
|
||
| func AddListCmd(rootCmd *cobra.Command, opts GlobalOptions) { | ||
| list := ListCmd{ | ||
| cmd: &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List resources available through OMS", | ||
| Long: io.Long(`List resources managed by or available for OMS, | ||
| eg. available Codesphere packages`), | ||
| }, | ||
| } | ||
| rootCmd.AddCommand(list.cmd) | ||
| AddListPackagesCmd(list.cmd, opts) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/codesphere-cloud/oms/internal/portal" | ||
| "github.com/codesphere-cloud/oms/internal/util" | ||
|
|
||
| "github.com/codesphere-cloud/cs-go/pkg/io" | ||
| "github.com/jedib0t/go-pretty/v6/table" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type ListBuildsCmd struct { | ||
| cmd *cobra.Command | ||
| Opts ListBuildsOpts | ||
| TableWriter util.TableWriter | ||
| } | ||
|
|
||
| type ListBuildsOpts struct { | ||
| GlobalOptions | ||
| Internal bool | ||
| } | ||
|
|
||
| func (c *ListBuildsCmd) RunE(_ *cobra.Command, args []string) error { | ||
| p := portal.NewPortalClient() | ||
| packages, err := p.ListCodespherePackages() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to list codesphere packages: %w", err) | ||
| } | ||
|
|
||
| c.PrintPackagesTable(packages) | ||
| return nil | ||
| } | ||
|
|
||
| func AddListPackagesCmd(list *cobra.Command, opts GlobalOptions) { | ||
| builds := ListBuildsCmd{ | ||
| cmd: &cobra.Command{ | ||
| Use: "packages", | ||
| Short: "List available packages", | ||
| Long: io.Long(`List packages available for download via the OMS portal.`), | ||
| }, | ||
| Opts: ListBuildsOpts{GlobalOptions: opts}, | ||
| TableWriter: util.GetTableWriter(), | ||
| } | ||
|
|
||
| builds.cmd.RunE = builds.RunE | ||
| builds.cmd.Flags().BoolVarP(&builds.Opts.Internal, "list-internal", "i", false, "List internal packages") | ||
| _ = builds.cmd.Flags().MarkHidden("list-internal") | ||
|
|
||
| list.AddCommand(builds.cmd) | ||
| } | ||
|
|
||
| func (c *ListBuildsCmd) PrintPackagesTable(packages portal.CodesphereBuilds) { | ||
| c.TableWriter.AppendHeader(table.Row{"Int", "Version", "Build Date", "Hash", "Artifacts"}) | ||
|
|
||
| for _, build := range packages.Builds { | ||
| if !c.Opts.Internal && build.Internal { | ||
| continue | ||
| } | ||
|
|
||
| int := "" | ||
| if build.Internal { | ||
| int = "*" | ||
| } | ||
|
|
||
| artifacts := "" | ||
| for i, art := range build.Artifacts { | ||
| if i > 0 { | ||
| artifacts += ", " | ||
| } | ||
| artifacts = artifacts + art.Filename | ||
| } | ||
|
|
||
| c.TableWriter.AppendRow(table.Row{int, build.Version, build.Date, build.Hash, artifacts}) | ||
| } | ||
| c.TableWriter.Render() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package cmd_test | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/jedib0t/go-pretty/v6/table" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| //. "github.com/onsi/gomega" | ||
| "github.com/stretchr/testify/mock" | ||
|
|
||
| "github.com/codesphere-cloud/oms/cli/cmd" | ||
| "github.com/codesphere-cloud/oms/internal/portal" | ||
| "github.com/codesphere-cloud/oms/internal/util" | ||
| ) | ||
|
|
||
| var _ = Describe("ListPackages", func() { | ||
|
|
||
| var ( | ||
| mockTableWriter util.MockTableWriter | ||
| c cmd.ListBuildsCmd | ||
| internal bool | ||
| buildDate time.Time | ||
| ) | ||
| BeforeEach(func() { | ||
| c = cmd.ListBuildsCmd{ | ||
| Opts: cmd.ListBuildsOpts{ | ||
| Internal: internal, | ||
| }, | ||
| TableWriter: &mockTableWriter, | ||
| } | ||
|
|
||
| buildDate, _ = time.Parse("2006-01-02", "2025-05-01") | ||
|
|
||
| // header is always appended | ||
| mockTableWriter.EXPECT().AppendHeader(mock.Anything) | ||
| mockTableWriter.EXPECT().Render().Return("") | ||
| }) | ||
|
|
||
| Context("Internal packages are excluded", func() { | ||
| It("doesn't list internal packages, artifacts are separated by ,", func() { | ||
| mockTableWriter.EXPECT().AppendRow( | ||
| table.Row{"", "1.42", buildDate, "externalBuild", "installer.tar, installer2.tar"}, | ||
| ) | ||
| c.PrintPackagesTable( | ||
| portal.CodesphereBuilds{ | ||
| Builds: []portal.CodesphereBuild{ | ||
| { | ||
| Hash: "externalBuild", | ||
| Version: "1.42", | ||
| Date: buildDate, | ||
| Internal: false, | ||
| Artifacts: []portal.Artifact{ | ||
| {Filename: "installer.tar"}, | ||
| {Filename: "installer2.tar"}, | ||
| }, | ||
| }, | ||
| { | ||
| Hash: "internalBuild", | ||
| Internal: true, | ||
| }, | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| }) | ||
| Context("Internal packages are included", func() { | ||
| BeforeEach(func() { | ||
| internal = true | ||
| }) | ||
| It("marks internal packages with a *", func() { | ||
| mockTableWriter.EXPECT().AppendRow( | ||
| table.Row{"", "1.42", buildDate, "externalBuild", "installer.tar, installer2.tar"}, | ||
| ) | ||
| mockTableWriter.EXPECT().AppendRow( | ||
| table.Row{"*", "master", buildDate, "internalBuild", "installer.tar, installer2.tar"}, | ||
| ) | ||
| c.PrintPackagesTable( | ||
| portal.CodesphereBuilds{ | ||
| Builds: []portal.CodesphereBuild{ | ||
| { | ||
| Hash: "externalBuild", | ||
| Version: "1.42", | ||
| Date: buildDate, | ||
| Internal: false, | ||
| Artifacts: []portal.Artifact{ | ||
| {Filename: "installer.tar"}, | ||
| {Filename: "installer2.tar"}, | ||
| }, | ||
| }, | ||
| { | ||
| Hash: "internalBuild", | ||
| Version: "master", | ||
| Date: buildDate, | ||
| Internal: true, | ||
| Artifacts: []portal.Artifact{ | ||
| {Filename: "installer.tar"}, | ||
| {Filename: "installer2.tar"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,32 @@ | ||
| module github.com/codesphere-cloud/oms | ||
|
|
||
| go 1.24.1 | ||
| go 1.24.2 | ||
|
|
||
| require github.com/spf13/cobra v1.9.1 | ||
| require ( | ||
| github.com/codesphere-cloud/cs-go v0.10.1 | ||
| github.com/jedib0t/go-pretty/v6 v6.6.7 | ||
| github.com/onsi/ginkgo/v2 v2.23.4 | ||
| github.com/onsi/gomega v1.37.0 | ||
| github.com/spf13/cobra v1.9.1 | ||
| github.com/stretchr/testify v1.10.0 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/davecgh/go-spew v1.1.1 // indirect | ||
| github.com/go-logr/logr v1.4.3 // indirect | ||
| github.com/go-task/slim-sprig/v3 v3.0.0 // indirect | ||
| github.com/google/go-cmp v0.7.0 // indirect | ||
| github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect | ||
| github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
| github.com/mattn/go-runewidth v0.0.16 // indirect | ||
| github.com/pmezard/go-difflib v1.0.0 // indirect | ||
| github.com/rivo/uniseg v0.4.7 // indirect | ||
| github.com/spf13/pflag v1.0.6 // indirect | ||
| github.com/stretchr/objx v0.5.2 // indirect | ||
| go.uber.org/automaxprocs v1.6.0 // indirect | ||
| golang.org/x/net v0.40.0 // indirect | ||
| golang.org/x/sys v0.33.0 // indirect | ||
| golang.org/x/text v0.25.0 // indirect | ||
| golang.org/x/tools v0.31.0 // indirect | ||
| gopkg.in/yaml.v3 v3.0.1 // indirect | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.