How to review a pull request in IntelliJ IDEA?
Asked Answered
H

5

114

We are using git, Bitbucket, and IntelliJ IDEA. The project is mainly written in Java and Groovy.

Is there a good way to review pull requests right from IntelliJ?

Haw answered 24/10, 2016 at 11:41 Comment(1)
You can use this plugin to review Bitbucket PRs. It's not free though. plugins.jetbrains.com/plugin/13538-code-review-for-bitbucketMonandrous
G
51

The formal support for GitHub (or BitBucket for that matter) pull request review is still pending (issue IDEA-85079, opened in 2012). It will be implemented in the 2020.2 release (see here).

Since 2016, it has support for GitHub PR in 2018.3, as commented here:

This is mostly read-only mode for now - one could create a local branch from a PR or open it on GitHub to comment/close it - but this is only the first step.

In future releases we plan to add additional functionality - ability to assign PRs IDEA-146659, merge/close them directly from IDE, comment on the PR and specific lines of code - IDEA-64794.

But: (Sept. 2019)

It's not at all obvious how to open the PR page. I had to look up the release notes to discover it's a double click. Discoverability of the PR tab is also poor; it isn't visible by default and there's no way to reach it from the version control tab, which is where I looked first.

Jan. 2020: Dan Oak mentions in the comments that:

CodeStream provides a tool to integrate GitHub PRs into IDEA.
See Pull Request Integrations:

CodeStream can display merged pull request comments in your editor as annotations on the current version of your


2016:

That leaves you with a manual process, fetching a PR, and comparing the branches:

git fetch origin pull/1234/head:pr-1234

For BitBucket:

git fetch origin refs/pull-requests/1234/from:pr-1234

(See also "How to fetch Pull Requests in BitBucket")

Then you can compare branches in IntelliJ.

Gusto answered 24/10, 2016 at 12:1 Comment(14)
I was looking for a bitbucket solution, but I guess this will come even after the github one.Haw
@gba Actually, the problem (and current solution) is the same for bitBucket pull requestsGusto
@gba I have edited the answer to include the refspec valid for BitBucket (instead of just GitHub)Gusto
I don't get then you compare branches in intellij. After fetching pull request, what to do. Pull request is not shown as branch.Prase
@ShashwatKumar the refspec refs/pull-requests/1234/from:pr-1234 should create the local branch pr-1234. If not, please open a new questio describing your issue and current setup.Gusto
Yup got it. Probably branch name pull/1234/from us wrongPrase
@Gusto - How do you leave PR comments in this process?Racklin
@Racklin I don't know if PR comments are supported on the client side (here, the IDE IntelliJ IDEA): this is more a server-side feature (on GitHub or BitBucket directly)Gusto
For BitBucket: that's nice. but how about gitlab?Phenylamine
@workplaylifecycle There exists a manual process with merge requests for GitLab (which are the equivalent of pull requests for GitHub or BitBucket). See docs.gitlab.com/ee/user/project/merge_requests/…Gusto
codestream.com provides a tool to integrate GitHub PRs into IDEA. See github.com/TeamCodeStream/CodeStream/wiki/Pull-Request-IntegrationsOgpu
@DanOak Thank you for this update. I have included your comment in the answer for more visibility.Gusto
@Gusto codestream.com now has a more robust GitHub PR integration (you can create/comment/merge PRs) see codestream.com/blog/codestream-9-0-puts-github-in-your-ideWashedout
@Washedout I agree. I believe I do mention Codestream in the answer.Gusto
P
120

Most up-to-date information (March 2021)

Now, IntelliJ 2020.2 fully supports reviewing Pull Requests.

Preview of the feature

Accessing the feature

You can either navigate to: Main menu > VCS > Git > View Pull Requests.

Access from top-menu

Or it might be in your left "side-menu" (here the third option from the top):

Access from side-menu

Further information

It seems to be mostly an integration for GitHub (source):

