Commit graph

142 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
Heath Stewart
2758b80013
Remove unnecessary --help comment 2024-04-15 21:38:16 -07:00
Andy Feller
88a7e529ab
Merge pull request #8762 from Ebonsignori/8761/allow-multiple-items-in-nested-array
allow multiple items in nested array
2024-04-09 14:23:19 -04:00
Andy Feller
b722dd4151 Add tests for non-happy field paths
This commit as a suite of test around different combination of `gh api` field scenarios that result in errors.

In the course of creating this test, there were 2 scenarios that did not raise an error as expected involving overriding an existing map value.
2024-04-05 17:21:28 -04: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
a76af8588c
Resolve PR comments 2024-04-04 01:26:09 -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
0dfe6ec4b4
Clarify --merge-pages docs
Only works when piping or redirecting stdout.
2024-04-04 01:21:03 -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
a65103667e
Move jsonmerge package to internal 2024-04-04 01:20:57 -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
Evan Bonsignori
fce871f3f4
Apply suggestions from code review
Co-authored-by: Andy Feller <andyfeller@github.com>
2024-04-02 17:39:20 -07:00
Evan Bonsignori
3c3bed779f update example for deeply nested array update 2024-03-15 18:43:00 -07:00
Evan Bonsignori
234e0b3c8a allow multiple items in nested array 2024-02-26 17:43:51 -08:00
Yukai Chou
ba585149c3 Leftovers 2023-11-23 07:12:47 +08:00
Yukai Chou
e81b9b2517 Wrap HTTP methods 2023-11-23 07:10:08 +08:00
Yukai Chou
07a87ca8a4 Wrap special values and placeholders like - and $1 2023-11-23 07:09:29 +08:00
Yukai Chou
21bf1babdf Proof-reading 2023-11-17 02:04:35 +08: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
ffalor
e4e7bf5c8c
force method to uppercase (#7514)
Co-authored-by: Mislav Marohnić <mislav@github.com>
2023-06-01 13:54:56 +00:00
Mislav Marohnić
7a814b31c2
api: support array params in GET queries (#7513) 2023-05-31 20:23:31 +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
Sam Coe
c9a2d85793
Cleanup config.AuthToken and config.DefaultHost methods (#7049) 2023-02-28 00:24:45 +00: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
Heath Stewart
cd63b0eac5 Add more help to "template" flags
Resolves #6089
2022-09-17 23:12:48 -07:00
Mislav Marohnić
436d9ef859
Fix "missing method Fd" crash on Windows (#6200)
This ensures that `IOStreams.Out` always keeps the original `Fd()` value even if it's wrapped as a Colorable stream for Windows in cases when enabling virtual terminal processing has failed.
2022-09-06 17:29:06 +02: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
cacff4ad6d
Use go-gh config package (#5771) 2022-06-23 11:50:04 +00:00
Sam Coe
074ed50b8a
Integrate go-gh API package (#5614) 2022-06-23 04:05:31 +01:00
Josh Soref
7d99a98f02 Clarify that ShowResponseHeaders includes status line 2022-05-23 10:18:50 -04:00
Håvard Anda Estensen
58cb773e09
Replace ioutil with io and os (#5498) 2022-04-26 13:07:44 +02:00
Mislav Marohnić
5f8bdd64da gh api: clarify how to pass API preview names 2022-02-18 18:39:30 +01:00
Mislav Marohnić
0a5e220231 Ignore EPIPE errors when writing to a closed pager
While a gh command is writing stdout to a pager, the user may choose to
close the pager program before the pager has read all the data on its
standard input. In that case, the parent gh process will receive an
EPIPE error, which would bubble up its error handling and cause it to
print something like:

    write |1: broken pipe

Since this was caused by an explicit user action of closing the pager,
and since the user probably doesn't want to see this uninformative
error, this informs our global error handling of this error and causes
it to be ignored.
2022-02-10 16:42:00 +01:00
Mislav Marohnić
4a3ef50d2d
Standardize pager output across commands (#5141)
Add pager functionality to the following commands:
- gist list
- pr checks
- release list
- run list
- run view
- secret list
- workflow list
- workflow view

Additionally, normalize error handling when starting the pager has
failed: only print a non-fatal notice to stderr instead of aborting the
whole command.
2022-02-01 08:36:51 +01: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ć
fac020eb39
Merge pull request #5063 from issyl0/repo-envvar-compatible-with-gh-api
cmd/api: Respect `GH_REPO` when substituting `{owner}/{repo}`
2022-01-20 18:16:10 +01:00
Issy Long
8c2695b4a0
cmd/api: Respect GH_REPO when substituting {owner}/{repo}
- This fixes issue 5061.
- Previously, a user could set `GH_REPO=TestOrg/repo` and run `gh api
  repos/{owner}/{repo}/releases` expecting to see the releases from
  `TestOrg/repo` but instead see releases from the current git repo
  they're in.
- Or, worse, if the user ran the command from outside of a git repo,
  they'd see a "not a git repo" error from git itself.
- This was different to `GH_REPO=TestOrg/repo gh release list` which
  successfully lists `TestOrg/repo`'s releases.

----

Before:

```shell
$ cd repos/issyl0/not-a-git-repo
$ GH_REPO=issyl0/terraform-provider-improvmx gh api repos/{owner}/{repo}/releases
unable to expand placeholder in path: fatal: not a git repository (or any of the parent directories): .git
/opt/homebrew/bin/git: exit status 128
```

```shell
$ cd repos/issyl0/a-git-repo-with-no-releases
$ GH_REPO=issyl0/terraform-provider-improvmx gh api repos/{owner}/{repo}/releases
[]
```

After:

```shell
$ cd repos/issyl0/not-a-git-repo
$ GH_REPO=issyl0/terraform-provider-improvmx ../../cli/cli/bin/gh api repos/{owner}/{repo}/releases
[lots of JSON about GH_REPO's releases - success]
```

```shell
$ cd repos/issyl0/a-git-repo-with-no-releases
$ GH_REPO=issyl0/terraform-provider-improvmx ../../cli/cli/bin/gh api repos/{owner}/{repo}/releases
[lots of JSON about GH_REPO's releases - success]
```
2022-01-19 23:16:13 +00:00