Пример #1
0
func (r bot) list(p *robots.Payload, cmd utils.Command) error {
	ps, err := db.GetProjects()
	if err != nil {
		return err
	}

	if ps == nil || len(ps) < 1 {
		r.handler.Send(p, "There are no linked projects currently. Use `link` command to add one.")
		return nil
	}

	s := ""

	for _, pr := range ps {
		fmt.Println(" *** Project", pr)
		fmt.Println("     Starting PVT", strconv.FormatInt(pr.PivotalId, 10))
		pvtPr, err := r.getPvtProject(p, strconv.FormatInt(pr.PivotalId, 10))
		if err != nil {
			return err
		}
		fmt.Println("     Starting MVN", strconv.FormatInt(pr.MavenlinkId, 10))
		mvnPr, err := r.getMvnProject(p, strconv.FormatInt(pr.MavenlinkId, 10))
		if err != nil {
			return err
		}

		sprintInfo := ""
		if pr.MvnSprintStoryId != "" {
			mvn, err := mavenlink.NewFor(p.UserName)
			if err != nil {
				return err
			}

			fmt.Println("     Starting Story", pr.MvnSprintStoryId)
			sprintStory, err := mvn.GetStory(pr.MvnSprintStoryId)
			fmt.Println("     Sotry result", err)
			if err != nil {
				fmt.Println("     Returning error:", err)
				return err
			}

			sprintInfo = "Current sprint: " + sprintStory.Title + "\n"
			fmt.Println("     Finished Story")
		}

		s += fmt.Sprintf(
			"*%s*\nPivotal %d - %s to Mavenlink %s - %s\n%s",
			pr.Name, pvtPr.Id, pvtPr.Name, mvnPr.Id, mvnPr.Title, sprintInfo)
		fmt.Println("     Finished Project")
	}

	fmt.Println("     Sending response:", s)
	r.handler.Send(p, s)
	return nil
}
Пример #2
0
func StartedTasks(bot *UserBot, cmd utils.Command) error {
	username := bot.lastMessage.User.Name
	projects, err := db.GetProjects()
	if err != nil {
		return err
	}

	if projects == nil || len(projects) < 1 {
		bot.reply("There are no linked projects currently. Use `/project link` command to add one.")
		return nil
	}

	user, err := db.GetUserByName(username)
	if err != nil {
		return err
	}

	pvt, err := pivotal.NewFor(username)
	if err != nil {
		return err
	}

	msg := ""
	for _, p := range projects {
		filter := map[string]string{
			"owned_by": user.StrPivotalId(),
			"state":    "started",
		}
		stories, err := pvt.FilteredStories(p.StrPivotalId(), filter)
		if err != nil {
			return err
		}

		if len(stories) < 1 {
			continue
		}

		msg += "Stories for *" + p.Name + "*:\n"
		for _, s := range stories {
			msg += fmt.Sprintf("%d - %s - %s\n", s.Id, s.Name, s.State)
		}
	}

	if msg == "" {
		msg = "No started tasks for you"
	}

	bot.reply(msg)
	return nil
}