Ejemplo n.º 1
0
func FormatStories(stories []Story) []robots.Attachment {
	atts := []robots.Attachment{}

	for _, s := range stories {
		a := robots.Attachment{}
		a.Color = "#7CD197"
		a.Fallback = fmt.Sprintf("%s - *%s* %s (%s)\n",
			strings.Title(s.StoryType), s.Id, s.Title, s.State)
		a.Title = fmt.Sprintf("Task #%s - %s\n", s.Id, s.Title)
		a.TitleLink = fmt.Sprintf(
			"https://app.mavenlink.com/workspaces/%s/#tracker/%s",
			s.WorkspaceId, s.Id)
		a.Text = strings.Title(s.State)

		if s.Users != nil && len(s.Users) > 0 {
			assignees := ""
			for _, u := range s.Users {
				if assignees != "" {
					assignees += ", "
				}
				assignees += u.Name
			}
			a.Text += " - Assignees: " + assignees
		}

		if s.TimeEstimateInMinutes > 0 {
			a.Text += fmt.Sprintf(" - Estimated hours: %s",
				utils.FormatHour(s.TimeEstimateInMinutes))
		}

		if s.LoggedBillableTimeInMinutes > 0 {
			a.Text += fmt.Sprintf(" - Logged hours: %s",
				utils.FormatHour(s.LoggedBillableTimeInMinutes))
		}

		atts = append(atts, a)
	}

	return atts
}
Ejemplo n.º 2
0
func (r bot) stories(p *robots.Payload, cmd utils.Command) error {
	name := cmd.Arg(0)

	var ps *db.Project
	var err error
	if name != "" {
		ps, err = db.GetProjectByName(name)
		if err != nil {
			return err
		}
		if ps == nil {
			r.handler.Send(p, "Project *"+name+"* not found")
			return nil
		}
	}

	if ps == nil {
		ps, err = db.GetProjectByChannel(p.ChannelName)
		if err != nil {
			return err
		}
		if ps == nil {
			r.handler.Send(p, "Missing project name")
			return nil
		}
	}

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

	sprint, err := mvn.GetStory(ps.MvnSprintStoryId)
	if err != nil {
		return err
	}

	stories, err := mvn.GetChildStories(ps.MvnSprintStoryId)
	if err != nil {
		return err
	}

	r.handler.Send(p, "Mavenlink stories for *"+ps.Name+"*, sprint *"+sprint.Title+"*:")
	atts := mavenlink.FormatStories(stories)
	for _, a := range atts {
		r.handler.SendWithAttachments(p, "", []robots.Attachment{a})
	}

	var totalEstimated int64
	var totalLogged int64
	for _, s := range stories {
		totalEstimated += s.TimeEstimateInMinutes
		totalLogged += s.LoggedBillableTimeInMinutes
	}

	s := ""
	if totalEstimated > 0 {
		s += fmt.Sprintf("Total estimated: %s", utils.FormatHour(totalEstimated))
	}
	if totalLogged > 0 {
		if totalEstimated > 0 {
			s += " - "
		}
		s += fmt.Sprintf("Total logged: %s", utils.FormatHour(totalLogged))
	}
	if s != "" {
		r.handler.Send(p, s)
	}

	return nil
}