コード例 #1
0
ファイル: project.go プロジェクト: gistia/slackbot
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
}
コード例 #2
0
ファイル: project.go プロジェクト: gistia/slackbot
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
}
コード例 #3
0
ファイル: commands.go プロジェクト: gistia/slackbot
func StartedTasks(bot *UserBot, cmd utils.Command) error {
	username := bot.lastMessage.User.Name
	projects, err := db.GetProjects()
	if err != nil {
		return err
	}

	if projects == nil || len(projects) < 1 {
		bot.reply("There are no linked projects currently. Use `/project link` command to add one.")
		return nil
	}

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

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

	msg := ""
	for _, p := range projects {
		filter := map[string]string{
			"owned_by": user.StrPivotalId(),
			"state":    "started",
		}
		stories, err := pvt.FilteredStories(p.StrPivotalId(), filter)
		if err != nil {
			return err
		}

		if len(stories) < 1 {
			continue
		}

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

	if msg == "" {
		msg = "No started tasks for you"
	}

	bot.reply(msg)
	return nil
}
コード例 #4
0
ファイル: project.go プロジェクト: gistia/slackbot
func (r bot) addmember(p *robots.Payload, cmd utils.Command) error {
	name := cmd.Arg(0)
	if name == "" {
		err := errors.New(
			"Missing project name. Use `!project addmember <project> <username>`")
		return err
	}
	username := cmd.Arg(1)
	if name == "" {
		err := errors.New(
			"Missing user name. Use `!project addmember <project> <username>`")
		return err
	}

	pr, err := getProject(name)
	if err != nil {
		return err
	}

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

	if pr == nil {
		r.handler.Send(p, "Project *"+name+"* not found")
		return nil
	}

	user, err := db.GetUserByName(username)
	if pr == nil {
		r.handler.Send(p, "Project *"+name+"* not found")
		return nil
	}
	if user == nil {
		r.handler.Send(p, "User *"+username+"* not found")
		return nil
	}

	_, err = pvt.CreateProjectMembership(pr.StrPivotalId(), *user.PivotalId, "member")
	if err != nil {
		return err
	}

	r.handler.Send(p, "New member *"+username+"* added to *"+name+"*")
	return nil
}
コード例 #5
0
ファイル: pivotal.go プロジェクト: gistia/slackbot
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
}