Commit graph

68 commits

Author SHA1 Message Date
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
wilso199
3ecb9de1a7 Adding a hostname flag option for use with gh api 2020-10-21 16:31:20 +00:00
Francisco Miamoto
bba2d6d204 improve test cases 2020-08-12 09:09:37 -03:00
Francisco Miamoto
b83342856b use factory method for branch
Also, improve the handling for the branch placeholder
2020-08-12 09:01:17 -03:00
Francisco Miamoto
9ebcec9aaf handle a detached head 2020-08-12 08:52:39 -03:00
Francisco Miamoto
0c10f67cd5 add branch placeholder for api calls 2020-08-12 08:52:39 -03:00
Martín Montes
27765f9987 Generalize REST error parsing 2020-08-07 14:22:20 +02:00
AliabbasMerchant
7a04bf1672 api --silent Changes:
Show Response Headers (if requested) even with `--silent` flag
Shift silent tests to `Test_apiRun`
Changed usage string of `--silent` flag
2020-06-30 19:18:28 +05:30
AliabbasMerchant
aa43c55f60 Skip printing headers when --silent in api 2020-06-29 07:13:06 +05:30