Commit graph

93 commits

Author SHA1 Message Date
yuvrajangadsingh
fdd6388086 refactor: deduplicate scope error handling between api/client.go and project queries
Consolidate duplicated INSUFFICIENT_SCOPES error handling into a single
implementation. The project queries package now calls
api.GenerateScopeErrorForGQL instead of reimplementing the same logic.

Removes duplicated requiredScopesFromServerMessage, scopesRE, and the
associated test (already covered by api/client_test.go).

Fixes #12823
2026-03-05 20:57:32 +05:30
Kynan Ware
e725e38370
Merge pull request #12596 from elijahthis/fix/clarify-scope-error
fix: clarify scope error while creating issues for projects
2026-03-02 11:12:35 -07:00
William Martin
166db75d36 pin REST API version to 2022-11-28
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-13 19:46:16 +01:00
elijahthis
6f739036b8 fix: clarify scope error while creating issues for projects 2026-02-01 23:12:01 +01:00
Babak K. Shandiz
d129b94fc5
refactor: remove returned resp from api.EndpointNeedsScopes
The returned response from `api.EndpointNeedsScopes` causes `bodyclose`
linter to raise a false positive error, assuming it's a new response that
its body needs to be closed.

Signed-off-by: Babak K. Shandiz <babakks@github.com>
2025-11-03 20:05:24 +00:00
Tyler McGoffin
81591a09b8 Use go-gh/auth package for IsEnterprise, IsTenancy, and NormalizeHostname 2024-10-15 11:56:43 -07: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
Mislav Marohnić
36ffbe18de
Improve looking up draft releases by tag name
This changes the FetchRelease implementation to look up draft releases directly using by its pending tag name, as opposed to resorting to the Releases list API which is backed by Elastic Search and thus suffers replication lag after the creation of a draft release.

Bonus: all release lookup functions now accept a context for cancellation.
2022-12-14 21:24:08 +01:00
Mislav Marohnić
e58bf212fe
Fix API client code docs 2022-12-14 21:22:05 +01:00
Chris Westra
4daac49917
Remove released feature flag
`branch_for_issue_api` is no longer in the dotcom codebase so we can remove it from here
2022-10-05 07:45:15 -04:00
Chris Westra
7c7896859c Add flag to features list 2022-09-08 10:02:00 -04:00
Sam Coe
117929c57e
Always send GraphQL-Features: merge_queue with graphql requests 2022-08-18 21:50:00 +03:00
Mislav Marohnić
d21d388b8d
Restore old GH_DEBUG=1 behavior for HTTP logging (#6054)
- No HTTP bodies or headers are logged until `GH_DEBUG=api` is used.
- Logging to terminal now supports colorization.
2022-08-10 17:59:13 +02:00
Sam Coe
2cdb9d34d4
Use SkipDefaultHeaders option (#5996) 2022-07-26 07:15:50 +02:00
Sam Coe
9d70d62520
Set blank headers so they are not automatically resolved by go-gh (#5935) 2022-07-14 14:13:34 +02:00
Sam Coe
074ed50b8a
Integrate go-gh API package (#5614) 2022-06-23 04:05:31 +01:00
Ariel Deitcher
53a8737c87 pr merge: add support for Merge Queue
Co-authored-by: Mislav Marohnić <mislav@github.com>
2022-06-08 12:24:36 +02:00
Håvard Anda Estensen
58cb773e09
Replace ioutil with io and os (#5498) 2022-04-26 13:07:44 +02:00
nate smith
a3fba669bd add and use RESTWithNext 2022-03-29 10:15:33 -05:00
Mario Campos
97ea5e77b4
Fix obtained scope mapping to include implied scopes (#5256)
* Fix obtained scope mapping to include missing scopes

As is, `gotScopes` does not contain certain scopes because it doesn't check for the "special" scopes that imply other scopes. For example, the `repo` scope implies `repo:invite`.

* Add a comment in ScopesSuggestion explaining branch statements

* Delete whitespace to appease go-fmt
2022-03-01 14:37:58 +00:00
nate smith
bd6e50a08a Merge remote-tracking branch 'origin/trunk' into feature/target-repo-fork-name 2022-01-25 14:08:27 -06: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
Gowtham Munukutla
3fb4c481dc modify tests 2021-12-11 10:17:04 +05:30
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