Commit graph

57 commits

Author SHA1 Message Date
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
AliabbasMerchant
5e56e31384 Added Test for --silent flag in api 2020-06-29 00:30:24 +05:30
Mislav Marohnić
c945fb4336 Automatically add per_page=100 to paginated REST requests
Most endpoints respect this parameter by default. Those that don't will
just ignore it. The `per_page=100` parameter is not added if there is
already a `per_page` parameter specified in the request.
2020-06-23 18:42:57 +02:00
Mislav Marohnić
f4ecd365a6 api command: add GraphQL support for --paginate 2020-06-17 18:02:20 +02:00
Mislav Marohnić
3f940c98f1 Add assertion for 1st api request before pagination 2020-06-16 18:19:39 +02:00
Mislav Marohnić
7907def880 api command: add support for REST pagination 2020-06-16 18:16:49 +02:00
Mislav Marohnić
3f6d0bff45 Switch to :owner/:repo syntax for placeholders 2020-06-11 21:46:27 +02:00
Mislav Marohnić
acf0046718 api command: support {owner} and {repo} placeholders
When `{owner}` and `{repo}` strings are found in request path (for REST
requests) or `query` (for GraphQL), they are replaced with values from
the repository of the current working directory.
2020-06-11 15:00:29 +02:00
Mislav Marohnić
74a39f3ed1 Turns out we do need explicit Content-Length for file uploads
This reverts commit 141388fd23.
2020-06-10 18:18:49 +02:00
Nate Smith
bd7e6bf00c
Merge branch 'trunk' into api-raw-body 2020-06-10 11:00:59 -05:00
Nate Smith
096bf6bb79
Merge pull request #1115 from cli/api-errors
Print HTTP errors on stderr in `api` command
2020-06-10 10:35:04 -05:00
Mislav Marohnić
141388fd23 Turns out, Go will automatically set Content-Length 2020-06-10 16:29:50 +02:00