2018-07-15 10:26:11 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2018-07-31 16:18:09 +03:00
|
|
|
"fmt"
|
2018-08-13 19:32:11 +03:00
|
|
|
|
2018-07-15 10:26:11 +03:00
|
|
|
"github.com/MichaelMure/git-bug/bug"
|
|
|
|
"github.com/MichaelMure/git-bug/bug/operations"
|
2018-07-31 16:18:09 +03:00
|
|
|
"github.com/MichaelMure/git-bug/input"
|
2018-07-19 13:30:25 +03:00
|
|
|
"github.com/spf13/cobra"
|
2018-07-15 10:26:11 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2018-07-19 13:30:25 +03:00
|
|
|
commentMessageFile string
|
|
|
|
commentMessage string
|
2018-07-15 10:26:11 +03:00
|
|
|
)
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
func runComment(cmd *cobra.Command, args []string) error {
|
2018-07-15 10:26:11 +03:00
|
|
|
var err error
|
|
|
|
|
|
|
|
if len(args) > 1 {
|
2018-07-17 20:28:37 +03:00
|
|
|
return errors.New("Only one bug id is supported")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(args) == 0 {
|
|
|
|
return errors.New("You must provide a bug id")
|
2018-07-15 10:26:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
prefix := args[0]
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
if commentMessageFile != "" && commentMessage == "" {
|
|
|
|
commentMessage, err = input.FromFile(commentMessageFile)
|
2018-07-15 10:26:11 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2018-07-31 16:18:09 +03:00
|
|
|
|
|
|
|
if commentMessage == "" {
|
2018-07-31 17:43:43 +03:00
|
|
|
commentMessage, err = input.BugCommentEditorInput(repo)
|
2018-07-31 16:18:09 +03:00
|
|
|
if err == input.ErrEmptyMessage {
|
|
|
|
fmt.Println("Empty message, aborting.")
|
|
|
|
return nil
|
|
|
|
}
|
2018-07-15 10:26:11 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
author, err := bug.GetUser(repo)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-23 01:04:46 +03:00
|
|
|
b, err := bug.FindLocalBug(repo, prefix)
|
2018-07-15 10:26:11 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-25 19:01:32 +03:00
|
|
|
operations.Comment(b, author, commentMessage)
|
2018-07-15 10:26:11 +03:00
|
|
|
|
2018-07-25 19:01:32 +03:00
|
|
|
return b.Commit(repo)
|
2018-07-15 10:26:11 +03:00
|
|
|
}
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
var commentCmd = &cobra.Command{
|
|
|
|
Use: "comment <id> [<options>...]",
|
|
|
|
Short: "Add a new comment to a bug",
|
|
|
|
RunE: runComment,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-07-20 16:46:14 +03:00
|
|
|
RootCmd.AddCommand(commentCmd)
|
2018-07-19 13:30:25 +03:00
|
|
|
|
|
|
|
commentCmd.Flags().StringVarP(&commentMessageFile, "file", "F", "",
|
|
|
|
"Take the message from the given file. Use - to read the message from the standard input",
|
|
|
|
)
|
|
|
|
|
|
|
|
commentCmd.Flags().StringVarP(&commentMessage, "message", "m", "",
|
|
|
|
"Provide the new message from the command line",
|
|
|
|
)
|
2018-07-15 10:26:11 +03:00
|
|
|
}
|