From ce27fbc67177b40b4b30de2294f11a2f5ea4dc19 Mon Sep 17 00:00:00 2001 From: Fabian Siegel Date: Thu, 8 Apr 2021 14:16:39 +0200 Subject: [PATCH] pr create: fix names --- client/workspaces.go | 7 ++++++- cmd/commands/pr/comments/comments.go | 7 ++++--- cmd/commands/pr/create/create.go | 11 ++++++----- go.mod | 2 +- go.sum | 2 ++ util/logging/logging.go | 11 ++++++++++- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/client/workspaces.go b/client/workspaces.go index 248f01a..6733708 100644 --- a/client/workspaces.go +++ b/client/workspaces.go @@ -15,12 +15,17 @@ type Workspace struct { UUID string `mapstructure:"uuid"` } +type WorkspaceMembership struct { + User Account `mapstructure:"user"` + Workspace Workspace `mapstructure:"workspace"` +} + type Workspaces struct { Workspaces []Workspace `mapstructure:"workspaces"` } type Members struct { - Values []Account `mapstructure:"values"` + Values []WorkspaceMembership `mapstructure:"values"` } func (c Client) GetWorkspaceMembers(workspace string) (*Members, error) { diff --git a/cmd/commands/pr/comments/comments.go b/cmd/commands/pr/comments/comments.go index 4e816b4..9093dcb 100644 --- a/cmd/commands/pr/comments/comments.go +++ b/cmd/commands/pr/comments/comments.go @@ -2,16 +2,17 @@ package comments import ( "fmt" - "github.com/craftamap/bb/util/logging" "regexp" "sort" "strconv" "strings" + "github.com/craftamap/bb/util/logging" + "github.com/charmbracelet/glamour" "github.com/cli/cli/git" - "github.com/craftamap/bb/cmd/options" "github.com/craftamap/bb/client" + "github.com/craftamap/bb/cmd/options" "github.com/kyokomi/emoji" "github.com/logrusorgru/aurora" "github.com/muesli/reflow/wordwrap" @@ -70,7 +71,7 @@ func Add(prCmd *cobra.Command, globalOpts *options.GlobalOptions) { members, err := c.GetWorkspaceMembers(bbrepo.RepoOrga) if err == nil { for _, member := range members.Values { - ReviewersNameCache[member.AccountID] = member.DisplayName + ReviewersNameCache[member.User.AccountID] = member.User.DisplayName } } diff --git a/cmd/commands/pr/create/create.go b/cmd/commands/pr/create/create.go index 5e79bfc..598286b 100644 --- a/cmd/commands/pr/create/create.go +++ b/cmd/commands/pr/create/create.go @@ -416,19 +416,20 @@ func manageReviewers(bbrepo *bbgit.BitbucketRepo, c *client.Client, currentUser } if answer == "add reviewer" { - fmt.Printf("%s%s%s\n", aurora.Magenta(":: "), aurora.Bold("Note: "), "Currently, only members of the current workspace can be added as reviewers.") - fmt.Printf("%s%s%s\n", aurora.Magenta(":: "), aurora.Bold("Note: "), "Currently, there is no way of detecting if a user of your workspace has access to the repository. Adding a wrong user without access to the repository leads to a error while creating the repository.") + logging.Note("Currently, only members of the current workspace can be added as reviewers.") + logging.Note("Currently, there is no way of detecting if a user of your workspace has access to the repository. Adding a wrong user without access to the repository leads to a error while creating the repository.") members, err := c.GetWorkspaceMembers(bbrepo.RepoOrga) if err != nil { logging.Warning(fmt.Sprint("Could not get workspace members - create the pr without reviewers and add them manually using the browser", err)) continue } + logging.Debugf("members: %+v", members) var nonReviewersMembers []string for _, member := range members.Values { - ReviewersNameCache[member.UUID] = member.DisplayName - if !stringInSlice(member.UUID, reviewers) && member.UUID != currentUser.Uuid { - nonReviewersMembers = append(nonReviewersMembers, member.UUID) + ReviewersNameCache[member.User.UUID] = member.User.DisplayName + if !stringInSlice(member.User.UUID, reviewers) && member.User.UUID != currentUser.Uuid { + nonReviewersMembers = append(nonReviewersMembers, member.User.UUID) } } nameToUUID := map[string]string{} diff --git a/go.mod b/go.mod index 2e89839..6c4b269 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/cli/safeexec v1.0.0 github.com/dustin/go-humanize v1.0.0 github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f - github.com/ktrysmt/go-bitbucket v0.9.2 + github.com/ktrysmt/go-bitbucket v0.9.10 github.com/kyokomi/emoji v2.2.4+incompatible github.com/logrusorgru/aurora v2.0.3+incompatible github.com/mitchellh/mapstructure v1.3.3 diff --git a/go.sum b/go.sum index fd7cf3c..252504a 100644 --- a/go.sum +++ b/go.sum @@ -162,6 +162,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/ktrysmt/go-bitbucket v0.9.2 h1:HpfQEGPqyvdxYamryObQHm82okwVi1iDTDETVZxBAJE= github.com/ktrysmt/go-bitbucket v0.9.2/go.mod h1:9u0v3hsd2rqCHRIpbir1oP7F58uo5dq19sBYvuMoyQ4= +github.com/ktrysmt/go-bitbucket v0.9.10 h1:T9LWNYnDmUoyogjlloqkmJ+OSiAKqoJNG/TEqnuqt7o= +github.com/ktrysmt/go-bitbucket v0.9.10/go.mod h1:xd9fs7pyFU04E/aKM884UM5biKbKf4iZz2FumSNA6y0= github.com/kyokomi/emoji v2.2.4+incompatible h1:np0woGKwx9LiHAQmwZx79Oc0rHpNw3o+3evou4BEPv4= github.com/kyokomi/emoji v2.2.4+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA= github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= diff --git a/util/logging/logging.go b/util/logging/logging.go index bcf84ad..fb3219a 100644 --- a/util/logging/logging.go +++ b/util/logging/logging.go @@ -2,9 +2,18 @@ package logging import ( "fmt" + "github.com/logrusorgru/aurora" ) +func Debug(message ...interface{}) { + fmt.Printf("%s%s\n", aurora.BgCyan(":: "+aurora.Bold("DEBUG: ").String()), fmt.Sprint(message...)) +} + +func Debugf(message ...interface{}) { + fmt.Printf("%s%s\n", aurora.BgCyan(":: "+aurora.Bold("DEBUG: ").String()), fmt.Sprintf(message[0].(string), message[1:]...)) +} + func Error(message ...interface{}) { fmt.Printf("%s%s%s\n", aurora.Red(":: "), aurora.Bold("An error occurred: "), message) } @@ -23,4 +32,4 @@ func Success(message ...interface{}) { func SuccessExclamation(message ...interface{}) { fmt.Printf("%s%s", aurora.Bold(aurora.Green("! ")), aurora.Bold(fmt.Sprint(message...))) -} \ No newline at end of file +}