commentOnPath adds a comment about the given file without attaching it to a review.
(repo repository.Repo, args []string)
| 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 { |
| 172 | if *commentFile == "" { |
| 173 | return errors.New("You must specify the containing file for detached comments.") |
| 174 | } |
| 175 | |
| 176 | if len(args) > 1 { |
| 177 | return errors.New("Only commenting on a single location is supported.") |
| 178 | } |
| 179 | var commentedUponRef string |
| 180 | if len(args) == 1 { |
| 181 | commentedUponRef = args[0] |
| 182 | } else { |
| 183 | commentedUponRef = "HEAD" |
| 184 | } |
| 185 | commentedUponCommit, err := repo.ResolveRefCommit(commentedUponRef) |
| 186 | if err != nil { |
| 187 | return fmt.Errorf("Failed to resolve the comment location: %v\n", err) |
| 188 | } |
| 189 | |
| 190 | commentThreads, err := review.GetDetachedComments(repo, *commentFile) |
| 191 | if err != nil { |
| 192 | return err |
| 193 | } |
| 194 | if err := validateArgs(repo, args, commentThreads); err != nil { |
| 195 | return err |
| 196 | } |
| 197 | |
| 198 | c, err := buildCommentFromFlags(repo, commentedUponCommit) |
| 199 | if err != nil { |
| 200 | return err |
| 201 | } |
| 202 | return review.AddDetachedComment(repo, c) |
| 203 | } |
| 204 | |
| 205 | // commentCmd defines the "comment" subcommand. |
| 206 | var commentCmd = &Command{ |
no test coverage detected