| 280 | } |
| 281 | |
| 282 | func editRun(opts *EditOptions) error { |
| 283 | httpClient, err := opts.HttpClient() |
| 284 | if err != nil { |
| 285 | return err |
| 286 | } |
| 287 | |
| 288 | if opts.Detector == nil { |
| 289 | baseRepo, err := opts.BaseRepo() |
| 290 | if err != nil { |
| 291 | return err |
| 292 | } |
| 293 | |
| 294 | cachedClient := api.NewCachedHTTPClient(httpClient, time.Hour*24) |
| 295 | opts.Detector = fd.NewDetector(cachedClient, baseRepo.RepoHost()) |
| 296 | } |
| 297 | |
| 298 | findOptions := shared.FindOptions{ |
| 299 | Selector: opts.SelectorArg, |
| 300 | Fields: []string{"id", "author", "url", "title", "body", "baseRefName", "reviewRequests", "labels", "projectCards", "projectItems", "milestone"}, |
| 301 | Detector: opts.Detector, |
| 302 | } |
| 303 | |
| 304 | if len(opts.Assets) > 0 { |
| 305 | findOptions.Fields = append(findOptions.Fields, "repository") |
| 306 | } |
| 307 | |
| 308 | issueFeatures, err := opts.Detector.IssueFeatures() |
| 309 | if err != nil { |
| 310 | return err |
| 311 | } |
| 312 | |
| 313 | // TODO ApiActorsSupported |
| 314 | if issueFeatures.ApiActorsSupported { |
| 315 | findOptions.Fields = append(findOptions.Fields, "assignedActors") |
| 316 | } else { |
| 317 | findOptions.Fields = append(findOptions.Fields, "assignees") |
| 318 | } |
| 319 | |
| 320 | pr, repo, err := opts.Finder.Find(findOptions) |
| 321 | if err != nil { |
| 322 | return err |
| 323 | } |
| 324 | |
| 325 | // Built before the prompts, so a run that cannot upload stops early. |
| 326 | var uploader *attachments.Uploader |
| 327 | if len(opts.Assets) > 0 { |
| 328 | cfg, err := opts.Config() |
| 329 | if err != nil { |
| 330 | return err |
| 331 | } |
| 332 | // A URL selector names its own host, so this can differ from the |
| 333 | // default host. |
| 334 | host := repo.RepoHost() |
| 335 | tokenType := cfg.Authentication().ActiveTokenType(host) |
| 336 | uploader, err = attachments.NewUploader(httpClient, tokenType, host, pr.RepositoryDatabaseID(), pr.RepositoryViewerPermission()) |
| 337 | if err != nil { |
| 338 | return err |
| 339 | } |