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

Method NewOwner

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

NewOwner creates a project Owner If canPrompt is false, login is required as we cannot prompt for it. If login is not empty, it is used to lookup the project owner. If login is empty, interactive mode is used to select an owner. from the current viewer and their organizations

(canPrompt bool, login string)

Source from the content-addressed store, hash-verified

1444// If login is empty, interactive mode is used to select an owner.
1445// from the current viewer and their organizations
1446func (c *Client) NewOwner(canPrompt bool, login string) (*Owner, error) {
1447 if login != "" {
1448 id, ownerType, err := c.OwnerIDAndType(login)
1449 if err != nil {
1450 return nil, err
1451 }
1452
1453 return &Owner{
1454 Login: login,
1455 Type: ownerType,
1456 ID: id,
1457 }, nil
1458 }
1459
1460 if !canPrompt {
1461 return nil, fmt.Errorf("owner is required when not running interactively")
1462 }
1463
1464 logins, err := c.userOrgLogins()
1465 if err != nil {
1466 return nil, err
1467 }
1468
1469 options := make([]string, 0, len(logins))
1470 for _, l := range logins {
1471 options = append(options, l.Login)
1472 }
1473
1474 answerIndex, err := c.prompter.Select("Which owner would you like to use?", "", options)
1475 if err != nil {
1476 return nil, err
1477 }
1478
1479 l := logins[answerIndex]
1480 return &Owner{
1481 Login: l.Login,
1482 Type: l.Type,
1483 ID: l.ID,
1484 }, nil
1485}
1486
1487// NewProject creates a project based on the owner and project number
1488// if canPrompt is false, number is required as we cannot prompt for it

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
resolveItemEditNamesFunction · 0.80

Calls 4

OwnerIDAndTypeMethod · 0.95
userOrgLoginsMethod · 0.95
ErrorfMethod · 0.65
SelectMethod · 0.65

Tested by 1

TestNewOwner_nonTTYFunction · 0.64