Skip to content

Commit

Permalink
Merged in release/0.4.0 (pull request #4)
Browse files Browse the repository at this point in the history
Merge release/0.4.0
  • Loading branch information
gildas committed Dec 14, 2023
2 parents 990d1b6 + 177baef commit fa5dbda
Show file tree
Hide file tree
Showing 43 changed files with 1,222 additions and 117 deletions.
69 changes: 67 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,41 @@ You can delete a project with the `bb project delete` command:
bb project delete myproject --workspace myworkspace
```

#### Project Default Reviewers

You can list the default reviewers of a project with the `bb project reviewer list` command:

```bash
bb project reviewer list --workspace myworkspace --project myproject
```

You can add a default reviewer to a project with the `bb project reviewer add` command:

```bash
bb project reviewer add \
--workspace myworkspace \
--project myproject \
userUUID
```

You can remove a default reviewer from a project with the `bb project reviewer remove` command:

```bash
bb project reviewer remove \
--workspace myworkspace \
--project myproject \
userUUID
```

You can get the details of a default reviewer with the `bb project reviewer get` or `bb project reviewer show` command:

```bash
bb project reviewer get \
--workspace myworkspace \
--project myproject \
userUUID
```

### Pull Requests

You can list pull requests with the `bb pullrequest list` command:
Expand Down Expand Up @@ -201,6 +236,38 @@ You can `merge` a pull request with the `bb pullrequest merge` command:
bb pullrequest merge 1
```

### Artifacts (Downloads)

You can list artifacts with the `bb artifact list` command:

```bash
bb artifact list
```

By default the current repository is used, you can specify a repository with the `--repository` flag.

You can also upload an artifact with the `bb artifact upload` command:

```bash
bb artifact upload myartifact.zip
```

At the moment, only one file at a time is supported (no folders or stdin). The artifact name is the file name.

You can download an artifact with the `bb artifact download` command:

```bash
bb artifact download myartifact.zip
```

You can provide a `--destination` flag to specify the destination folder. If the folder does not exist, it will be created.

Finally, you can delete an artifact with the `bb artifact delete` command:

```bash
bb artifact delete myartifact.zip
```

### Completion

`bb` supports completion for Bash, fish, Powershell, and zsh.
Expand Down Expand Up @@ -266,5 +333,3 @@ bb completion zsh > "$(brew --prefix)/share/zsh/site-functions/_bb"
### TODO

We will add more commands in the future. If you have any suggestions, please open an issue.

At the moment all outputs are in JSON. We will add more output formats in the future.
47 changes: 47 additions & 0 deletions cmd/artifact/artifact.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package artifact

import (
"fmt"

"bitbucket.org/gildas_cherruel/bb/cmd/link"
"bitbucket.org/gildas_cherruel/bb/cmd/user"
"github.com/spf13/cobra"
)

type Artifact struct {
Name string `json:"name" mapstructure:"name"`
Size uint64 `json:"size" mapstructure:"size"`
Downloads uint64 `json:"downloads" mapstructure:"downloads"`
User user.User `json:"user" mapstructure:"user"`
Links link.Links `json:"links" mapstructure:"links"`
}

var Command = &cobra.Command{
Use: "artifact",
Short: "Manage artifacts",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Artifact requires a subcommand:")
for _, command := range cmd.Commands() {
fmt.Println(command.Name())
}
},
}

// GetHeader gets the header for a table
//
// implements common.Tableable
func (artifact Artifact) GetHeader(short bool) []string {
return []string{"Name", "Size", "Downloads", "Owner"}
}

// GetRow gets the row for a table
//
// implements common.Tableable
func (artifact Artifact) GetRow(headers []string) []string {
return []string{
artifact.Name,
fmt.Sprintf("%d", artifact.Size),
fmt.Sprintf("%d", artifact.Downloads),
artifact.User.Name,
}
}
27 changes: 27 additions & 0 deletions cmd/artifact/artifacts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package artifact

type Artifacts []Artifact

// GetHeader gets the headers for the list command
//
// implements common.Tableables
func (artifacts Artifacts) GetHeader() []string {
return Artifact{}.GetHeader(false)
}

// GetRowAt gets the row for the list command
//
// implements common.Tableables
func (artifacts Artifacts) GetRowAt(index int) []string {
if index < 0 || index >= len(artifacts) {
return []string{}
}
return artifacts[index].GetRow(nil)
}

// Size gets the number of elements
//
// implements common.Tableables
func (artifacts Artifacts) Size() int {
return len(artifacts)
}
49 changes: 49 additions & 0 deletions cmd/artifact/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package artifact

import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
"github.com/spf13/cobra"
)

var deleteCmd = &cobra.Command{
Use: "delete",
Short: "delete an artifact by its filename",
Args: cobra.ExactArgs(1),
RunE: deleteProcess,
}

var deleteOptions struct {
Repository string
}

func init() {
Command.AddCommand(deleteCmd)

deleteCmd.Flags().StringVar(&deleteOptions.Repository, "repository", "", "Repository to delete artifacts from. Defaults to the current repository")
}

