Skip to content

Commit

Permalink
pr create: fix names
Browse files Browse the repository at this point in the history
  • Loading branch information
craftamap committed Apr 8, 2021
1 parent b70f346 commit ce27fbc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
7 changes: 6 additions & 1 deletion client/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions cmd/commands/pr/comments/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}

Expand Down
11 changes: 6 additions & 5 deletions cmd/commands/pr/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
11 changes: 10 additions & 1 deletion util/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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...)))
}
}

0 comments on commit ce27fbc

Please sign in to comment.