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

Method fromEnv

acceptance/acceptance_test.go:1307–1354  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1305}
1306
1307func (e *testScriptEnv) fromEnv() error {
1308 envMap := map[string]string{}
1309
1310 requiredEnvVars := []string{
1311 "GH_ACCEPTANCE_HOST",
1312 "GH_ACCEPTANCE_ORG",
1313 "GH_ACCEPTANCE_TOKEN",
1314 }
1315
1316 var missingEnvs []string
1317 for _, key := range requiredEnvVars {
1318 val, ok := os.LookupEnv(key)
1319 if val == "" || !ok {
1320 missingEnvs = append(missingEnvs, key)
1321 continue
1322 }
1323
1324 envMap[key] = val
1325 }
1326
1327 if len(missingEnvs) > 0 {
1328 return missingEnvError{missingEnvs: missingEnvs}
1329 }
1330
1331 if envMap["GH_ACCEPTANCE_ORG"] == "github" || envMap["GH_ACCEPTANCE_ORG"] == "cli" {
1332 return fmt.Errorf("GH_ACCEPTANCE_ORG cannot be 'github' or 'cli'")
1333 }
1334
1335 e.host = envMap["GH_ACCEPTANCE_HOST"]
1336 e.org = envMap["GH_ACCEPTANCE_ORG"]
1337 e.token = envMap["GH_ACCEPTANCE_TOKEN"]
1338 var err error
1339 e.hasUserCapability, err = tokenHasUserCapability(e.token)
1340 if err != nil {
1341 return err
1342 }
1343
1344 e.scripts = parseScriptFilter(os.Getenv("GH_ACCEPTANCE_SCRIPT"))
1345 e.preserveWorkDir = os.Getenv("GH_ACCEPTANCE_PRESERVE_WORK_DIR") == "true"
1346 e.skipDefer = os.Getenv("GH_ACCEPTANCE_SKIP_DEFER") == "true"
1347 e.apiHost = os.Getenv("GH_ACCEPTANCE_API_HOST")
1348 e.user = os.Getenv("GH_ACCEPTANCE_USER")
1349 if e.apiHost != "" && e.user == "" {
1350 return fmt.Errorf("GH_ACCEPTANCE_USER is required when GH_ACCEPTANCE_API_HOST is set")
1351 }
1352
1353 return nil
1354}

Callers 1

TestAcceptanceFunction · 0.95

Calls 3

tokenHasUserCapabilityFunction · 0.85
parseScriptFilterFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected