This addresses #2226 and #2116 by creating a `gist` subcommand.
This allows you to both create and retrieve gists. When creating a gist
it can be public or private.
In order to do this, the `gist` scope is added to the token we request.
Closes: #2226Closes: #2116
Signed-off-by: Phil Dibowitz <phil@ipom.com>
This allows hub to be easier used within GitHub Actions where GITHUB_REPOSITORY is pre-populated by default. If GITHUB_USER is not set in the environment, its value is inferred from the part of GITHUB_REPOSITORY value until the first slash character.
When supplied with GITHUB_TOKEN, hub will attempt to request the `user`
API resource which isn't available in the context of Actions.
To work around this, scripts may now set GITHUB_USER to avoid hitting
the unavailable API resource.
Hub is impossible to use from within GitHub Actions because specifying
GITHUB_TOKEN will trigger the code path where the `user` resource is
requested from the GitHub API to get the current login name, but this
resource is not available for that token.
This failure message was cryptic and misleading before as it was
sometimes presented as HTTP 401. This change ensures that the correct
HTTP 403 "Resource not accessible by integration" message is shown.
If you're trying to create `owner/foo` repo and there is an existing
redirect from `owner/foo` to a differently name repo, don't consider
that one as an existing repo and proceed with creating `owner/foo`.
Also, adopt the new name of the fork more precisely so it's reflected in
the new remote URL. The name of the new git remote is for now *not*
inherited from the returned Repository object for backwards compatibility.
Fixes#1178
When looking up an existing hub token among user's authorizations, be
sure to fetch all results by following pagination links. Previously we
just stopped at the 1st page, and if the token for hub didn't appear
there we would try to create it, which would result in a 422 validation
error if it already existed.
References 1e4477b566Fixes#531, fixes#558, fixes#563
For people who are using hub for a longer time now, hub has stored an OAuth
token in Authorizations API with a `note_url` value that is now outdated
(e.g. "http://defunkt.io/hub/"). The newer `oauth_app_url` doesn't match
that, so the token is not reused. Hub tries to create a new OAuth token
with a `note` that says "hub" which fails with a 422 because it already
exists.
This fixes reusing old OAuth tokens even if the `note_url` doesn't match
anymore. Any key with `note` that says "hub" will get reused.
Fixes#496
Technically, they're going to be the same values for OAuth tokens
created via the API, but since we write to `note_url` field it makes
sense to use the same field to read the value back, for consistency.
hub initially tries to fetch user's existing OAuth token for hub if it
exists, and will prompt the user for a 2FA code. However those who
receive it via SMS would never get the code since a GET to GitHub's
Authorizations API purposely doesn't trigger an SMS. There's some
discussion as to whether this is an API bug for not, but in the
meantime, make a dummy POST request for the sole reason of triggering
the SMS.
Fixes#412, closes#435, closes#445
API authentication and persisting of credentials in Config was
convoluted and inflexible, and it wasn't possible to log in with
different credentials than your GitHub screen name. Since Enterprise
supports different authentication schemes, it's important to allow
emails for login as well (or any string for that matter) and retrieve
the user's screen name after successful authentication.
This also improves handling special characters in Basic Auth usernames
and passwords.
Fixes#407
This ensures we end up with the correct capitalization of user's login
name, and gives the opportunity to the server to change the project name
without having us choke on it.
Fixes#263
I tried to hack Sinatra to automatically serialize non-string response
bodies as JSON, but this is not straightforward due to sinatra/sinatra#512
and doesn't really work in a whole lot of edge-cases.
Introduced a simple `json` helper and now using that instead of `body`.