Пример #1
0
func (r bot) addTime(p *robots.Payload, cmd utils.Command) error {
	args, err := cmd.ParseArgs("mavenlink-id", "time-in-hours")
	if err != nil {
		return err
	}

	mvnID, timeStr := args[0], args[1]
	hours, err := strconv.ParseFloat(timeStr, 64)
	if err != nil {
		return err
	}

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

	story, err := mvn.GetStory(mvnID)
	if err != nil {
		return err
	}

	minutes := int(hours * 60)
	_, err = mvn.AddTimeEntry(story, minutes)
	if err != nil {
		return err
	}

	r.handler.Send(p, fmt.Sprintf("Added *%.1f* hours to story *%s - %s*",
		hours, story.Id, story.Title))
	return nil
}
Пример #2
0
func (r bot) estimate(p *robots.Payload, cmd utils.Command) error {
	args, err := cmd.ParseArgs("pivotal-id", "estimate")
	if err != nil {
		return err
	}

	pvtId, estimate := args[0], args[1]

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

	// pvtStory, err := pvt.GetStory(pvtId)
	// if err != nil {
	// 	return err
	// }
	//
	numEstimate, err := strconv.Atoi(estimate)
	if err != nil {
		return err
	}

	story, err := pvt.EstimateStory(pvtId, numEstimate)
	if err != nil {
		return err
	}

	s := "Story successfully updated:\n"
	r.handler.SendWithAttachments(p, s, []robots.Attachment{
		utils.FmtAttachment("", story.Name, story.Url, ""),
	})

	return nil
}
Пример #3
0
func (r bot) assign(p *robots.Payload, cmd utils.Command) error {
	res, err := cmd.ParseArgs("pivotal-story-id", "username")
	if err != nil {
		return err
	}

	storyId, username := res[0], res[1]

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

	user, err := db.GetUserByName(username)
	if err != nil {
		return err
	}
	if user == nil {
		return errors.New("User *" + username + "* not found")
	}

	story, err := pvt.AssignStory(storyId, *user.PivotalId)
	if err != nil {
		return err
	}

	s := "Story successfully updated:\n"
	r.handler.SendWithAttachments(p, s, []robots.Attachment{
		utils.FmtAttachment("", story.Name, story.Url, ""),
	})

	return nil
}
Пример #4
0
func (r bot) unassigned(p *robots.Payload, cmd utils.Command) error {
	res, err := cmd.ParseArgs("project")
	if err != nil {
		return err
	}

	name := res[0]
	pr, err := getProject(name)
	if err != nil {
		return err
	}

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

	msg := "Unassigned stories for *" + name + "*:\n"

	stories, err := pvt.GetUnassignedStories(pr.StrPivotalId())

	if len(stories) < 1 {
		r.handler.Send(p, "No unassigned stories for *"+name+"*")
		return nil
	}

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

	r.handler.Send(p, msg)
	return nil
}
Пример #5
0
func (r bot) vote(p *robots.Payload, cmd utils.Command) error {
	args, err := cmd.ParseArgs("vote")
	if err != nil {
		return err
	}
	vote := args[0]

	session, err := db.GetCurrentSession(p.ChannelName)
	if err != nil {
		return err
	}
	if session == nil {
		r.handler.Send(p, "No active poker session on *"+p.ChannelName+"*. Use `/poker session` to start a new session.")
		return nil
	}

	story, err := session.GetCurrentStory()
	if err != nil {
		return err
	}
	if story == nil {
		r.handler.Send(p, "No current story on *"+p.ChannelName+"*. Use `/poker story` to start a new session.")
		return nil
	}

	err = story.CastVote(p.UserName, vote)
	if err != nil {
		return err
	}

	r.handler.Send(p, "Vote cast for *"+p.UserName+"*")

	users := session.Users
	if users != "" {
		expUsers := strings.Split(users, ",")
		votes, err := story.GetVotes()
		if err != nil {
			return err
		}

		for _, v := range votes {
			expUsers = utils.RemoveFromSlice(expUsers, v.User)
		}

		if len(expUsers) < 1 {
			r.handler.Send(p, "Everyone voted, revealing votes.")
			r.revealVotes(p, cmd)
			r.handler.Send(p, "Now set the estimate for this story with `!poker set <estimate>`")
		}
	}

	return nil
}
Пример #6
0
func (r bot) sendMyStories(p *robots.Payload, cmd utils.Command) error {
	args, err := cmd.ParseArgs("pvt-project-id")
	if err != nil {
		return err
	}

	project := args[0]
	pvt, err := conn(p.UserName)
	if err != nil {
		return err
	}

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

	filter := map[string]string{
		"owned_by": user.StrPivotalId(),
		"state":    "started,finished,delivered",
	}
	stories, err := pvt.FilteredStories(project, filter)
	if err != nil {
		return err
	}

	if len(stories) < 1 {
		r.handler.Send(p, "No open stories for *"+p.UserName+"*")
		return nil
	}

	str := "Current stories for *" + p.UserName + "*:\n"
	atts := []robots.Attachment{}
	for _, s := range stories {
		fallback := fmt.Sprintf("%d - %s - %s\n", s.Id, s.Name, s.State)
		title := fmt.Sprintf("%d - %s\n", s.Id, s.Name)
		a := utils.FmtAttachment(fallback, title, s.Url, s.State)
		atts = append(atts, a)
	}

	r.handler.SendWithAttachments(p, str, atts)
	return nil
}
Пример #7
0
func (r bot) setEstimation(p *robots.Payload, cmd utils.Command) error {
	args, err := cmd.ParseArgs("estimation")
	if err != nil {
		return err
	}
	estimation := args[0]

	session, err := db.GetCurrentSession(p.ChannelName)
	if err != nil {
		return err
	}
	if session == nil {
		r.handler.Send(p, "No active poker session on *"+p.ChannelName+"*. Use `/poker session` to start a new session.")
		return nil
	}

	story, err := session.GetCurrentStory()
	if err != nil {
		return err
	}
	if story == nil {
		r.handler.Send(p, "No current story on *"+p.ChannelName+"*. Use `/poker story` to start a new session.")
		return nil
	}

	err = story.UpdateEstimation(estimation)
	if err != nil {
		return err
	}

	r.handler.Send(p, "Tracked estimation of *"+estimation+"* hours for *"+story.Title+"*")

	story, err = session.GetCurrentStory()
	if err != nil {
		return err
	}
	if story != nil {
		r.nextStory(p, cmd)
	}

	return nil
}
Пример #8
0
func (r bot) set(p *robots.Payload, cmd utils.Command) error {
	args, err := cmd.ParseArgs("start-date", "end-date")
	if err != nil {
		return err
	}

	start, end := args[0], args[1]
	desc := cmd.StrFrom(2)

	startDate, err := time.Parse("2006-01-02", start)
	if err != nil {
		return err
	}
	endDate, err := time.Parse("2006-01-02", end)
	if err != nil {
		return err
	}

	_, err = db.CreateVacation(p.UserName, desc, &startDate, &endDate)

	r.handler.Send(p, "Vacation created")
	return nil
}