Ejemplo n.º 1
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
}
Ejemplo n.º 2
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
}
Ejemplo n.º 3
0
func (r bot) myStories(p *robots.Payload, cmd utils.Command) error {
	name := cmd.Arg(0)
	var pr *db.Project
	var err error

	if name == "" {
		pr, err = db.GetProjectByChannel(p.ChannelName)
	} else {
		pr, err = db.GetProjectByName(name)
	}

	if err != nil {
		return err
	}

	if pr == nil {
		r.handler.Send(p, "Missing project name.")
		return nil
	}

	pvt, err := pivotal.NewFor(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",
	}
	stories, err := pvt.FilteredStories(pr.StrPivotalId(), filter)
	if err != nil {
		return err
	}

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

	str := "Current stories in project *" + pr.Name + "* 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
}
Ejemplo n.º 4
0
func (r bot) addStories(p *robots.Payload, cmd utils.Command) error {
	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+"*.")
		return nil
	}

	appUrl := os.Getenv("APP_URL")
	url := appUrl + "poker?channel=" + p.ChannelName + "&channel_id=" + p.ChannelID
	a := utils.FmtAttachment("", "Click here to add stories", url, "Add stories in back to this session by following the link")
	r.handler.SendWithAttachments(p, "", []robots.Attachment{a})
	return nil
}
Ejemplo n.º 5
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
}
Ejemplo n.º 6
0
func (r bot) pullRequests(p *robots.Payload, cmd utils.Command) error {
	repo := cmd.Arg(0)
	if repo == "" {
		return errors.New("Missing repo name. Use `!github prs <repo-name>`")
	}

	parts := strings.Split(repo, "/")
	owner := parts[0]
	name := parts[1]
	client, err := r.getClient(p.UserName)
	if err != nil {
		return err
	}

	prs, _, err := client.PullRequests.List(owner, name, nil)
	if err != nil {
		return err
	}

	if len(prs) < 1 {
		r.handler.Send(p, "No open pull requests for *"+repo+"*")
		return nil
	}

	s := "Open pull requests for *" + repo + "*:\n"
	atts := []robots.Attachment{}

	for _, pr := range prs {
		atts = append(atts, utils.FmtAttachment(
			fmt.Sprintf("%d - %s", *pr.Number, *pr.Title),
			*pr.Title,
			*pr.HTMLURL,
			fmt.Sprintf("#%d %s on %s by %s",
				*pr.Number, *pr.State,
				(*pr.CreatedAt).Format("Jan 2, 2006"), *pr.User.Login)))
	}

	r.handler.SendWithAttachments(p, s, atts)
	return nil
}
Ejemplo n.º 7
0
func (r bot) addStory(p *robots.Payload, cmd utils.Command) error {
	name := cmd.Arg(0)
	if name == "" {
		err := errors.New(
			"Missing project name. Use `!project addtask <project> [type:<story-type>] <task-name>`")
		return err
	}

	storyType := cmd.Param("type")
	if storyType == "" {
		storyType = "feature"
	}

	storyName := strings.Join(cmd.ArgsFrom(1), " ")
	if storyName == "" {
		err := errors.New(
			"Missing story name. Use `!project addtask <project> <task-name>`")
		return err
	}

	pr, err := getProject(name)
	if err != nil {
		return err
	}
	mvn, err := mavenlink.NewFor(p.UserName)
	if err != nil {
		return err
	}
	pvt, err := pivotal.NewFor(p.UserName)
	if err != nil {
		return err
	}

	pvtStory := pivotal.Story{
		Name:      storyName,
		ProjectId: pr.PivotalId,
		Type:      storyType,
	}
	pvtNewStory, err := pvt.CreateStory(pvtStory)
	if err != nil {
		return err
	}

	desc := fmt.Sprintf("[pvt:%d]", pvtNewStory.Id)
	mvnStory := mavenlink.Story{
		Title:       storyName,
		Description: desc,
		ParentId:    pr.MvnSprintStoryId,
		WorkspaceId: strconv.FormatInt(pr.MavenlinkId, 10),
		StoryType:   "task",
	}
	mvnNewStory, err := mvn.CreateStory(mvnStory)
	if err != nil {
		return err
	}

	tmpStory := pivotal.Story{
		Id:          pvtNewStory.Id,
		Description: "[mvn:" + mvnNewStory.Id + "]",
	}
	pvtNewStory, err = pvt.UpdateStory(tmpStory)
	if err != nil {
		return err
	}

	pvtAtt := utils.FmtAttachment(
		fmt.Sprintf("- Pivotal %d - %s\n", pvtNewStory.Id, pvtNewStory.Name),
		fmt.Sprintf("Pivotal %d - %s\n", pvtNewStory.Id, pvtNewStory.Name),
		pvtNewStory.Url, "")
	mvnAtt := utils.FmtAttachment(
		fmt.Sprintf("- Mavenlink %s - %s\n", mvnNewStory.Id, mvnNewStory.Title),
		fmt.Sprintf("Mavenlink %s - %s\n", mvnNewStory.Id, mvnNewStory.Title),
		mvnNewStory.URL(), "")

	s := "Stories successfully added:\n"
	r.handler.SendWithAttachments(p, s, []robots.Attachment{pvtAtt, mvnAtt})
	return nil
}