MCPcopy Create free account
hub / github.com/github/gh-aw / upsertDefaultsVariable

Function upsertDefaultsVariable

pkg/cli/env_command.go:535–550  ·  view source on GitHub ↗
(target defaultsTarget, name, value string)

Source from the content-addressed store, hash-verified

533}
534
535func upsertDefaultsVariable(target defaultsTarget, name, value string) error {
536 patchOut, patchErr := runDefaultsGH("api", "-X", "PATCH", target.variableEndpoint(name), "-f", "name="+name, "-f", "value="+value)
537 if patchErr == nil {
538 return nil
539 }
540 if !isDefaultsNotFoundError(patchErr, patchOut) {
541 return fmt.Errorf("failed to update %s: %w", name, errWithOutput(patchErr, patchOut))
542 }
543
544 envCmdLog.Printf("Variable %s not found via PATCH, creating via POST", name)
545 out, err := runDefaultsGH("api", "-X", "POST", target.variablesEndpoint(), "-f", "name="+name, "-f", "value="+value)
546 if err != nil {
547 return fmt.Errorf("failed to set %s: %w", name, errWithOutput(err, out))
548 }
549 return nil
550}
551
552func deleteDefaultsVariable(target defaultsTarget, name string) error {
553 out, err := runDefaultsGH("api", "-X", "DELETE", target.variableEndpoint(name))

Callers 1

defaultsUpdateFromFileFunction · 0.85

Calls 7

runDefaultsGHFunction · 0.85
isDefaultsNotFoundErrorFunction · 0.85
errWithOutputFunction · 0.85
variableEndpointMethod · 0.80
variablesEndpointMethod · 0.80
ErrorfMethod · 0.45
PrintfMethod · 0.45

Tested by

no test coverage detected