Example #1
0
func Comment(c *cli.Context, withProject bool) {
	taskId := api.FindTaskId(c.Args().First(), false, withProject)
	task, stories := api.Task(taskId, true)

	tmpFile := os.TempDir() + "/asana_comment.txt"
	f, err := os.Create(tmpFile)
	utils.Check(err)
	defer f.Close()

	err = template(f, task, stories)
	utils.Check(err)

	cmd := exec.Command(os.Getenv("EDITOR"), tmpFile)
	cmd.Stdin, cmd.Stdout = os.Stdin, os.Stdout
	err = cmd.Run()

	txt, err := ioutil.ReadFile(tmpFile)

	utils.Check(err)

	isForClose := getIsForClose(string(txt))
	asignee := getAsignee(string(txt))
	postComment := trim(string(txt))

	if postComment != "" {
		commented := api.CommentTo(taskId, postComment)
		fmt.Println("Commented on Task: \"" + task.Name + "\"\n")
		fmt.Println(commented)

		if isForClose {
			result := api.Update(taskId, "completed", "true")
			fmt.Println("Task closed \"" + task.Name + "\"\n")
			fmt.Println(result)
		}

		if asignee != "" {
			result := api.Update(taskId, "assignee", api.FindUserId(strings.Replace(asignee, "@", "", -1)))
			fmt.Println("New asignee \"" + asignee + "\"\n")
			fmt.Println(result)
		}
	} else {
		fmt.Println("Aborting comment due to empty content.")
	}
}
Example #2
0
func Assign(c *cli.Context, withProject bool) {
	assignee := c.Args()[1]

	task := api.Update(api.FindTaskId(c.Args().First(), false, withProject), "assignee", api.FindUserId(assignee))
	fmt.Println("assigned! : " + task.Name + " to " + task.Assignee.Name)
}