Now the entire GitHub pull request workflow can be done directly from IntelliJ IDEA. It’s possible to browse, assign, manage, and even merge pull requests, view the timeline and inline comments, submit comments and reviews, and accept changes.

A more in-depth description of all the VCS-related features introduced can be found here:

Full GitHub Pull Requests support

We are excited to announce that IntelliJ IDEA 2020.2 will come with full support for GitHub Pull Requests!

We introduced initial support for GitHub Pull Requests with v2018.3, and we’ve been enhancing this functionality ever since. Previously, the IDE had some useful features, such as the GitHub tool window with a list of all pull requests associated with the repository, the Timeline view for a pull request, which opens in the editor, and the ability to view comments in diffs and create comments of your own. But those features were mostly for viewing pull requests and not for interacting with them.

With the upcoming IntelliJ IDEA 2020.2, you’ll be able to browse, assign, manage, and even merge pull requests, view the timeline and in-line comments, submit comments and reviews, and accept changes.

You no longer need to switch between the browser and your IDE. The entire Pull Request workflow can now be completed from within IntelliJ IDEA!

More previews

And two more sneak-peaks for the Review and Merge:

Preview #2

Preview #3


Creating PRs

Moreover, as of 2021.1, you can create Pull Requests, too:

creating a PR

Palembang answered 21/9, 2019 at 3:43 Comment(15)
I think it works only for Github, I tried to do it for a project hosted on Bitbucket and the "View pull request" option wasn't there. However, when I tried with a Github project it is there.Esemplastic
I am not seeing either with GHE.Indict
same with gitlab, it only support github by defaultLilybel
Find Pull Request plugin (plugins.jetbrains.com/plugin/8262-find-pull-request) can help add comments if you prefer not to use the modal diff view in IntelliJ PR tool window.Christine
Idem, sadly, it doesn't display the option for my Gitlab projectPlumper
Doesn't seem like code navigation is turned on. Kinda defeat the purpose of having it inside the IDE. I wonder if that feature is in the backlogAcroter
This works in Goland as well. Important to note is that if you are using .ssh/config, Jetbrains has set this up so that the hostname must match github.com exactly. Not a great way to implement this feature! A work around (if you have multiple github accounts in .ssh/config is to name the host as [email protected], set the user to git and that sort of works (update: can view comments, commits, not diffs). Also, you may need to delete your github account (in Intellij/Goland, etc) and add it again via the PR interface when it prompts for login, or you could get an already added error.Yu
This does not seem to work with Github enterprise as @Indict pointed out :(Sepalous
Seems not to work with GitLab, I entered my server, created an access token but I just can't find the view.Kym
This does work for me with Guthub EnterpriseBackrest
does anyone know if there is way to use the suggest changes feature directly from intelliJ?Umbilicus
@Umbilicus Start your code with the ```suggestion. jetbrains.com/help/idea/…Tetra
I cant create a PR and keep getting this error: "Can't create a new pull request: Head sha can't be blank, Base sha can't be blank, Head user can't be blank, Head repository can't be blank, No commits between BlahBlah:main and , Head ref must be a branch, not all refs are readable" Any ideas?Chromonema
could you please explain a similar solution for Bitbucket? because I could not do this for Bitbucket, does it possible in IntelliJ?Khalid
I am not seeing thisRottweiler
G
51

The formal support for GitHub (or BitBucket for that matter) pull request review is still pending (issue IDEA-85079, opened in 2012). It will be implemented in the 2020.2 release (see here).

Since 2016, it has support for GitHub PR in 2018.3, as commented here:

This is mostly read-only mode for now - one could create a local branch from a PR or open it on GitHub to comment/close it - but this is only the first step.

In future releases we plan to add additional functionality - ability to assign PRs IDEA-146659, merge/close them directly from IDE, comment on the PR and specific lines of code - IDEA-64794.

But: (Sept. 2019)

It's not at all obvious how to open the PR page. I had to look up the release notes to discover it's a double click. Discoverability of the PR tab is also poor; it isn't visible by default and there's no way to reach it from the version control tab, which is where I looked first.

Jan. 2020: Dan Oak mentions in the comments that:

CodeStream provides a tool to integrate GitHub PRs into IDEA.
See Pull Request Integrations:

CodeStream can display merged pull request comments in your editor as annotations on the current version of your


2016:

That leaves you with a manual process, fetching a PR, and comparing the branches:

git fetch origin pull/1234/head:pr-1234

For BitBucket:

git fetch origin refs/pull-requests/1234/from:pr-1234

(See also "How to fetch Pull Requests in BitBucket")

Then you can compare branches in IntelliJ.

Gusto answered 24/10, 2016 at 12:1 Comment(14)
I was looking for a bitbucket solution, but I guess this will come even after the github one.Haw
@gba Actually, the problem (and current solution) is the same for bitBucket pull requestsGusto
@gba I have edited the answer to include the refspec valid for BitBucket (instead of just GitHub)Gusto
I don't get then you compare branches in intellij. After fetching pull request, what to do. Pull request is not shown as branch.Prase
@ShashwatKumar the refspec refs/pull-requests/1234/from:pr-1234 should create the local branch pr-1234. If not, please open a new questio describing your issue and current setup.Gusto
Yup got it. Probably branch name pull/1234/from us wrongPrase
@Gusto - How do you leave PR comments in this process?Racklin
@Racklin I don't know if PR comments are supported on the client side (here, the IDE IntelliJ IDEA): this is more a server-side feature (on GitHub or BitBucket directly)Gusto
For BitBucket: that's nice. but how about gitlab?Phenylamine
@workplaylifecycle There exists a manual process with merge requests for GitLab (which are the equivalent of pull requests for GitHub or BitBucket). See docs.gitlab.com/ee/user/project/merge_requests/…Gusto
codestream.com provides a tool to integrate GitHub PRs into IDEA. See github.com/TeamCodeStream/CodeStream/wiki/Pull-Request-IntegrationsOgpu
@DanOak Thank you for this update. I have included your comment in the answer for more visibility.Gusto
@Gusto codestream.com now has a more robust GitHub PR integration (you can create/comment/merge PRs) see codestream.com/blog/codestream-9-0-puts-github-in-your-ideWashedout
@Washedout I agree. I believe I do mention Codestream in the answer.Gusto
O
10

I find it easier to append fetch = +refs/pull/*/head:refs/remotes/origin/pr/* under [remote "origin"] section inside .git/config so it looks like this:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = xxxxxxxxxxxxxxx.git
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

And then git fetch origin fetches all pull requests. I think this should work for BitBucket too though I haven't tested it.

Obelisk answered 9/1, 2018 at 16:3 Comment(0)
A
4

In Jetbrains 2023 you can do one of these:

  • Just open the Pull requests window(usually on the left side of IDE)
  • Or go to the menu Git -> Github -> View pull requests

For the first time, you'll need to log in with your git account.

Aerometer answered 16/1, 2023 at 13:16 Comment(1)
The question is tagged bitbucket and doesn’t say anything about GitHub. Sadly, Intellij doesn’t seem to support BitBucket right now.Notability
C
1

To view the Pull request and changes, use the following steps in Intellij:

  1. Go to version control.
  2. Click logs. There will a list of all commits.
  3. Select a perticular commits.
  4. On the right window, you will get the list of changes in this commit.
  5. Select show parent changes.
  6. Click on the files which show changes and then you will able to see all the code changes.
Carte answered 24/7, 2019 at 13:11 Comment(2)
A pull request may have multiple commits. Also, I would expect full integration with github and bitbucket for adding comments, tasks, approving, merging etc’. Thanks anyway :-)Haw
Thanks a lot @KayV. You helped a lot, even though i did knew about this, i forgot to use it on PR's.Camarata

© 2022 - 2024 — McMap. All rights reserved.