commentOnReview adds a comment to the current code review.
(repo repository.Repo, args []string)
| 132 | |
| 133 | // commentOnReview adds a comment to the current code review. |
| 134 | func commentOnReview(repo repository.Repo, args []string) error { |
| 135 | var r *review.Review |
| 136 | var err error |
| 137 | |
| 138 | if len(args) > 1 { |
| 139 | return errors.New("Only commenting on a single review is supported.") |
| 140 | } |
| 141 | if len(args) == 1 { |
| 142 | r, err = review.Get(repo, args[0]) |
| 143 | } else { |
| 144 | r, err = review.GetCurrent(repo) |
| 145 | } |
| 146 | |
| 147 | if err != nil { |
| 148 | return fmt.Errorf("Failed to load the review: %v\n", err) |
| 149 | } |
| 150 | if r == nil { |
| 151 | return errors.New("There is no matching review.") |
| 152 | } |
| 153 | |
| 154 | if err := validateArgs(repo, args, r.Comments); err != nil { |
| 155 | return err |
| 156 | } |
| 157 | |
| 158 | commentedUponCommit, err := r.GetHeadCommit() |
| 159 | if err != nil { |
| 160 | return err |
| 161 | } |
| 162 | |
| 163 | c, err := buildCommentFromFlags(r.Repo, commentedUponCommit) |
| 164 | if err != nil { |
| 165 | return err |
| 166 | } |
| 167 | return r.AddComment(*c) |
| 168 | } |
| 169 | |
| 170 | // commentOnPath adds a comment about the given file without attaching it to a review. |
| 171 | func commentOnPath(repo repository.Repo, args []string) error { |
no test coverage detected