validateOwner validates that the owner exists
(ctx context.Context, ownerType, owner string, verbose bool)
| 227 | |
| 228 | // validateOwner validates that the owner exists |
| 229 | func validateOwner(ctx context.Context, ownerType, owner string, verbose bool) error { |
| 230 | projectLog.Printf("Validating %s: %s", ownerType, owner) |
| 231 | console.LogVerbose(verbose, fmt.Sprintf("Validating %s exists: %s", ownerType, owner)) |
| 232 | |
| 233 | var query string |
| 234 | if ownerType == "org" { |
| 235 | query = fmt.Sprintf(`query { organization(login: "%s") { id login } }`, escapeGraphQLString(owner)) |
| 236 | } else { |
| 237 | query = fmt.Sprintf(`query { user(login: "%s") { id login } }`, escapeGraphQLString(owner)) |
| 238 | } |
| 239 | |
| 240 | _, err := workflow.RunGH("Validating owner...", "api", "graphql", "-f", "query="+query) |
| 241 | if err != nil { |
| 242 | if ownerType == "org" { |
| 243 | return fmt.Errorf("organization '%s' not found or not accessible", owner) |
| 244 | } |
| 245 | return fmt.Errorf("user '%s' not found or not accessible", owner) |
| 246 | } |
| 247 | |
| 248 | console.LogVerbose(verbose, fmt.Sprintf("✓ %s '%s' validated", capitalizeFirst(ownerType), owner)) |
| 249 | return nil |
| 250 | } |
| 251 | |
| 252 | // capitalizeFirst capitalizes the first letter of a string |
| 253 | func capitalizeFirst(s string) string { |
no test coverage detected