Skip to content

Commit

Permalink
Migrate user to members for API upgrade
Browse files Browse the repository at this point in the history
Which is a preliminary requirement to properly support
workflows to fix the bug with workflow/states
  • Loading branch information
jnormington committed Oct 10, 2017
1 parent e249865 commit a110a67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
24 changes: 12 additions & 12 deletions clubhouse_options.go
Expand Up @@ -14,13 +14,13 @@ type ClubhouseOptions struct {
ClubhouseEntry *ch.Clubhouse
StoryType string
AddCommentWithTrelloLink bool
ImportUser *ch.User
ImportMember *ch.Member
}

// ListUsers makes the call to Clubhouse package for the list
// of users. And fails hard if an err occurs.
func (co *ClubhouseOptions) ListUsers() *[]ch.User {
u, err := co.ClubhouseEntry.ListUsers()
// ListMember makes the call to Clubhouse package for the list
// of members. And fails hard if an err occurs.
func (co *ClubhouseOptions) ListMembers() *[]ch.Member {
u, err := co.ClubhouseEntry.ListMembers()

if err != nil {
log.Fatal(err)
Expand All @@ -38,7 +38,7 @@ func SetupClubhouseOptions() *ClubhouseOptions {

co.getProjectsAndPromptUser()
co.getWorkflowStatesAndPromptUser()
co.getUsersAndPromptUser()
co.getMembersAndPromptUser()
co.promptUserForStoryType()
co.promptUserIfAddCommentWithTrelloLink()

Expand Down Expand Up @@ -80,23 +80,23 @@ func (co *ClubhouseOptions) getProjectsAndPromptUser() {
co.Project = &projects[i]
}

func (co *ClubhouseOptions) getUsersAndPromptUser() {
users, err := co.ClubhouseEntry.ListUsers()
func (co *ClubhouseOptions) getMembersAndPromptUser() {
members, err := co.ClubhouseEntry.ListMembers()
if err != nil {
log.Fatal(err)
}

fmt.Println("Please select a backup user account if a user is not mapped correctly")
for i, u := range users {
fmt.Printf("[%d] %s\n", i, u.Name)
for i, u := range members {
fmt.Printf("[%d] %s\n", i, u.Profile.Name)
}

i := promptUserSelectResource()
if i >= len(users) {
if i >= len(members) {
log.Fatal(errOutOfRange)
}

co.ImportUser = &users[i]
co.ImportMember = &members[i]
}

func (co *ClubhouseOptions) getWorkflowStatesAndPromptUser() {
Expand Down
2 changes: 1 addition & 1 deletion import.go
Expand Up @@ -35,7 +35,7 @@ func buildLinkFiles(card *Card, opts *ClubhouseOptions) []int64 {
Name: k,
Type: "url",
URL: v,
UploaderID: opts.ImportUser.ID,
UploaderID: opts.ImportMember.ID,
}

r, err := opts.ClubhouseEntry.CreateLinkedFiles(lf)
Expand Down
26 changes: 11 additions & 15 deletions user_mapping.go
Expand Up @@ -16,9 +16,9 @@ const csvFile = "userMappingTtoC.csv"
// UserMap contains the users from Trello and Clubhouse
// with a Mapping which consumed and generated by the csv input.
type UserMap struct {
TrelloMembers *[]trello.Member
ClubhouseUsers *[]ch.User
BackupUserID string
TrelloMembers *[]trello.Member
ClubhouseMembers *[]ch.Member
BackupUserID string

GenerateCSV bool
Mapping map[string]string
Expand All @@ -29,8 +29,8 @@ func NewUserMap(to *TrelloOptions, co *ClubhouseOptions) *UserMap {
var um UserMap

um.TrelloMembers = to.ListMembers()
um.ClubhouseUsers = co.ListUsers()
um.BackupUserID = co.ImportUser.ID
um.ClubhouseMembers = co.ListMembers()
um.BackupUserID = co.ImportMember.ID
um.Mapping = make(map[string]string)

return &um
Expand Down Expand Up @@ -92,15 +92,15 @@ func (um UserMap) buildUserMapToFile() {
// Try best guess mapping for csv output
// to make it easier for larger teams
for _, m := range *um.TrelloMembers {
for _, u := range *um.ClubhouseUsers {
if len(u.Permissions) == 0 {
for _, u := range *um.ClubhouseMembers {
if u.Profile.EmailAddress == "" {
// User has no email address
users = append(users, []string{m.Username, ""})
continue
}

if m.FullName == u.Name {
email := u.Permissions[0].EmailAddress
if m.FullName == u.Profile.Name {
email := u.Profile.EmailAddress
users = append(users, []string{m.Username, email})
continue
}
Expand Down Expand Up @@ -158,12 +158,8 @@ func (um *UserMap) buildUserMapFromCSV() {
}

func (um UserMap) getClubhouseUserID(email string) string {
for _, u := range *um.ClubhouseUsers {
if len(u.Permissions) == 0 {
continue
}

if u.Permissions[0].EmailAddress == email {
for _, u := range *um.ClubhouseMembers {
if u.Profile.EmailAddress == email {
return u.ID
}
}
Expand Down

0 comments on commit a110a67

Please sign in to comment.