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

Method NewOwner

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

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