Exemplo n.º 1
0
func (r bot) startStory(p *robots.Payload, cmd utils.Command) error {
	title := cmd.StrFrom(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, "Cannot start a new story until you estimate *"+story.Title+"*")
		return nil
	}

	err = session.StartPokerStory(title)
	if err != nil {
		return err
	}

	r.handler.Send(p, "We can now vote for *"+title+"*")
	return nil
}
Exemplo n.º 2
0
func (r bot) create(p *robots.Payload, cmd utils.Command) error {
	alias := cmd.Arg(0)
	if alias == "" {
		r.handler.Send(p, "Missing project alias. Usage: `!project createproject <alias> <long-name>`")
		return nil
	}
	name := cmd.StrFrom(1)
	if name == "" {
		r.handler.Send(p, "Missing project name. Usage: `!project createproject <alias> <long-name>`")
		return nil
	}
	mvn, err := mavenlink.NewFor(p.UserName)
	if err != nil {
		return err
	}
	pvt, err := pivotal.NewFor(p.UserName)
	if err != nil {
		return err
	}
	pvtProject := pivotal.Project{
		Name: name,
		// PointScale: "1,2,3,4,5,6,7,8,9,10,16,20",
	}
	pvtNewProject, err := pvt.CreateProject(pvtProject)
	if err != nil {
		return err
	}
	mvnProject := mavenlink.Project{
		Title:       name,
		Description: fmt.Sprintf("[pvt:%s]", pvtNewProject.Id),
		CreatorRole: "maven",
	}
	mvnNewProject, err := mvn.CreateProject(mvnProject)
	if err != nil {
		return err
	}
	if mvnNewProject == nil {
		return errors.New("Mavenlink returned a nil project")
	}
	pvtNewProject.Description = "[mvn:" + mvnNewProject.Id + "]"
	pvtNewProject, err = pvt.UpdateProject(*pvtNewProject)
	if err != nil {
		return err
	}

	err = r.makeLink(p, alias, mvnNewProject.Id, strconv.FormatInt(pvtNewProject.Id, 10))
	if err != nil {
		return err
	}

	r.handler.Send(p, "Project *"+name+"* created on Pivotal and Mavenlink.")
	return nil
}
Exemplo n.º 3
0
func (r bot) startSession(p *robots.Payload, cmd utils.Command) error {
	title := cmd.StrFrom(0)

	users := cmd.Param("users")

	err := db.StartPokerSession(p.ChannelName, title, users)
	if err != nil {
		return err
	}

	r.handler.Send(p, "Started poker session for *"+title+"*")
	return nil
}
Exemplo n.º 4
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
}
Exemplo n.º 5
0
func (r bot) addSprint(p *robots.Payload, cmd utils.Command) error {
	name := cmd.Arg(0)
	if name == "" {
		r.handler.Send(p, "Missing project name")
		return nil
	}

	ps, err := db.GetProjectByName(name)
	if err != nil {
		return err
	}

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

	sprintName := cmd.StrFrom(1)
	if sprintName == "" {
		sprintName = "Sprint 1"

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

			matched, err := regexp.MatchString(`Sprint [\d]+`, s.Title)
			if err != nil {
				return err
			}
			if matched {
				num, err := strconv.ParseInt(strings.Split(s.Title, " ")[1], 10, 64)
				if err != nil {
					return err
				}
				sprintName = fmt.Sprintf("Sprint %d", (num + 1))
			}
		}
	}

	s := mavenlink.Story{
		Title:       sprintName,
		WorkspaceId: strconv.FormatInt(ps.MavenlinkId, 10),
		StoryType:   "milestone",
	}

	ns, err := mvn.CreateStory(s)
	if err != nil {
		return err
	}

	fmt.Printf("%+v\n", ns)

	ps.MvnSprintStoryId = ns.Id
	err = db.UpdateProject(*ps)
	if err != nil {
		return err
	}

	s = *ns
	r.handler.Send(p, "Added new sprint to *"+ps.Name+"*: "+s.Id+" - "+s.Title)
	return nil
}