// FindBoard discovers the ID of an existing board by name. func (c Connection) FindBoard(name string) (string, error) { u := c.url([]string{"organizations", c.profile.Organization, "boards"}, map[string]string{ "fields": "name", }) var boardResults []struct { ID string `json:"id"` Name string `json:"name"` } err := c.get(u, &boardResults) if err != nil { return "", err } for _, board := range boardResults { log.WithFields(log.Fields{ "name": board.Name, "id": board.ID, }).Debug("Board") if board.Name == name { return board.ID, nil } } return "", fmt.Errorf("Unable to find a board with the name [%s].", name) }
func TestLogstashFormatter(t *testing.T) { assert := assert.New(t) lf := LogstashFormatter{Type: "abc"} fields := logrus.Fields{ "message": "def", "level": "ijk", "type": "lmn", "one": 1, "pi": 3.14, "bool": true, } entry := logrus.WithFields(fields) entry.Message = "msg" entry.Level = logrus.InfoLevel b, _ := lf.Format(entry) var data map[string]interface{} dec := json.NewDecoder(bytes.NewReader(b)) dec.UseNumber() dec.Decode(&data) // base fields assert.Equal(json.Number("1"), data["@version"]) assert.NotEmpty(data["@timestamp"]) assert.Equal("abc", data["type"]) assert.Equal("msg", data["message"]) assert.Equal("info", data["level"]) // substituted fields assert.Equal("def", data["fields.message"]) assert.Equal("ijk", data["fields.level"]) assert.Equal("lmn", data["fields.type"]) // formats assert.Equal(json.Number("1"), data["one"]) assert.Equal(json.Number("3.14"), data["pi"]) assert.Equal(true, data["bool"]) }
// FindList locates a list on a board by name. func (c Connection) FindList(name string, boardID string) (*List, error) { u := c.url([]string{"boards", boardID, "lists"}, nil) var listResults []List err := c.get(u, &listResults) if err != nil { return nil, err } for _, list := range listResults { log.WithFields(log.Fields{ "name": list.Name, "id": list.ID, "position": list.Position, }).Debug("List") if list.Name == name { return &list, nil } } return nil, fmt.Errorf("Unable to find a list with the name [%s].", name) }
func run(c *cli.Context) { levelName := strings.ToLower(c.String("log")) level, err := log.ParseLevel(levelName) handleErr(err) log.SetLevel(level) p, err := LoadProfile(c.String("profile")) handleErr(err) conn := Connection{profile: *p} currentSprintID, err := conn.FindBoard("Current Sprint") handleErr(err) log.WithField("board id", currentSprintID).Debug("Current sprint board located.") doneList, err := conn.FindList("Done", currentSprintID) handleErr(err) log.WithField("list id", doneList.ID).Debug("Done list located.") org, err := conn.FindOrg() handleErr(err) log.WithFields(log.Fields{ "org id": org.ID, "member count": len(org.MemberIDs), }).Debug("Organization ID located.") myID, err := conn.FindMyUserID() handleErr(err) log.WithField("user id", myID).Debug("My user ID located.") archiveBoardName := newBoardName() archiveBoardID, err := conn.CreateBoard(archiveBoardName) handleErr(err) log.WithFields(log.Fields{ "board id": archiveBoardID, "board name": archiveBoardName, }).Info("Created archive board.") for _, memberID := range org.MemberIDs { if memberID != myID { log.WithField("member ID", memberID).Debug("Granting access") err = conn.AddMember(archiveBoardID, memberID) handleErr(err) } } log.WithField("member count", len(org.MemberIDs)).Info("Granted access to this organization.") autoListIDs, err := conn.GetListIDs(archiveBoardID) handleErr(err) for _, listID := range autoListIDs { log.WithField("list id", listID).Debug("Deleting list") err = conn.DeleteList(listID) handleErr(err) } log.Info("Deleted pre-existing lists.") err = conn.MoveList(doneList.ID, archiveBoardID, 1) handleErr(err) log.Info("Moved Done list to the archive board.") err = conn.AddList("Done", currentSprintID, doneList.Position) handleErr(err) log.Info("Created Done list on the Current Sprint board.") }