Esempio n. 1
0
// LoadProfile attempts to locate and load a profile from disk.
func LoadProfile(path string) (*Profile, error) {
	inf, err := os.Open(path)
	if err != nil {
		if os.IsNotExist(err) {
			log.WithField("profile path", path).Errorf("You have no profile yet!\n%s", noProfileMessage)
		}

		return nil, err
	}
	defer inf.Close()

	p := &Profile{}
	err = json.NewDecoder(inf).Decode(p)
	if err != nil {
		return p, err
	}

	if p.Key == "" {
		log.Error("To get a Trello API key, log in to the web UI and visit: https://trello.com/1/appKey/generate")
		return p, errors.New("Trello API key missing")
	}

	if p.Token == "" {
		log.Errorf("To get a Trello token, visit https://trello.com/1/authorize?key=%s&name=Closer"+
			"&expiration=never&scope=read,write&response_type=token", p.Key)
		return p, errors.New("Trello token missing")
	}

	if p.Organization == "" {
		return p, errors.New("Trello organization missing")
	}

	return p, nil
}
Esempio n. 2
0
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.")
}