MCPcopy Index your code
hub / github.com/cli/go-gh

github.com/cli/go-gh @v2.13.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.13.0 ↗ · + Follow
454 symbols 1,609 edges 66 files 163 documented · 36% 11 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Go library for the GitHub CLI

go-gh is a collection of Go modules to make authoring GitHub CLI extensions easier.

Modules from this library will obey GitHub CLI conventions by default:

  • repository.Current() respects the value of the GH_REPO environment variable and reads from git remote configuration as fallback.

  • GitHub API requests will be authenticated using the same mechanism as gh, i.e. using the values of GH_TOKEN and GH_HOST environment variables and falling back to the user's stored OAuth token.

  • Terminal capabilities are determined by taking environment variables GH_FORCE_TTY, NO_COLOR, CLICOLOR, etc. into account.

  • Generating table or Go template output uses the same engine as gh.

  • The browser module activates the user's preferred web browser.

Usage

See the full go-gh reference documentation for more information

package main

import (
    "fmt"
    "log"
    "github.com/cli/go-gh/v2"
    "github.com/cli/go-gh/v2/pkg/api"
)

func main() {
    // These examples assume `gh` is installed and has been authenticated.

    // Shell out to a gh command and read its output.
    issueList, _, err := gh.Exec("issue", "list", "--repo", "cli/cli", "--limit", "5")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(issueList.String())

    // Use an API client to retrieve repository tags.
    client, err := api.DefaultRESTClient()
    if err != nil {
        log.Fatal(err)
    }
    response := []struct{
        Name string
    }{}
    err = client.Get("repos/cli/cli/tags", &response)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(response)
}

See examples for more demonstrations of usage.

Contributing

If anything feels off, or if you feel that some functionality is missing, please check out our contributing docs. There you will find instructions for sharing your feedback and for submitting pull requests to the project. Thank you!

Extension points exported contracts — how you extend this code

TablePrinter (Interface)
(no doc) [2 implementers]
pkg/tableprinter/table.go
FileWriter (Interface)
FileWriter provides a minimal writable interface for stdout and stderr.
pkg/prompter/prompter.go
FileReader (Interface)
FileReader provides a minimal readable interface for stdin.
pkg/prompter/prompter.go

Core symbols most depended-on inside this repo

String
called by 60
internal/yamlmap/yaml_map.go
code
called by 42
pkg/x/markdown/accessibility.go
AddField
called by 33
pkg/tableprinter/table.go
Get
called by 31
pkg/api/rest_client.go
Set
called by 28
pkg/config/config.go
ReadFromString
called by 17
pkg/config/config.go
Parse
called by 16
pkg/template/template.go
IsModified
called by 16
internal/yamlmap/yaml_map.go

Shape

Function 290
Method 111
Struct 47
Interface 3
TypeAlias 2
FuncType 1

Languages

Go100%

Modules by API surface

pkg/tableprinter/table.go22 symbols
pkg/template/template.go20 symbols
pkg/prompter/mock.go20 symbols
pkg/config/config.go19 symbols
pkg/config/config_test.go18 symbols
pkg/term/env.go17 symbols
internal/yamlmap/yaml_map.go16 symbols
pkg/api/rest_client.go14 symbols
pkg/api/http_client.go14 symbols
pkg/api/cache.go14 symbols
pkg/prompter/prompter.go13 symbols
pkg/auth/auth.go12 symbols

For agents

$ claude mcp add go-gh \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact