MCPcopy
hub / github.com/cli/cli / NewProject

Method NewProject

pkg/cmd/project/shared/queries/queries.go:1445–1501  ·  view source on GitHub ↗

NewProject creates a project based on the owner and project number if canPrompt is false, number is required as we cannot prompt for it if number is 0 it will prompt the user to select a project interactively otherwise it will make a request to get the project by number set `fields“ to true to get t

(canPrompt bool, o *Owner, number int32, fields bool)

Source from the content-addressed store, hash-verified

1443// otherwise it will make a request to get the project by number
1444// set `fields“ to true to get the project's field data
1445func (c *Client) NewProject(canPrompt bool, o *Owner, number int32, fields bool) (*Project, error) {
1446 if number != 0 {
1447 variables := map[string]interface{}{
1448 "number": githubv4.Int(number),
1449 "firstItems": githubv4.Int(0),
1450 "afterItems": (*githubv4.String)(nil),
1451 "firstFields": githubv4.Int(0),
1452 "afterFields": (*githubv4.String)(nil),
1453 }
1454
1455 if fields {
1456 variables["firstFields"] = githubv4.Int(LimitMax)
1457 }
1458 if o.Type == UserOwner {
1459 var query userOwner
1460 variables["login"] = githubv4.String(o.Login)
1461 err := c.doQueryWithProgressIndicator("UserProject", &query, variables)
1462 return newProjectFromQueryWithoutItemsQuery(query.Owner.Project), err
1463 } else if o.Type == OrgOwner {
1464 variables["login"] = githubv4.String(o.Login)
1465 var query orgOwner
1466 err := c.doQueryWithProgressIndicator("OrgProject", &query, variables)
1467 return newProjectFromQueryWithoutItemsQuery(query.Owner.Project), err
1468 } else if o.Type == ViewerOwner {
1469 var query viewerOwner
1470 err := c.doQueryWithProgressIndicator("ViewerProject", &query, variables)
1471 return newProjectFromQueryWithoutItemsQuery(query.Owner.Project), err
1472 }
1473 return nil, errors.New("unknown owner type")
1474 }
1475
1476 if !canPrompt {
1477 return nil, fmt.Errorf("project number is required when not running interactively")
1478 }
1479
1480 projects, err := c.Projects(o.Login, o.Type, 0, fields)
1481 if err != nil {
1482 return nil, err
1483 }
1484
1485 if len(projects.Nodes) == 0 {
1486 return nil, fmt.Errorf("no projects found for %s", o.Login)
1487 }
1488
1489 options := make([]string, 0, len(projects.Nodes))
1490 for _, p := range projects.Nodes {
1491 title := fmt.Sprintf("%s (#%d)", p.Title, p.Number)
1492 options = append(options, title)
1493 }
1494
1495 answerIndex, err := c.prompter.Select("Which project would you like to use?", "", options)
1496 if err != nil {
1497 return nil, err
1498 }
1499
1500 return &projects.Nodes[answerIndex], nil
1501}
1502

Callers 15

runCloseFunction · 0.80
runLinkFunction · 0.80
runCopyFunction · 0.80
runMarkTemplateFunction · 0.80
runListFunction · 0.80
runDeleteFunction · 0.80
runViewFunction · 0.80
runCreateFieldFunction · 0.80
runDeleteItemFunction · 0.80
runAddItemFunction · 0.80
runListFunction · 0.80
TestNewProject_nonTTYFunction · 0.80

Calls 6

ProjectsMethod · 0.95
ErrorfMethod · 0.65
SelectMethod · 0.65
StringMethod · 0.45

Tested by 1

TestNewProject_nonTTYFunction · 0.64