func (r bot) set(p *robots.Payload, cmd utils.Command) error { name := cmd.Arg(0) if name == "" { r.handler.Send(p, "Missing Slack user name. Use `!user set <user-name> [mvn:<mavenlink-id>] [pvt:<pivotal-id>]`") return nil } mvnId := cmd.Param("mvn") pvtId := cmd.Param("pvt") user := db.User{Name: name} if mvnId != "" { mvnInt, err := strconv.ParseInt(mvnId, 10, 64) if err != nil { return err } user.MavenlinkId = &mvnInt } if pvtId != "" { pvtInt, err := strconv.ParseInt(pvtId, 10, 64) if err != nil { return err } user.PivotalId = &pvtInt } if err := db.SaveUser(user); err != nil { return err } r.handler.Send(p, "User *"+name+"* saved") return nil }
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 }
func (r bot) link(p *robots.Payload, cmd utils.Command) error { name := cmd.Arg(0) if name == "" { r.handler.Send(p, "Missing project name. Usage: !project link name mvn:id pvt:id") return nil } mvn := cmd.Param("mvn") if mvn == "" { r.handler.Send(p, "Missing mavenlink project. Usage: !project link name mvn:id pvt:id") return nil } pvt := cmd.Param("pvt") if pvt == "" { r.handler.Send(p, "Missing pivotal project. Usage: !project link name mvn:id pvt:id") return nil } err := r.makeLink(p, name, mvn, pvt) if err != nil { return err } return nil }
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 }