MCPcopy Create free account
hub / github.com/cli/cli / editRun

Function editRun

pkg/cmd/pr/edit/edit.go:282–452  ·  view source on GitHub ↗
(opts *EditOptions)

Source from the content-addressed store, hash-verified

280}
281
282func 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 }

Callers 3

Test_editRunFunction · 0.70
NewCmdEditFunction · 0.70

Calls 15

UploadAndAttachMethod · 0.95
NewCachedHTTPClientFunction · 0.92
NewUploaderFunction · 0.92
NewClientFromHTTPFunction · 0.92
AssigneeSearchFuncFunction · 0.92
NewStringSetFunction · 0.92
reviewerSearchFuncFunction · 0.85
NamesMethod · 0.80
ProjectNamesMethod · 0.80
ProjectTitlesMethod · 0.80
AddValuesMethod · 0.80
DirtyMethod · 0.80

Tested by 2

Test_editRunFunction · 0.56