Commit graph

64 commits

Author SHA1 Message Date
Mislav Marohnić
f0e6c98bf0 Fix auto-forking scenario in pr create
When an existing `headRepo` couldn't be detected, it's time to auto-fork
one. Unfortunately, an obscure Go behavior made it seem like `headRepo`
was a non-nil value, where in fact it did contain a nil pointer which
would crash the process.

This avoids ever assigning nil pointers to `var headRepo ghrepo.Interface`.
2020-04-01 19:37:56 +02:00
Mislav Marohnić
24a332bb1b Use remote tracking branch for base when detecting commits for pr create
This is to avoid errors when a local base branch is missing or out of
date.
2020-03-31 13:32:44 +02:00
Mislav Marohnić
da2116f8ee Merge remote-tracking branch 'origin/master' into pr-create-push-default 2020-03-30 13:32:37 +02:00
Mislav Marohnić
cba8331d55 Avoid auto-forking/pushing an already pushed branch in pr create
A branch is considered already pushed if its HEAD commit hash matches
the commit hash of one of the remote tracking branches:
`refs/remotes/<remote>/<branch>`

This mechanism allows the user to:

- Choose a remote as push target for their branch different than the one
  that would automatically get chosen for them by `pr create`;

- Avoid a `git push` operation (and its associated git hooks) if a push
  was not necessary in the first place.
2020-03-26 20:35:42 +01:00
Mislav Marohnić
5b2e1847b7 Merge remote-tracking branch 'origin/master' into pr-create-push-default 2020-03-25 08:16:04 +01:00
vilmibm
2895252e3b respect -B when checking for existing pull requests 2020-03-23 14:26:31 -05:00
Mislav Marohnić
e3653672a8 Simplify git.AddRemote implementation
The 2nd argument now unused since we've determined that, in practice, we
can safely fetch git objects from a freshly created fork on GitHub and
that we don't need the remote URL-swapping workaround.
2020-03-20 13:08:33 +01: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
Mislav Marohnić
5b76881624 Improve detecting existing PR on pr create
- Only check for existing PRs if `--web` wasn't given
- Fix detecting PRs from forks
- Improve order of error handling: local validation errors are handled
  earlier than the ones that have to consult the API