func deleteProcess(cmd *cobra.Command, args []string) error {
log := logger.Must(logger.FromContext(cmd.Context())).Child(cmd.Parent().Name(), "delete")

if profile.Current == nil {
return errors.ArgumentMissing.With("profile")
}

log.Infof("Deleting artifact %s from repository %s with profile %s", args[0], listOptions.Repository, profile.Current)
err := profile.Current.Delete(
log.ToContext(cmd.Context()),
deleteOptions.Repository,
fmt.Sprintf("downloads/%s", args[0]),
nil,
)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to delete artifact %s: %s\n", args[0], err)
os.Exit(1)
}
return nil
}
54 changes: 54 additions & 0 deletions cmd/artifact/download.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package artifact

import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
"github.com/spf13/cobra"
)

var downloadCmd = &cobra.Command{
Use: "download",
Aliases: []string{"get", "fetch"},
Short: "download an artifact",
Args: cobra.ExactArgs(1),
RunE: getProcess,
}

var downloadOptions struct {
Repository string
Destination string
}

func init() {
Command.AddCommand(downloadCmd)

downloadCmd.Flags().StringVar(&downloadOptions.Repository, "repository", "", "Repository to download artifacts from. Defaults to the current repository")
downloadCmd.Flags().StringVar(&downloadOptions.Destination, "destination", "", "Destination folder to download the artifact to. Defaults to the current folder")
_ = downloadCmd.MarkFlagDirname("destination")
}

func getProcess(cmd *cobra.Command, args []string) error {
log := logger.Must(logger.FromContext(cmd.Context())).Child(cmd.Parent().Name(), "download")

if profile.Current == nil {
return errors.ArgumentMissing.With("profile")
}

log.Infof("Downloading artifact %s", args[0])

err := profile.Current.Download(
log.ToContext(cmd.Context()),
downloadOptions.Repository,
fmt.Sprintf("downloads/%s", args[0]),
downloadOptions.Destination,
)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to download artifact %s: %s\n", args[0], err)
os.Exit(1)
}
return nil
}
49 changes: 49 additions & 0 deletions cmd/artifact/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package artifact

import (
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
"github.com/spf13/cobra"
)

var listCmd = &cobra.Command{
Use: "list",
Short: "list all projects",
Args: cobra.NoArgs,
RunE: listProcess,
}

var listOptions struct {
Repository string
}

func init() {
Command.AddCommand(listCmd)

listCmd.Flags().StringVar(&listOptions.Repository, "repository", "", "Repository to list artifacts from. Defaults to the current repository")
}

func listProcess(cmd *cobra.Command, args []string) (err error) {
log := logger.Must(logger.FromContext(cmd.Context())).Child(cmd.Parent().Name(), "list")

if profile.Current == nil {
return errors.ArgumentMissing.With("profile")
}

log.Infof("Listing all projects from repository %s with profile %s", listOptions.Repository, profile.Current)
artifacts, err := profile.GetAll[Artifact](
cmd.Context(),
profile.Current,
listOptions.Repository,
"downloads",
)
if err != nil {
return err
}
if len(artifacts) == 0 {
log.Infof("No artifact found")
return nil
}
return profile.Current.Print(cmd.Context(), Artifacts(artifacts))
}
50 changes: 50 additions & 0 deletions cmd/artifact/upload.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package artifact

import (
"fmt"
"os"

"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
"github.com/spf13/cobra"
)

var uploadCmd = &cobra.Command{
Use: "upload",
Short: "upload an artifact",
Args: cobra.ExactArgs(1),
RunE: uploadProcess,
}

var uploadOptions struct {
Repository string
}

func init() {
Command.AddCommand(uploadCmd)

uploadCmd.Flags().StringVar(&uploadOptions.Repository, "repository", "", "Repository to upload artifacts to. Defaults to the current repository")
}

func uploadProcess(cmd *cobra.Command, args []string) error {
log := logger.Must(logger.FromContext(cmd.Context())).Child(cmd.Parent().Name(), "upload")

if profile.Current == nil {
return errors.ArgumentMissing.With("profile")
}

log.Infof("Uploading artifact %s", args[0])

err := profile.Current.Upload(
log.ToContext(cmd.Context()),
uploadOptions.Repository,
"downloads",
args[0],
)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to upload artifact %s: %s\n", args[0], err)
os.Exit(1)
}
return nil
}
14 changes: 14 additions & 0 deletions cmd/branch/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ var Command = &cobra.Command{
},
}

// GetHeader gets the header for a table
//
// implements common.Tableable
func (branch Branch) GetHeader(short bool) []string {
return []string{"Name"}
}

// GetRow gets the row for a table
//
// implements common.Tableable
func (branch Branch) GetRow(headers []string) []string {
return []string{branch.Name}
}

// Validate validates a Branch
func (branch *Branch) Validate() error {
var merr errors.MultiError
Expand Down
Loading

0 comments on commit fa5dbda

Please sign in to comment.