Commit graph

51 commits

Author SHA1 Message Date
Mislav Marohnić
11fbb60ae7 Rename the module to "github.com/cli/cli/v2" 2021-08-25 12:41:30 +02:00
Mislav Marohnić
02a2ed2f73 Add repo view --json export functionality 2021-05-12 17:05:15 +02:00
Mislav Marohnić
7a8db80420 Prompt for push target during pr create
We no longer guess the head repository using heuristics; instead, we
present the user with the choice of pushable repositories and an
additional option to create a new fork.

The new `pr create --head` flag is available for the user to specify the
head branch in `branch` or `owner:branch` format and completely skip any
forking or auto-pushing checks.
2020-09-16 14:49:36 +02:00
Mislav Marohnić
d534a94d1b Change how base repository is resolved
On first run in a git repository, `BaseRepo()` will now prompt the user
which repository should be queried as base repository if there are
multiple git remotes or when we are in the context of a fork.

In non-interactive mode, the prompt is skipped and we default to the
first git remote instead.

After the base repo is resolved, the result is cached in the local
repository using `git config` so that RepositoryNetwork API lookups can
be avoided in the future.
2020-09-15 21:27:12 +02:00
Mislav Marohnić
969321bff2 🔥 cleanup in context 2020-09-15 19:09:16 +02:00
Mislav Marohnić
b7550fbf15 Correctly surface errors when parsing pr create --repo override
This avoids a crash when passing invalid input for the
`pr create --repo` flag.
2020-08-27 14:26:27 +02:00
Mislav Marohnić
c095a4bead Allow explicitly specifying the hostname for gh operations
Accept the "HOST/OWNER/REPO" syntax or passing a full URL for both the
`--repo` flag and the GH_REPO environment variable and allow setting
GH_HOST environment variable to override just the hostname for
operations that assume "github.com" by default.

Examples:

    $ gh repo clone example.org/owner/repo
    $ GH_HOST=example.org gh repo clone repo

    $ GH_HOST=example.org gh api user
    $ GH_HOST=example.org gh gist create myfile.txt

    $ gh issue list -R example.org/owner/repo
    $ gh issue list -R https://example.org/owner/repo.git
    $ GH_REPO=example.org/owner/repo gh issue list
2020-08-12 16:16:34 +02:00
Mislav Marohnić
dbbf76df10 Cleanup in context 2020-08-07 14:51:48 +02:00
Mislav Marohnić
47cef736f4 Fix GH_REPO override 2020-08-07 14:47:58 +02:00
Mislav Marohnić
aef1a4ba4d Extract root command and factory logic into separate packages 2020-08-07 14:40:33 +02:00
Mislav Marohnić
288d01318b Respect the hostname of current repository in queries 2020-07-23 22:31:08 +02:00
Mislav Marohnić
f93261a6f9 Revert to ignoring non-github.com git remotes
This fixes a regression where extra git remotes pointing to
non-github.com hostnames could result in gh trying to parse repository
information from them.
2020-07-16 18:54:35 +02:00
Mislav Marohnić
446a4111f7 Respect hostnames when resolving git remotes and URL args to repos 2020-07-02 20:36:10 +02:00
Mislav Marohnić
77227a6c50 Trigger OAuth flow only when requesting auth token
Previously we would trigger OAuth flow when the config file did not
exist. Now we will let an empty Config object be initialized in that
case, but trigger OAuth flow when the Context caller requests an
AuthToken.
2020-06-02 13:24:39 +02:00
Mislav Marohnić
767521c055 Stop providing AuthLogin from context
The login name of the authenticated user will be readily available only
if authentication info comes from the config file. With other upcoming
authentication modes (for example, the GITHUB_TOKEN environment
variable), the token is the only piece of information we got, so we
would need to additionally query for the login name.

Since `issue status` and `pr status` are the only commands that need the
name of the authenticated user right now, have those commands explicitly
query for the login name. This results in an additional API query, but
simplifies Context implementation and future authentication approaches.
2020-05-20 17:09:13 +02:00
Kevin Bluer
d440a95aed
Improved error message when "owner/repo" format not provided (#919)
Fixes #882
2020-05-18 11:13:48 +02:00
vilmibm
db9f4c36aa oops 2020-04-20 16:51:23 -05:00
vilmibm
c4693077aa move config stuff to its own package 2020-04-20 13:57:16 -05:00
vilmibm
815f461e8b more strict erroring around missing user/token 2020-04-20 12:49:46 -05:00
vilmibm
a325db3051 new config infrastructure
- adds config get and config set commands
- supports arbitrary k/v strings set at top and host level
- supports writing an updated config, preserving comments
- supports mostly lazy evaluation of yaml
2020-04-17 15:17:44 -05:00
vilmibm
44acdd4ec3 Merge branch 'master' into pr-status-no-commits 2020-03-30 12:04:02 -05:00
vilmibm
121173c330 better error reporting + catch for empty repo 2020-03-23 15:21:58 -05:00
Mislav Marohnić
d75faab85a Creating a PR now always prioritizes an existing fork as a push target
Before: the default push target for the current branch in `pr create`
was the first repository found among git remotes that has write access.

Now: the default push target is the fork the base repo, if said fork
exists and has write access, falling back to old behavior otherwise.

This change in the default is to facilitate contributions to projects
that have a hard requirement that all pull requests (even those opened
by people with write access to that project) come from forks.
2020-03-19 16:04:23 +01:00
Mike Rogers
caf12adef1 unusally > unusually 2020-03-07 20:44:14 +00:00
Dasio
8aa46c236e Init slice with provided capacity if it's known in advance 2020-02-24 22:16:41 +01:00
Mislav Marohnić
4727fc4659 Ensure descriptive error when no github.com remotes found 2020-02-20 22:30:25 +01:00
Yash Ladha
4ee995dafd
fix(486): Getting issue list on no remotes specified
Fixes: #486
2020-02-21 02:14:20 +05:30
vilmibm
c8a4ac66d8 start on fixing tests 2020-02-11 21:56:20 -06:00
vilmibm
f653dbb6b5 wrap and reuse the resolveToRemotes code from PR commands 2020-02-11 19:33:04 -06:00
vilmibm
22be13d8d5 move resolveRemotesToRepos to context 2020-02-11 19:33:04 -06:00
Borna Butkovic
f0d8c65194 pr view, status, list parent repo instead of fork 2020-02-11 19:33:04 -06:00
Mislav Marohnić
a710893fc1 Rename to cli/cli 2020-01-24 16:08:52 +01:00
Mislav Marohnić
1f90579d2a Extract common interface for a GitHub Repository
Also define a handful of utility methods:
- `New(owner, repo)`
- `FullName`: the name slash owner pair
- `FromFullName`: parse the name slash owner pair
- `FromURL`: parse a GitHub.com URL
- `IsSame(r1, r2)`: compare two repositories
2020-01-22 22:44:46 +01:00
Mislav Marohnić
f0801b2deb Simplify reading current branch from git 2019-12-17 14:45:24 +01:00
Corey Johnson
9becb5f790 Have one place manage the config dir location 2019-12-13 16:16:46 -08:00
Corey Johnson
7c1390d02d Merge pull request #131 from github/move-config-to-folder
Move config to a directory
2019-12-04 15:53:34 -08:00
Mislav Marohnić
87a1490d1e Improvements to update notifier authentication
- Check for updates even if `~/.config/gh` does not exist. In this case,
  the API call is unauthenticated.

- Avoid having the update notifier ever triggering the OAuth flow.
2019-12-04 15:41:08 +01:00
Corey Johnson
4b9cca3129 Change where the config file is located 2019-12-03 16:36:35 -08:00
Mislav Marohnić
f786802e9e Customizable API client 2019-10-29 21:07:03 +01:00
Mislav Marohnić
8370602f49 WIP eliminate package-level state in commands, context 2019-10-25 21:49:08 +02:00
Mislav Marohnić
641de86427 Eliminate package-level state in git remote parsing 2019-10-25 21:48:25 +02:00
Mislav Marohnić
5aca575964 Wire up OAuth authentication flow to initialize config file
The config file is now `~/.config/gh`.
2019-10-18 19:08:11 +02:00
Mislav Marohnić
2aa77fb8ea Add Context.SetAuthToken 2019-10-18 18:47:42 +02:00
Mislav Marohnić
79e8766d8f Use eq in more tests 2019-10-17 14:44:53 +02:00
Mislav Marohnić
a8aa5feb02 Test remote parsing 2019-10-17 02:25:59 +02:00
Mislav Marohnić
8016d80884 Create overridable Context interface 2019-10-17 02:25:59 +02:00
nate smith
0600c8c68c switch to context struct 2019-10-15 13:36:38 -05:00
nate smith
cccb6832c3 Revert "towards moving config into context"
This reverts commit 7427716ea8.
2019-10-14 11:02:04 -05:00
nate smith
6ef29819c7 towards moving config into context 2019-10-11 10:53:29 -05:00
nate smith
6e6b18c50a move more stuff into context.go 2019-10-10 15:43:25 -05:00