2020-03-18 13:09:02 +01:00
Mislav Marohnić
23dfeff84f Merge remote-tracking branch 'origin/master' into check-if-pr-exists 2020-03-18 12:04:08 +01:00
vilmibm
0344e9543a humanize branch name for title 2020-03-17 16:18:32 -05:00
vilmibm
98a2281f45 more nuanced error handling 2020-03-17 16:09:40 -05:00
vilmibm
af46fcb1ff --fill for pr create 2020-03-16 15:32:47 -05:00
vilmibm
2d90c09f48 review feedback 2020-03-16 15:32:35 -05:00
Tarasovych
d0c32e7a3d changed error message and pr check 2020-03-16 16:01:03 +02:00
vilmibm
8769299731 titlebody prepopulation 2020-03-13 15:12:03 -05:00
Tarasovych
f3c9406e76 fixed repo argument 2020-03-13 16:01:37 +02:00
Tarasovych
b544583b26 added check if pr already exists 2020-03-13 14:02:29 +02:00
Mislav Marohnić
d584a9692c Raise error if --draft was used in pr create --web
Since we cannot pass the "draft" option as query parameter, this raises
an error instead of proceeding to open the browser and potentially
confuse the user as to why `--draft` wasn't respected.
2020-03-09 14:53:27 +01:00
Mislav Marohnić
7777307588 Avoid forking/pushing until pr create inputs have been processed
This avoids fork or push operation if there were errors processing the
input arguments or if the operation has been cancelled during
interactive survey.
2020-03-09 14:51:40 +01:00
Mislav Marohnić
c10f2ff945 Communicate to the user that we're waiting before retrying git push
When the user has just created a fork, it might not yet be ready for
writing. This ensures that the wait period between retries is
communicated to the user on stderr.
2020-02-24 19:36:54 +01:00
Mislav Marohnić
1a82e39ba9 Respect title & body from arguments to pr create -w 2020-02-20 22:48:04 +01:00
Mislav Marohnić
96ba2d27d8 Respect overriden base branch in pr create --web 2020-02-17 14:14:37 +01:00
vilmibm
212dc1da1d properly specify head ref for cross-repo/same-branch 2020-02-12 16:11:04 -06:00
vilmibm
22be13d8d5 move resolveRemotesToRepos to context 2020-02-11 19:33:04 -06:00
vilmibm
9025838448 update error text 2020-01-28 10:20:59 -06:00
vilmibm
bfd1d804a8 prevent graphql error 2020-01-27 16:00:11 -06:00
Mislav Marohnić
a710893fc1 Rename to cli/cli 2020-01-24 16:08:52 +01:00
Mislav Marohnić
b44dad2319 Merge remote-tracking branch 'origin/master' into no-errors-wrap 2020-01-23 16:46:56 +01:00
Nate Smith
a0f2e1736a Merge pull request #244 from github/ghrepo-interface
Extract common interface for a GitHub Repository
2020-01-23 09:39:16 -06:00
Nate Smith
bf0f345ea3 Merge pull request #243 from github/display-url
Extract helper for URL display
2020-01-23 09:36:40 -06:00
Mislav Marohnić
9122bc181c Migrate away from errors.Wrap()
Turns out the "standard" way of wrapping errors in Go is via
`fmt.Errorf("%w")`, which doesn't require an external package and also allows a
finer control of error sentence formatting.
2020-01-23 13:19:28 +01:00
Mislav Marohnić
90f6a73ba5 Extract helper to print a URL 2020-01-22 23:03:23 +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ć
a767fd7910 Add code comments for tricky parts 2020-01-22 18:37:50 +01:00
Mislav Marohnić
e2a825effb Auto-fork on pr create if no pushable target found 2020-01-22 18:32:06 +01:00
Mislav Marohnić
fa30c16ad5 Fix web-based pr create for forks 2020-01-21 23:20:32 +01:00
Mislav Marohnić
6c49614db7 Fix tests 2020-01-21 22:56:15 +01:00
Mislav Marohnić
7a614ce697 Support triangular git workflows in pr create
- The local git remotes are scanned and resolved to GitHub repositories
- The "base" repo is the first result resolved to its parent repo (if a fork)
- The name of the default branch is read from the base repo
- The "head" repo is the first repo that has push access
2020-01-21 18:26:08 +01:00
vilmibm
31001877bd hide potentially long query strings when printing urls 2020-01-16 14:18:40 -06:00
vilmibm
1e19b9953a use pluralize helper 2020-01-15 12:39:35 -06:00
vilmibm
32461284cc fix some TODOs 2020-01-15 12:35:28 -06:00
vilmibm
7bbd70d6b2 use default to preserve non-interactive behavior 2020-01-15 11:27:25 -06:00
vilmibm
d8cbb6a6a7 support previewing PRs in the browser 2020-01-14 17:03:53 -06:00
vilmibm
e821d2781a towards extending survey.Editor behavior 2020-01-14 15:20:11 -06:00
Corey Johnson
2e0ea153d5 Merge remote-tracking branch 'origin/master' into appropriate-context-and-feedback 2020-01-06 09:52:26 -08:00
Corey Johnson
b98bd2cfb8 Use base branch 2019-12-20 10:58:25 -08:00
Mislav Marohnić
d5ba3de751 Add template support to issue create, pr create
If multiple templates are found, the user is prompted to select one.

The templates are searched for, in order of preference:

- issues:
  1. `.github/ISSUE_TEMPLATE/*.md`
  2. `.github/ISSUE_TEMPLATE.md`
  3. `ISSUE_TEMPLATE/*.md`
  4. `ISSUE_TEMPLATE.md`
  5. `docs/ISSUE_TEMPLATE/*.md`
  6. `docs/ISSUE_TEMPLATE.md`

- pull requests:
  1. `.github/PULL_REQUEST_TEMPLATE/*.md`
  2. `.github/PULL_REQUEST_TEMPLATE.md`
  3. `PULL_REQUEST_TEMPLATE/*.md`
  4. `PULL_REQUEST_TEMPLATE.md`
  5. `docs/PULL_REQUEST_TEMPLATE/*.md`
  6. `docs/PULL_REQUEST_TEMPLATE.md`

The filename matches are case-insensitive.
2019-12-18 22:15:20 +01:00
Mislav Marohnić
7b7c985e79 Merge remote-tracking branch 'origin/master' into appropriate-context-and-feedback 2019-12-17 13:00:10 +01:00
Corey Johnson
6d0f4e7a90 Add more text 2019-12-16 11:41:56 -08:00