Commit graph

70 commits

Author SHA1 Message Date
Des Preston
8f9548fd37
Ignore scope suggestions for http 422 (#4809)
HTTP 422 messages are for validation errors, but OAUTH permissions
suggestions get printed anyways. Most times, the user probably has the
right permissions. This fix adds the check to avoid printing a confusing
message.

Co-authored-by: Mislav Marohnić <mislav@github.com>
2021-12-01 18:13:48 +00:00
Mislav Marohnić
34fc5fb75c Improve issue view re: overfetching, PR support
- Supports passing a PR as argument, not just issues
- Makes it non-fatal when project cards were not able to load
- Cleans up legacy method for fetching issues
2021-11-24 18:49:36 +01:00
Mislav Marohnić
07cad386a5 Improve issue close re: overfetching, handling PRs
- `issue close` no longer fetches all issue fields and thus avoids the
  problem when loading failed due to token not having access to projects

- `issue close` now accepts either issue or pull number as argument.
2021-11-23 19:38:55 +01:00
Sam Coe
260716a9f8
Repace shurcool/graphql with cli/shurcool-graphql 2021-11-17 12:57:43 -08: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
Mislav Marohnić
11fbb60ae7 Rename the module to "github.com/cli/cli/v2" 2021-08-25 12:41:30 +02:00
Mislav Marohnić
3e23dcab15 Fix HTTP 502 error reporting from GraphQL request
Now it makes sure that the message portion will be printed to stderr
when the user encounters the error.
2021-08-18 22:17:32 +02:00
Mislav Marohnić
90b7886142 Fix unmarshalling GraphQL error type
The "path" field of a GraphQL error object contains a mix of strings and
numbers and cannot be deserialized into `[]string`. Fortunately, we
don't need to rely on the "path" field and instead have the final error
message be constructed by aggregating human-readable "message" fields.
2021-08-04 15:34:53 +02:00
Gowtham Munukutla
c4beed8276 complete tests 2021-05-30 13:42:39 +05:30
Mislav Marohnić
ac348b0dec Fix requesting REST sub-resources on GHE
GitHub REST resources typically return full URLs to fetch related
resources at. We used to parse those URLs to find just the path portion
and pass that in to the `REST()` function, which only accepted paths. By
doing so, we are essential de-constructing a URL just to re-assemble it
again. While re-assembling it for Enterprise, though, we would
accidentally inject an extra `api/v3/` prefix where one was not needed.

The solution is just to use raw URLs as reported by the REST API with
no modifications. This extends the `REST()` function to accept full URLs
in addition to just paths to resources.
2021-04-19 12:41:09 +02:00
Mislav Marohnić
3b117e6c3c
Merge pull request #2539 from divyaramanathan/issue-create-template
Implementing issue template GraphQL API call
2021-02-17 17:59:42 +01:00
Mislav Marohnić
83bb1bfd9d Port pr create to new templates implementation 2021-02-10 18:20:57 +01:00
Mislav Marohnić
5a110c8e42 Add SSH key generation & uploading to gh auth login flow 2021-02-01 23:34:00 +01:00
Mislav Marohnić
53cea2667e Support "integration" tokens
Integration tokens are different than OAuth token in it that they don't report any `X-Oauth-Scopes` in response headers.
2020-10-16 17:11:14 +00:00
Mislav Marohnić
626be2a095 Fix formatting in MissingScopesError 2020-10-16 17:11:10 +00:00
Mislav Marohnić
38f0f607e9 🔥 outdated CheckScopes 2020-10-16 17:10:23 +00:00
Mislav Marohnić
6933c381bf Restore Go 1.13 compatibility 2020-09-01 19:12:02 +02:00
Mislav Marohnić
cf46ae2db7 Log larger response bodies with DEBUG=api 2020-08-21 18:00:52 +02:00
Mislav Marohnić
33fd6b1149 Change API authentication to allow asset downloads
We install an HTTP middleware that adds the "Authorization" header on
every HTTP request. However, our asset download process might redirect
to a 3rd-party host (Amazon S3) and we want to allow those requests but
not require that they are authenticated.

Furthermore, we need the ability to specify the `Accept` request header
without it being overwritten by middleware, so now middleware only adds
headers that are not present in a request.
2020-08-21 18:00:52 +02:00
Mislav Marohnić
a00d927970 Add release download, upload files on create, upload retrying 2020-08-21 18:00:52 +02:00
Mislav Marohnić
c4f5d6db58 Preliminary gh release commands 2020-08-19 18:25:02 +02:00
vilmibm
6c64cb8d23 remove vestigial return from HasMinimumScopes 2020-08-11 16:33:13 -05:00
vilmibm
ec25b735ab gh auth status 2020-08-11 15:58:00 -05:00
vilmibm
35f18b6c02 gh auth login 2020-08-06 12:43:35 -05:00
Mislav Marohnić
c0b116b511 Merge remote-tracking branch 'origin' into ghe-api 2020-07-28 18:12:47 +02:00
Kumar Saurabh
78124a9716
API improvement : Drain response Body inside func HasScopes (#1428)
Ensure the response body is fully read and closed to reuse the same TCPconnection.

Co-authored-by: Kumar Saurabh <kumarsaurabh@Kumars-MacBook-Air.local>
2020-07-28 14:56:17 +02:00
Mislav Marohnić
288d01318b Respect the hostname of current repository in queries 2020-07-23 22:31:08 +02:00
Mislav Marohnić
e373195817 WIP migrate gist create to separate package 2020-07-21 18:13:16 +02:00
Mislav Marohnić
2086ecb3d1 Fix printing network error in case for failed HTTP requests
The CheckScopes middleware tried to read from `res.Headers` before it
verified that `res` is available.
2020-07-17 18:24:13 +02:00
Mislav Marohnić
28cd348176 Only check OAuth scopes when X-Oauth-Scopes header is present 2020-07-13 15:53:53 +02:00
Mislav Marohnić
55d31303ea Have admin:org scope satisfy read:org requirement
`admin:org` is inclusive of `read:org`, so if we find the former listed
in response headers, we can conclude that the token has necessary scopes
instead of letting a warning notice be shown.
2020-07-13 15:35:14 +02:00
Mislav Marohnić
f4c4ce0b0a Add names to GraphQL queries made over shurcooL adapter 2020-07-07 17:53:40 +02:00
Mislav Marohnić
1ca3d171e6 Tweak HTTP 422 handling when deleting branches 2020-06-30 19:21:39 +02:00
Pavel Borzenkov
c66eebc6fb api: return structured error for failed API calls
`fmt.Errorf` hides information and makes it hard to test for specific
conditions in returned error. Return a structured error instead.

Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
2020-06-27 18:47:34 +03: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ć
1595d3b950 Handle HTTP errors in HasScopes 2020-06-02 13:24:46 +02:00
Mislav Marohnić
2e93a065b1 Merge remote-tracking branch 'origin/master' into api-command 2020-05-27 12:56:06 +02:00
Mislav Marohnić
90fa193eaf Promote api command to a pkg/cmd/api package 2020-05-20 15:21:31 +02:00
Mislav Marohnić
fa3e25bb4d Serialize GraphQL parameters under variables 2020-05-20 15:21:31 +02:00
Mislav Marohnić
1609afe993 Add api command 2020-05-20 15:21:31 +02:00
vilmibm
96ba1eacef undo initial thing 2020-05-15 16:44:51 -05:00
vilmibm
7decae71fc untested first pass on ensureScopes 2020-05-15 16:40:13 -05:00
vilmibm
cc1ffb0aea pass apiClient to determineBaseRepo
Our code had an unspoken assumption that only one apiClient is created
during the course of a command. Violating this assumption is fine in
almost all cases, but not when we need to do a re-auth to add a new
oauth scope to a user's token.

There is likely a more elegant solution to the problem but until then
this changes determineBaseRepo to use an existing apiClient.
2020-05-13 14:55:49 -05:00
vilmibm
3a7f56456e tweak reauth code and request a new scope 2020-05-13 14:24:29 -05:00
Mislav Marohnić
3aaa231cc5 Guide user through re-authorization flow if read:org scope is missing
How this works for people with existing OAuth tokens:

    $ gh issue list -L1
    Notice: additional authorization required
    Press Enter to open github.com in your browser...
    [auth flow in the browser...]
    Authentication complete. Press Enter to continue...

    Showing 1 of 132 issues in cli/cli
    ...

Users of Personal Access Tokens get a different notice:

    Warning: gh now requires the `read:org` OAuth scope.
    Visit https://github.com/settings/tokens and edit your token to enable `read:org`
    or generate a new token and paste it via `gh config set -h github.com oauth_token MYTOKEN`
2020-04-23 18:20:21 +02:00
Mislav Marohnić
3d566dc5a6 Detect and warn about read:org OAuth scope being missing 2020-04-15 17:25:15 +02:00
gertd
203525c031 pr bug/rest-204 review feedback 2020-04-10 16:48:11 -07:00
gertd
b9f1b5dac1 fix api.REST(DELETE, ...) json.Unmarshal failure 2020-04-09 22:19:28 -07:00
Mislav Marohnić
9c00ac0224 Tweak verbose HTTP logging
- log headers only in DEBUG=api mode
- enable color output on stderr
- hide little-useful TLS debbuging info
- ensure all request headers are logged
2020-02-21 12:57:00 +01:00
Henrique Vicente
e7c88d0fb1
impr(verbose): using package httpretty to log requests on DEBUG. 2020-02-21 02:46:18 +01:00