Repositories

As suggested in #21, various checks before a message is added to either the comment or rejection are made. This seems to make more sense.

Modified commands/comment.go

@@ -44,6 +44,26 @@ var (
func commentOnReview(repo repository.Repo, args []string) error {
commentFlagSet.Parse(args)
args = commentFlagSet.Args()
var r *review.Review
var err error
if len(args) > 1 {
return errors.New("Only accepting a single review is supported.")
}
if len(args) == 1 {
r, err = review.Get(repo, args[0])
} else {
r, err = review.GetCurrent(repo)
}
if err != nil {
return fmt.Errorf("Failed to load the review: %v\n", err)
}
if r == nil {
return errors.New("There is no matching review.")
}
if *commentMessage == "" {
editor, err := repo.GetCoreEditor()
if err != nil {
@@ -81,25 +101,6 @@ func commentOnReview(repo repository.Repo, args []string) error {
return errors.New("Specifying a line number with the -l flag requires that you also specify a file name with the -f flag.")
}
var r *review.Review
var err error
if len(args) > 1 {
return errors.New("Only accepting a single review is supported.")
}
if len(args) == 1 {
r, err = review.Get(repo, args[0])
} else {
r, err = review.GetCurrent(repo)
}
if err != nil {
return fmt.Errorf("Failed to load the review: %v\n", err)
}
if r == nil {
return errors.New("There is no matching review.")
}
commentedUponCommit, err := r.GetHeadCommit()
if err != nil {
return err

Modified commands/reject.go

@@ -40,6 +40,25 @@ func rejectReview(repo repository.Repo, args []string) error {
rejectFlagSet.Parse(args)
args = rejectFlagSet.Args()
var r *review.Review
var err error
if len(args) > 1 {
return errors.New("Only rejecting a single review is supported.")
}
if len(args) == 1 {
r, err = review.Get(repo, args[0])
} else {
r, err = review.GetCurrent(repo)
}
if err != nil {
return fmt.Errorf("Failed to load the review: %v\n", err)
}
if r == nil {
return errors.New("There is no matching review.")
}
if *rejectMessage == "" {
editor, err := repo.GetCoreEditor()
if err != nil {
@@ -71,25 +90,6 @@ func rejectReview(repo repository.Repo, args []string) error {
os.Remove(path)
}
var r *review.Review
var err error
if len(args) > 1 {
return errors.New("Only rejecting a single review is supported.")
}
if len(args) == 1 {
r, err = review.Get(repo, args[0])
} else {
r, err = review.GetCurrent(repo)
}
if err != nil {
return fmt.Errorf("Failed to load the review: %v\n", err)
}
if r == nil {
return errors.New("There is no matching review.")
}
rejectedCommit, err := r.GetHeadCommit()
if err != nil {
return err