Skip to content

Commit

Permalink
Moved code around in reject.go and comment.go
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Harry Lawrence committed Dec 23, 2015
1 parent 2993185 commit 66e648a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
39 changes: 20 additions & 19 deletions commands/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions commands/reject.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 66e648a

Please sign in to comment.