1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Merge branch 'respectordering' of github.com:Seanstoppable/wtf into Seanstoppable-respectordering

This commit is contained in:
Chris Cummer 2019-10-02 19:40:13 -07:00
commit 47651fb102
3 changed files with 27 additions and 16 deletions

View File

@ -6,3 +6,8 @@ type TrelloCard struct {
List string List string
Description string Description string
} }
type TrelloList struct {
ID string
Name string
}

View File

@ -6,13 +6,13 @@ import (
"github.com/adlio/trello" "github.com/adlio/trello"
) )
func GetCards(client *trello.Client, username string, boardName string, lists map[string]string) (*SearchResult, error) { func GetCards(client *trello.Client, username string, boardName string, listNames []string) (*SearchResult, error) {
boardID, err := getBoardID(client, username, boardName) boardID, err := getBoardID(client, username, boardName)
if err != nil { if err != nil {
return nil, err return nil, err
} }
lists, err = getListIDs(client, boardID, lists) lists, err := getLists(client, boardID, listNames)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -20,8 +20,8 @@ func GetCards(client *trello.Client, username string, boardName string, lists ma
searchResult := &SearchResult{Total: 0} searchResult := &SearchResult{Total: 0}
searchResult.TrelloCards = make(map[string][]TrelloCard) searchResult.TrelloCards = make(map[string][]TrelloCard)
for listName, listID := range lists { for _, list := range lists {
cards, err := getCardsOnList(client, listID) cards, err := getCardsOnList(client, list.ID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -32,14 +32,14 @@ func GetCards(client *trello.Client, username string, boardName string, lists ma
for _, card := range cards { for _, card := range cards {
trelloCard := TrelloCard{ trelloCard := TrelloCard{
ID: card.ID, ID: card.ID,
List: listName, List: list.Name,
Name: card.Name, Name: card.Name,
Description: card.Desc, Description: card.Desc,
} }
cardArray = append(cardArray, trelloCard) cardArray = append(cardArray, trelloCard)
} }
searchResult.TrelloCards[listName] = cardArray searchResult.TrelloCards[list.Name] = cardArray
} }
return searchResult, nil return searchResult, nil
@ -65,7 +65,13 @@ func getBoardID(client *trello.Client, username, boardName string) (string, erro
return "", fmt.Errorf("could not find board with name %s", boardName) return "", fmt.Errorf("could not find board with name %s", boardName)
} }
func getListIDs(client *trello.Client, boardID string, lists map[string]string) (map[string]string, error) { func getLists(client *trello.Client, boardID string, listNames []string) ([]TrelloList, error) {
comparison := make(map[string]string, len(listNames))
results := []TrelloList{}
//convert to a map for comparison
for _, item := range listNames {
comparison[item] = ""
}
board, err := client.GetBoard(boardID, trello.Defaults()) board, err := client.GetBoard(boardID, trello.Defaults())
if err != nil { if err != nil {
return nil, err return nil, err
@ -77,12 +83,12 @@ func getListIDs(client *trello.Client, boardID string, lists map[string]string)
} }
for _, list := range boardLists { for _, list := range boardLists {
if _, ok := lists[list.Name]; ok { if _, ok := comparison[list.Name]; ok {
lists[list.Name] = list.ID results = append(results, TrelloList{ID: list.ID, Name: list.Name})
} }
} }
return lists, nil return results, nil
} }
func getCardsOnList(client *trello.Client, listID string) ([]*trello.Card, error) { func getCardsOnList(client *trello.Client, listID string) ([]*trello.Card, error) {

View File

@ -18,7 +18,7 @@ type Settings struct {
accessToken string accessToken string
apiKey string apiKey string
board string board string
list map[string]string list []string
username string username string
} }
@ -32,18 +32,18 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
username: ymlConfig.UString("username"), username: ymlConfig.UString("username"),
} }
settings.list = mapifyList(ymlConfig, globalConfig) settings.list = buildLists(ymlConfig, globalConfig)
return &settings return &settings
} }
func mapifyList(ymlConfig *config.Config, globalConfig *config.Config) map[string]string { func buildLists(ymlConfig *config.Config, globalConfig *config.Config) []string {
lists := make(map[string]string) lists := []string{}
// Single list // Single list
list, err := ymlConfig.String("list") list, err := ymlConfig.String("list")
if err == nil { if err == nil {
lists[list] = list lists = append(lists, list)
return lists return lists
} }
@ -51,7 +51,7 @@ func mapifyList(ymlConfig *config.Config, globalConfig *config.Config) map[strin
listList := ymlConfig.UList("list") listList := ymlConfig.UList("list")
for _, listName := range listList { for _, listName := range listList {
if list, ok := listName.(string); ok { if list, ok := listName.(string); ok {
lists[list] = list lists = append(lists, list)
} }
} }