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

Method NewOwner

pkg/cmd/project/shared/queries/queries.go:1440–1479  ·  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

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