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