Commit graph

111 commits

Author SHA1 Message Date
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
Mislav Marohnić
66c18b40f2
Handle SAML enforcement challenge from the server (#5054)
Whenever a SSO challenge gets issued by the server by means of a URL in
the `X-GitHub-SSO` response header, gh now additionally prints that URL
on the standard error stream.

This is achieved by installing a middleware to all HTTP requests and
storing the server challenge to a value accessible by `factory.SSOURL()`.
Such approach was made necessary mainly because of the
`shurcool-graphql` client which doesn't give access to response headers
when a GraphQL error case is encountered.
2022-01-19 14:22:22 +01: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
Stefan Huber
a1daf96314
Clarify magic type conversion of api params (#4434)
Co-authored-by: Mislav Marohnić <mislav@github.com>
2021-11-18 14:14:50 +00:00
Alan Donovan
f4491c7a80 Add FlagErrorf; encapsulate FlagError.error 2021-10-21 11:40:20 -04:00
Mislav Marohnić
01adff037f api: prevent repeating GET parameters when paginating 2021-10-18 20:18:23 +02:00
Mislav Marohnić
2ca18e0600 Warn about missing OAuth scopes when reporting HTTP 4xx errors
If a 4xx server response lists scopes in the X-Accepted-Oauth-Scopes
header that are not present in the X-Oauth-Scopes header, the final
error messaging on stderr will now include a hint for the user that they
might need to request the additional scope:

    $ gh codespace list
    error getting codespaces: HTTP 403: Must have admin rights to Repository. (https://api.github.com/user/codespaces?per_page=30)
    This API operation needs the "codespace" scope. To request it, run:  gh auth refresh -h github.com -s codespace
2021-10-13 23:24:14 +02:00
Reto Hablützel
f6e9734f17 add more hints to docs 2021-09-25 08:38:26 +02:00
rethab
f5b0d01e86 docs: add hint how to use use stdin in api command 2021-09-25 08:11:47 +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
Robin Neatherway
0e51ec1699 Correct benign mistake in off-by-one guard
m[2] is the third element of m, rather than the second, so we have to
check instead that the len of m is at least 3.

Because the regular expression has two capture groups, the length of m
will always be 3, so currently the guard will always be true.
2021-08-19 14:41:04 +01: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
Mislav Marohnić
a3a7deadb8
Merge pull request #3400 from embano1/patch-1
Add note on supported value types in raw-fields
2021-04-20 18:49:41 +02:00
Mislav Marohnić
e327b42f79 Add gh help formatting topic & link to it from commands with JSON output 2021-04-14 18:27:15 +02:00
Mislav Marohnić
61a8049592 Extract JSON filtering functionality from gh api 2021-04-13 16:48:21 +02:00
Michael Gasch
42b518191c Add note on supported value types in raw-fields
Proposing a slight amendment to the `gh api` field docs to clarify the current limitation around "complex" field values, e.g. arrays/objects.

Related: #1484
Signed-off-by: Michael Gasch <mgasch@vmware.com>
2021-04-12 15:20:43 +02:00
Sam
9ec1e21d4c
Default to GHES host if only GHES is authenticated (#3286) 2021-03-30 16:51:00 +02:00
Kid
3a8313b4f7
Fix a typo in gh api 2021-03-08 22:14:29 +08: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ć
4c26d617d3 Merge remote-tracking branch 'origin/api-template' into api-jq 2021-03-04 17:00:41 +01:00
Mislav Marohnić
eb08774370 Assert that executeTemplate is invoked 2021-03-04 16:48:06 +01:00
Mislav Marohnić
f53ad7161a Add more api --template tests 2021-03-04 16:35:08 +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ć
03baeb2645 Add documentation and tests for api --filter 2021-03-03 19:24:38 +01:00
Mislav Marohnić
9f4eb55b66 Merge remote-tracking branch 'origin/api-template' into api-jq 2021-03-03 17:35:18 +01:00