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:
commit
47651fb102
@ -6,3 +6,8 @@ type TrelloCard struct {
|
||||
List string
|
||||
Description string
|
||||
}
|
||||
|
||||
type TrelloList struct {
|
||||
ID string
|
||||
Name string
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ import (
|
||||
"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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lists, err = getListIDs(client, boardID, lists)
|
||||
lists, err := getLists(client, boardID, listNames)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -20,8 +20,8 @@ func GetCards(client *trello.Client, username string, boardName string, lists ma
|
||||
searchResult := &SearchResult{Total: 0}
|
||||
searchResult.TrelloCards = make(map[string][]TrelloCard)
|
||||
|
||||
for listName, listID := range lists {
|
||||
cards, err := getCardsOnList(client, listID)
|
||||
for _, list := range lists {
|
||||
cards, err := getCardsOnList(client, list.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -32,14 +32,14 @@ func GetCards(client *trello.Client, username string, boardName string, lists ma
|
||||
for _, card := range cards {
|
||||
trelloCard := TrelloCard{
|
||||
ID: card.ID,
|
||||
List: listName,
|
||||
List: list.Name,
|
||||
Name: card.Name,
|
||||
Description: card.Desc,
|
||||
}
|
||||
cardArray = append(cardArray, trelloCard)
|
||||
}
|
||||
|
||||
searchResult.TrelloCards[listName] = cardArray
|
||||
searchResult.TrelloCards[list.Name] = cardArray
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -77,12 +83,12 @@ func getListIDs(client *trello.Client, boardID string, lists map[string]string)
|
||||
}
|
||||
|
||||
for _, list := range boardLists {
|
||||
if _, ok := lists[list.Name]; ok {
|
||||
lists[list.Name] = list.ID
|
||||
if _, ok := comparison[list.Name]; ok {
|
||||
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) {
|
||||
|
@ -18,7 +18,7 @@ type Settings struct {
|
||||
accessToken string
|
||||
apiKey string
|
||||
board string
|
||||
list map[string]string
|
||||
list []string
|
||||
username string
|
||||
}
|
||||
|
||||
@ -32,18 +32,18 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
|
||||
username: ymlConfig.UString("username"),
|
||||
}
|
||||
|
||||
settings.list = mapifyList(ymlConfig, globalConfig)
|
||||
settings.list = buildLists(ymlConfig, globalConfig)
|
||||
|
||||
return &settings
|
||||
}
|
||||
|
||||
func mapifyList(ymlConfig *config.Config, globalConfig *config.Config) map[string]string {
|
||||
lists := make(map[string]string)
|
||||
func buildLists(ymlConfig *config.Config, globalConfig *config.Config) []string {
|
||||
lists := []string{}
|
||||
|
||||
// Single list
|
||||
list, err := ymlConfig.String("list")
|
||||
if err == nil {
|
||||
lists[list] = list
|
||||
lists = append(lists, list)
|
||||
return lists
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ func mapifyList(ymlConfig *config.Config, globalConfig *config.Config) map[strin
|
||||
listList := ymlConfig.UList("list")
|
||||
for _, listName := range listList {
|
||||
if list, ok := listName.(string); ok {
|
||||
lists[list] = list
|
||||
lists = append(lists, list)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user