Commit graph

76 commits

Author SHA1 Message Date
William Martin
268453803e fix(api): propagate InvokingAgent in gh api HTTP client
The gh api command builds its own HTTP client inline without
forwarding InvokingAgent, so the User-Agent header was missing
the Agent/<name> suffix when invoked by AI coding agents.

Thread InvokingAgent through Factory → ApiOptions → HTTPClientOptions,
mirroring the existing AppVersion pattern.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 16:55:16 +01:00
William Martin
8deae3038a Use active token stubbing on auth config 2025-06-17 15:53:13 +02:00
Anuraag Agrawal
cc9a2411e0 Cleanup 2025-05-29 12:28:26 +09:00
Anuraag Agrawal
f294a5f533 fix: get token for active user instead of blank if possible 2025-05-29 12:13:21 +09:00
William Martin
f4382d1345 Revert "Merge pull request #10384 from iamazeem/9798-gh-api-encode-package-name"
This reverts commit ed2c322a73, reversing
changes made to f019cf7cea.
2025-03-18 13:13:06 +01:00
Tyler McGoffin
ed2c322a73
Merge pull request #10384 from iamazeem/9798-gh-api-encode-package-name
[gh api] Escape package name (URL encoding) for packages endpoint
2025-02-25 11:12:48 -08:00
Josh Soref
023e347078 Do not try to parse bodies for HEAD requests
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2025-02-07 14:31:15 -05:00
Azeem Sajid
4107944f39 [gh api] Escape package name (URL encoding) for packages endpoint 2025-02-07 13:12:04 +05:00
William Martin
1d38230675
Move config interfaces into gh package (#9060) 2024-05-10 10:39:36 +02:00
Babak K. Shandiz
7c4e45cc9d
Fix issue with closing pager stream (#9020)
Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com>
2024-04-29 15:48:08 +02:00
William Martin
fd4f2c9c1f
Merge pull request #8620 from heaths/merge-json
Merge JSON responses from `gh api`
2024-04-17 11:45:13 +02:00
William Martin
9738d68bba Fix api cache test 2024-04-05 16:47:29 +02:00
Heath Stewart
4ea7bcacb3
Run defers in queue 2024-04-04 01:26:10 -07:00
Heath Stewart
e83e049306
Wrap JSON arrays, objects in array with --slurp
Effectively copies `jq --slurp` since `--jq` already uses the same grammar.
2024-04-04 01:26:05 -07:00
Heath Stewart
f41876d64c
Resolve PR comments 2024-04-04 01:21:04 -07:00
Heath Stewart
48f0cd6f11
Replace --paginate-all with --merge-pages 2024-04-04 01:21:02 -07:00
Heath Stewart
310e5524ba
Resolve test issues 2024-04-04 01:21:01 -07:00
Heath Stewart
e7f5dded06
Add more JSON merge tests 2024-04-04 01:21:00 -07:00
Heath Stewart
8e27e9a8cd
Merge JSON responses from gh api
Partly resolves cli/cli#1268 and replaces cli/cli#5652. Requires cli/go-gh#148 to be merged and optionally released.
2024-04-04 01:06:43 -07:00
Sam Coe
ebcf3a1022
Set default Accept header for api command when one is not specified (#8303) 2023-11-06 15:22:32 +01:00
Jun Nishimura
508065b72d
Add verbose flag to api cmd (#7826) 2023-08-25 09:37:37 -07:00
Alex Petrov
343896fdac
Do not interpret "branch" placeholder in api command when GH_REPO is set (#7626)
* fix(api): do not interpret "branch" placeholder when `GH_REPO` is set

Before, we would always interpret the "branch" placeholder, typically
setting it to the currently checked-out branch in the repository in the
current working directory. It didn't make sense to do that when the
`GH_REPO` environment variable was specified because the repository
would likely be different from the one in the current working directory.

Now, we instead report an error if both `GH_REPO` environment variable
and `branch` placeholder are specified.
2023-07-06 07:05:40 +00:00
Mislav Marohnić
63a4319f6c
api: output a single JSON array in REST pagination mode (#7190)
When fetching N pages, avoid printing N separate JSON arrays to the output stream. Instead, massage the output so that the N pages of data are merged into a single JSON array. This is achieved by omitting the final `]` for the first page, and omitting the initial `[` for all subsequent pages.
2023-06-09 20:55:06 +02:00
Martijn Pieters
530002ee7a
Pretty-print JSON results of jq filtering (#7236)
When connected to a TTY, tell the jq formatter to indent the output, and
enable colorization of the output if the terminal supports it.

Co-authored-by: Mislav Marohnić <mislav@github.com>
2023-04-25 13:27:17 +00:00
Sam Coe
dbc2f05124
Update go-gh to v2 (#7299)
* Update go-gh

* Update code for go-gh v2
2023-04-16 15:34:23 +10:00
Kevin Lee
9dc2653b0f
Warn against Windows absolute path when using gh api (#6895)
This warning is primarily for Windows users on MinGW applications like Git Bash

Co-authored-by: Mislav Marohnić <mislav@github.com>
2023-01-24 17:40:15 +01:00
Mislav Marohnić
6a5532481f
Avoid sending empty JSON body when no params to api command (#6775) 2022-12-22 21:45:17 +01:00
Mislav Marohnić
c5c2f9cc10
Supported passing nested JSON arrays/objects to api command via fields (#6614)
Examples:

	-f labels[]=bug -f labels[]=p1
        #=> { "labels": ["bug", "p1"] }

	-f branch[name]=patch-1 -F branch[protected]=true
        #=> { "branch": { "name": "patch-1", "protected": true }

	-f labels[][name]=bug-1 -f labels[][color]=red
        #=> { "labels": [{ "name": "bug-1", "color": "red" }] }
2022-12-22 20:12:00 +01:00
Sam Coe
6a8deb1f5a
Integrate latest go-gh packages (#6084) 2022-08-18 09:04:13 +03:00
Mislav Marohnić
56dfed531b api: fix writing response headers to terminal pager 2022-08-10 10:53:07 +02:00
Sam Coe
074ed50b8a
Integrate go-gh API package (#5614) 2022-06-23 04:05:31 +01:00
Håvard Anda Estensen
58cb773e09
Replace ioutil with io and os (#5498) 2022-04-26 13:07:44 +02:00
Sam Coe
e68aa12564
Dont execute jq filters or templates when api requests are not successful (#5088) 2022-01-29 09:32:01 +02:00
Mislav Marohnić
ead6bf87d9 api: handle HTTP 409 error message from the server
Previously, "errors" field was either an array of strings or an array of
error objects. This covers an additional case when "errors" is a string:

    $ gh api orgs/cli/actions/permissions/repositories
    {
      "message": "Conflict",
      "errors": "Actions are enabled for all repositories",
      "documentation_url": "https://docs.github.com/rest/reference/actions#list-selected-repositories-enabled-for-github-actions-in-an-organization"
    }
2021-12-06 19:54:54 +01:00
Mislav Marohnić
01adff037f api: prevent repeating GET parameters when paginating 2021-10-18 20:18:23 +02:00
Mislav Marohnić
11fbb60ae7 Rename the module to "github.com/cli/cli/v2" 2021-08-25 12:41:30 +02:00
Heath Stewart
e2973453b5
Add helper template functions for rendering tables (#3519)
Co-authored-by: Mislav Marohnić <mislav@github.com>
2021-08-23 21:00:25 +02:00
Cristian Dominguez
2f94adabb2
Use T.TempDir for temporary dirs in tests (#3580) 2021-05-07 12:21:26 +02:00
Mislav Marohnić
6a57dcfd7d 💅 cleanup placeholder implementation 2021-04-30 14:22:25 +02:00
Robin Neatherway
59b4d5cb7c Support standard path variable replacement syntax
Add support for the following synonyms:

{owner} for :owner
{repo} for :repo
{branch} for :branch
2021-04-30 14:22:25 +02:00
Sam
9ec1e21d4c
Default to GHES host if only GHES is authenticated (#3286) 2021-03-30 16:51:00 +02:00
Mislav Marohnić
4e24f36495 Declare --jq, --template, --silent options mutually exclusive 2021-03-04 17:29:59 +01:00
Mislav Marohnić
d89756c94c Add test for api --jq 2021-03-04 17:10:48 +01:00
Mislav Marohnić
06eeea0737 Change the api --filter flag to api --jq 2021-03-04 17:05:31 +01:00
Mislav Marohnić
eb08774370 Assert that executeTemplate is invoked 2021-03-04 16:48:06 +01:00
Mislav Marohnić
0f27084f57 Add flag parsing test for api --template 2021-03-04 15:01:59 +01:00
Mislav Marohnić
07cb5e9e17 Merge remote-tracking branch 'origin' into api-template 2021-03-04 14:53:08 +01:00
Mislav Marohnić
440b59f8c3 Add the api --preview flag to opt into GitHub API previews
This was previously available manually via the `-H` flag, but it was
verbose, especially when opting into multiple previews.
2021-03-03 20:12:51 +01:00
Mislav Marohnić
bf97c6e273 Add template functions, documentation, tests 2021-03-02 20:07:04 +01:00
Mislav Marohnić
e32e6406a7 Add test for api --cache behavior 2021-03-01 16:04:19 +01:00