Commit graph

58 commits

Author SHA1 Message Date
Mislav Marohnić
329ba1d57b Add --filter to api command to filter data using jq syntax 2021-02-22 17:51:58 +01:00
Mislav Marohnić
fd82d621d5 Add color function to api templates 2021-02-22 16:54:27 +01:00
Mislav Marohnić
517cfc2365 Add api --format flag for specifying an output template
With the `--format` flag, the value of the flag is parsed as a Go
template which is then evaluated against parsed response data.
https://golang.org/pkg/text/template
2021-02-22 16:15:02 +01:00
Mislav Marohnić
9dff05bf20 Add api --cache flag
Cache API responses on disk for a specified duration.
2021-02-22 16:13:24 +01:00
Mislav Marohnić
335f0117c0 Add more examples to api docs
- Clarify that fields need to be in "key=value" format
- Headers need to be in "key:value" format
- Contrast POST vs GET requests with params in examples
- Add an example of how to add HTTP headers
- Use backticks where applicable
2021-02-11 19:17:10 +01:00
vilmibm
e92cd43259 add IOStreams.ReadUserFile 2020-11-23 11:21:28 -08:00
Sam Coe
414de332fb
cleanup 2020-11-12 09:52:14 +03:00
Sam Coe
a79a0bbfd7
Add support for GH_TOKEN and GH_ENTERPRISE_TOKEN 2020-11-12 09:52:10 +03:00
Mislav Marohnić
fbff1fcfd2 Clarify the --hostname flag 2020-10-21 16:45:06 +00:00
Mislav Marohnić
228191bf85 Document GH_HOST for api command 2020-10-21 16:43:48 +00:00
Mislav Marohnić
460d55f723 Move HostnameValidator to ghinstance 2020-10-21 16:31:20 +00:00
wilso199
3ecb9de1a7 Adding a hostname flag option for use with gh api 2020-10-21 16:31:20 +00:00
Mislav Marohnić
50291aa6de Add PAGER support to the api command 2020-09-15 11:43:49 +02:00
Mislav Marohnić
ece17c4ce2 Add GITHUB_ENTERPRISE_TOKEN mention to api help 2020-09-07 21:37:55 +02:00
Mislav Marohnić
d8c5b7bfc0
Merge pull request #1517 from cli/select-host
Allow explicitly setting hostname for gh operations
2020-08-14 19:08:13 +02:00
Mislav Marohnić
c095a4bead Allow explicitly specifying the hostname for gh operations
Accept the "HOST/OWNER/REPO" syntax or passing a full URL for both the
`--repo` flag and the GH_REPO environment variable and allow setting
GH_HOST environment variable to override just the hostname for
operations that assume "github.com" by default.

Examples:

    $ gh repo clone example.org/owner/repo
    $ GH_HOST=example.org gh repo clone repo

    $ GH_HOST=example.org gh api user
    $ GH_HOST=example.org gh gist create myfile.txt

    $ gh issue list -R example.org/owner/repo
    $ gh issue list -R https://example.org/owner/repo.git
    $ GH_REPO=example.org/owner/repo gh issue list
2020-08-12 16:16:34 +02:00
Mislav Marohnić
e7a8b1e94e
Add documentation for ":branch" placeholder 2020-08-12 14:54:58 +02:00
Francisco Miamoto
800be370de propagate error from closure 2020-08-12 09:18:43 -03: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
Mislav Marohnić
2ab06ab4d6
Merge pull request #1415 from cli/ghe-api
Add GHE compatibility to the API adapter
2020-08-03 17:19:20 +02:00
Mislav Marohnić
d26cd64745 Support GraphQL operationName in gh api command
GraphQL supports supplying multiple queries in the `query` parameter,
but an additional `operationName` parameter is then required to select
the query to execute.

Previously, it was impossible to pass `operationName` since it would get
serialized under `variables`, but it needs to be a top-level parameter.
With this change, `operationName` is a special GraphQL parameter name
just like `query` already is.
2020-07-29 16:47:33 +02:00
Mislav Marohnić
288d01318b Respect the hostname of current repository in queries 2020-07-23 22:31:08 +02:00
Mislav Marohnić
75086f0b80 💅 Improve readability of api example code
Tab indentation is replaced with two spaces to curb deep indentation.
2020-07-16 17:46:25 +02:00
Mislav Marohnić
9e4af479da Add command line docs for supported environment variables 2020-07-16 17:46:09 +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
AliabbasMerchant
cb2308c077 --silent flag in api 2020-06-29 00:15:34 +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
vilmibm
8263cd238b linter appeasement 2020-06-10 11:05:21 -05: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
Mislav Marohnić
b099bb3037 api command: accept full URLs as path input
This is to allow file uploads to `https://uploads.github.com`
2020-06-10 16:26:23 +02:00
Mislav Marohnić
b329919b19 api command: support raw body passed in via --input <file>
This is to support file uploads or to pass in JSON bodies constructed
elsewhere.
2020-06-10 15:53:06 +02:00
Mislav Marohnić
4165793fae Extract printing response headers, include status line 2020-06-08 15:39:35 +02:00
Mislav Marohnić
fd1e87beeb Print response header keys in color too 2020-06-08 15:18:06 +02:00
Mislav Marohnić
5d5bd04102 💅 Extract parsing error response into its own function 2020-06-08 15:12:13 +02:00
Mislav Marohnić
d57b5171cf Print HTTP errors on stderr in api command
Most API errors are present in the response body itself, which will be
sent to stdout normally, but if stdout is redirected somewhere (as it's
common with scripts), failed HTTP requests will likely sabotage the rest
of the script, but no useful info will be shown on stderr.

This makes it so all REST and GraphQL errors are always shown on stderr.
Additionally, this makes sure that the command exits with a nonzero
status on any GraphQL errors.
2020-06-05 18:24:24 +02:00
Mislav Marohnić
62549465a0 Display JSON in indented, colored format in api output 2020-06-05 17:43:07 +02:00