Esempio n. 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.")
	}
}
Esempio n. 2
0
func Task(c *cli.Context, withProject bool) {
	t, stories := api.Task(api.FindTaskId(c.Args().First(), true, withProject), c.Bool("verbose"))
	red := ansi.ColorCode("red")
	blue := ansi.ColorCode("blue")
	green := ansi.ColorCode("green")
	reset := ansi.ColorCode("reset")
	bold := ansi.ColorCode("white")
	yellow := ansi.ColorCode("yellow")

	fmt.Printf("[ %s%s%s ] %s%s%s\n", red, t.Due_on, reset, bold, t.Name, reset)

	showTags(t.Tags)

	fmt.Printf("\n%s\n", t.Notes)

	if stories != nil {
		fmt.Println("\n----------------------------------------\n")
		for _, s := range stories {
			color := ""

			if strings.HasPrefix(s.String(), "*") {
				color = blue
			}
			match, _ := regexp.MatchString("\\* .* attached", s.String())
			if match {
				color = yellow
			}

			if strings.HasPrefix(s.String(), ">") {
				color = green
			}

			fmt.Printf("%s%s%s\n", color, s, reset)
		}
	}
}