Performing Code Reviews Using Oracle Developer Cloud Service


Options



Before You Begin

Purpose

In this tutorial, you will learn how to perform code reviews using Oracle Developer Cloud Service and NetBeans IDE.

Time to Complete

Approximately 30 minutes

Introduction

The Merge Requests component of Oracle Developer Cloud Service allows you to do the following:

  • Create code reviews and assign them to members of your team
  • As a team member, complete an assigned code review

Scenario

You have been assigned a task to add a Java web service to a project. You'll need to create a merge request along with a Git repository branch to make the code change. Then you'll get your code change reviewed by a team member. Once it has been reviewed, you will merge the changes from the branch back to the master.

In the environment you are using for this tutorial, you may be the only team member. For this reason, you'll submit the code changes for review and then perform the review yourself.

Context

The work you do for this tutorial would normally be done as part of an assigned issue. See the OBE tutorial Managing Issues Using Oracle Developer Cloud Service for information about working on issues.

The Oracle JDeveloper Team Server works very similarly to the NetBeans IDE Team Server. You can complete the Team Server tasks using Oracle JDeveloper.

What Do You Need?

  • A login to an Oracle Developer Cloud Service instance

  • One of the following supported browsers:

    • Chrome 48 or later (also for Android)
    • Firefox 38 or later
    • Internet Explorer 11 or 12
    • Safari 7 or 8 (Mac OS)
    • Safari Mobile 5 (iOS)
  • An installation of NetBeans IDE with the Oracle Developer Cloud Service plugin. See "Using NetBeans IDE with Oracle Developer Cloud Service" in Using Oracle Developer Cloud Service.

  • Some experience developing applications in Java

  • Some familiarity with the Git source control system

  • Some familiarity with NetBeans IDE

It would be helpful if you first completed the OBE tutorials Using NetBeans IDE to Create an Oracle Developer Cloud Service Project and Managing Issues Using Oracle Developer Cloud Service. This tutorial uses the project created in the first tutorial, but you can use any project to which you have access.

Creating a Merge Request and Branch

  1. If you are not already logged in, launch your Oracle Developer Cloud Service, following the instructions in "Accessing Oracle Developer Cloud Service Using the Web Interface" in Using Oracle Developer Cloud Service. When you reach the Welcome page, click your project, which in this case is My Web Application.

    Welcome page
    Description of this image

    The project Home page opens.

  2. From the project Home page, click the Merge Requests tab to see the results of the default Created By Me standard search.

    Merge Requests tab
    Description of this image
  3. Click the New Merge Request button on the right to open the New Merge Request wizard.

    New Merge Request button
    Description of this image
  4. On the Branch page of the wizard, from the Repository drop-down list, select my-web-application.git.

    From the Target Branch drop-down list, select master.

    In the Review Branch drop-down list, enter SvcBranch to create a branch for the review. This field presents you with a list of branches if there are any, but you can also use it to create a branch if a branch of that name does not exist.

    Click Next.

    Branch page of New Merge Request wizard
    Description of this image
  5. On the Details page of the wizard, Leave the Linked Issues and Linked Builds fields empty.

    In the Summary field, enter a title for the review, such as Review Web Service.

    In the Reviewers field, select your own name. (Normally, you would assign the review to one or more members of your team.)

    Click Next.

    Details page of New Merge Request wizard
    Description of this image
  6. On the Description page of the wizard, in the Edit Description text area, enter a message such as Please review the new web service.

    Finally, click Create.

    Description page of New Merge Request wizard
    Description of this image

    The review opens in a page of its own with the following tabs: Conversation, Commits, Changed Files, Linked Issues, and Linked Builds.

    Review page
    Description of this image

    On the right side are buttons for the reviewer to use: Merge, Approve, Reject, and Close. Below the buttons are a list of reviewers and a list of linked builds.

    Review page buttons
    Description of this image
  7. Click the Code tab and view the files in the master.

    Code tab contents for master
    Description of this image
  8. Select SvcBranch from the branch drop-down list.

    Switching to branch
    Description of this image
  9. Verify that the files in the branch are the same as those in the master.

    Code tab contents for branch
    Description of this image

Creating the New Branch in NetBeans IDE

These steps assume that you previously established a connection from NetBeans IDE to your Oracle Developer Cloud Service instance by following the instructions in the OBE tutorial Using NetBeans IDE to Create an Oracle Developer Cloud Service Project.

The Oracle JDeveloper Team Server works very similarly to the NetBeans IDE Team Server. You can complete the Team Server tasks using Oracle JDeveloper.

  1. Launch NetBeans IDE if it is not already open. Click the Projects tab, right-click MyWebApp. From the menu, select Git, then select Remote, and then select Fetch.

    Fetch menu selection
    Description of this image
  2. On the Remote Repository page of the Fetch from Remote Repository wizard, click Next.

    Remote Repository page
    Description of this image
  3. On the Remote Branches page, select the SvcBranch -> origin/SvcBranch check box and click Finish.

    Remote Branches page
    Description of this image
  4. Right-click the project and select Git, then select Branch/Tag, and then select Create Branch.

    Create Branch menu selection
    Description of this image
  5. In the Create Branch dialog box, enter SvcBranchin the Branch Name field. Verify that the Revision value is master. Then select the Checkout Created Branch check box and click Create.
  6. Create Branch dialog box
    Description of this image
  7. Return to the Projects tab, right-click the project, and select Git, then select Branch/Tag, and then select Set Tracked Branch.

    Set Tracked Branch menu selection
    Description of this image
  8. In the Select Branch dialog box, select origin/SvcBranch and click OK.

    Select Branch dialog box
    Description of this image
  9. From the Team menu, select Repository, and then select Repository Browser to open the repository browser if it is not already open.

    Repository Browser menu selection
    Description of this image

    Verify that the local branch and master are tracking the remote branch and master, and that you are currently in the local branch (shown in bold).

    Repository Browser pane
    Description of this image

Making Code Changes

  1. In NetBeans IDE, right-click the project and select New, and then select Web Service. (The Web Service menu item can appear anywhere in the menu.)

    New Web Service menu selection
    Description of this image
  2. On the Name and Location page of the wizard, enter a name for the web service (MyService, for example) in the Web Service Name field. In the Package field, enter service. Finally, click Finish.

    Name and Location page
    Description of this image

    The service is created, and the source file MyService.java appears in the Source Packages area.

    Web service in Projects tab
    Description of this image

    The source file also opens in an editor pane.

    Source file in editor pane
    Description of this image
  3. NetBeans IDE shows a yellow warning icon next to the hello method. Click the icon and make the suggested changes to add @Param and @Return annotations to the Javadoc comments, then save the file.

    Source file with changes
    Description of this image
  4. Right-click your project and select Git, and then select Commit.

    Git Commit menu selection
    Description of this image
  5. In the MyWebApp - SvcBranch commit dialog box, enter Added web service in the Commit Message text area, making sure that the MyService.java file is being added. Some other NetBeans IDE files may be added and modified as well. Then click Commit.

    Commit dialog box
    Description of this image
  6. Right-click your project and select Git, then select Remote, and then select Push to Upstream.

    Push to Upstream menu selection
    Description of this image

    The commit contents are pushed to the remote branch.

Verifying the Push in Oracle Developer Cloud Service

  1. In the browser, click the Project tab and verify that the push you made appears in the activity feed.

    Commit in activity feed
    Description of this image
  2. Click Code, then click Commits. Select master from the branch drop-down list if it is not already selected, and view the commits to the master.

    Commits on Code tab Commits page
    Description of this image
  3. From the branch drop-down list, select SvcBranch.

    Switching to the branch
    Description of this image

    The new commit is displayed along with the previous ones.

    Commits on branch
    Description of this image
  4. To verify that the new service was committed, click Show Details on the right side of the commit.

    Show Details link
    Description of this image

    The commit details are displayed.

    Details of the commit
    Description of this image

Performing a Review

  1. Click the Merge Requests tab to go to to the Merge Requests page. With the default Created By Me standard search selected, the Merge Requests table shows the review you assigned to yourself, with the status OPEN. (This review also appears for all the standard searches except All Closed Requests.) Click the Review Web Service Summary link to go to the review page.

    Review in Created By Me table
    Description of this image

    The review page displays the actions related to the review: conversations, commits, file changes, linked issues, linked builds, and buttons for possible actions you might take. It now shows the commit to the branch.

    Review page
    Description of this image
  2. To review the code changes, click the Changed Files tab. You will see the new Java source file along with any other added or modified files. The changes have a green or pink background to indicate code additions and deletions.

    Viewing code changes
    Description of this image
  3. Scroll down to the source file MyService.java and mouse over the line numbers to the left of the code. A plus sign is displayed to indicate that you can add a comment. Click the plus (+) sign.

    Viewing comment icon
    Description of this image
  4. Enter a comment in the comment pane.

    Comment dialog area
    Description of this image
  5. Click the Comment button to add the comment to the code. (The Save button puts the comment in a Pending Comments tab for later publication.)

    Comment button
    Description of this image

    The comment appears in the code.

    Comment added to code
    Description of this image
  6. Click Approve to approve the changes.

    Approve button
    Description of this image
  7. In the dialog box that is displayed, add a comment (for example, Looks fine so far), and then click OK.

    Approve dialog box
    Description of this image

    The approval appears on the right side of the page.

    Approval on review page
    Description of this image
  8. Click the Conversation tab. The comment and approval also appear in the Conversation area.

    Conversation tab
    Description of this image

    You could also post a general comment at the bottom of the page, using your chosen Wiki markup language.

    Comment area on review page
    Description of this image

You have now completed your role as a reviewer. Since you are the only reviewer, the submitter (also you) can now consider the review complete.

Merging the Code

  1. Click the Back to Merge Request List icon (<) or the Merge Requests tab to return to the Merge Requests page. In the Merge Requests table, the Status column still shows the review as OPEN. Either the submitter or a reviewer can perform the merge.

    Click the review link to go to the review page.

    Review in Created By Me table
    Description of this image

    Note: By default, a submitter or reviewer can merge a branch or close a review, whether or not code changes have been approved by reviewers. Approving or rejecting a merge request is just a special way to add a comment that you approve or disapprove the changes made to the source code.

  2. On the review page, click Merge.

    Merge button
    Description of this image
  3. In the Merge dialog box, add a comment (Merging new web service after review, for example). Select the Squash commits check box, but do not select the Delete branch check box. Finally, click Merge.

    Merge dialog box
    Description of this image

    The review status is shown as MERGED.

    MERGED status on review page
    Description of this image
  4. Click the Merge Requests tab. The completed review appears in the Merge Requests table for the Created By Me, All Closed Requests, and All Requests standard searches, with the status MERGED.

    MERGED status in Created By Me table
    Description of this image
  5. Click the Project tab. The main review actions appear in the activity feed.

    Review actions in activity feed
    Description of this image
  6. Click Code and look at the comment on the SvcBranch branch.

    Merged code on branch in Code tab
    Description of this image
  7. In the branch drop-down list, select master.

    Switching to master
    Description of this image

    View the comment on the master. The merge comment appears on the master.

    Merged code on master
    Description of this image

Now you can pull the changes down to your local repository using NetBeans IDE.

Pulling the Changes to Your Local Repository

  1. In NetBeans IDE, log in to the Team Server. From the Team menu, select Team Server, and then select Login. Click Login in the Login to Team Server dialog box.

    Team Server login
    Description of this image
  2. Click the Projects tab. Right-click the MyWebApp project and select Git, then select Remote, and then select Pull.

    Pull menu selection
    Description of this image
  3. On the Remote Repository page of the Pull from Remote Repository wizard, click Next.

    Remote Repository page of Pull wizard
    Description of this image
  4. On the Remote Branches page, select both check boxes, and then click Finish.

    Remote Branches page of Pull wizard
    Description of this image

    The local branch is updated with any changes from the remote one. In the Repository Browser, though, the local master is behind origin/master.

    Repository Browser window
    Description of this image
  5. Now, pull the changes to the local master. Right-click the project and select Git, then select Branch/Tag, and then select Switch to Branch.

    Switch to Branch menu selection
    Description of this image
  6. In the Switch to Selected Branch dialog box, select master, and then click Switch.

    Switch to Selected Branch dialog box
    Description of this image
  7. The project does not currently contain the new web service. Right-click the project and select Git, then select Remote, and then select Pull.

    Pull menu selection
    Description of this image
  8. On the Remote Repository page of the Pull from Remote Repository dialog box, click Next.

    Remote Repository page of Pull wizard
    Description of this image
  9. On the Remote Branches page, verify that the master -> origin/master check box is selected, and then click Finish.

    Remote Branches page of Pull wizard
    Description of this image

    The new web service code now appears in the project.

    Projects tab with new web service in master
    Description of this image

    In the Repository Browser, the local and remote master are now in sync.

    Repository Browser window
    Description of this image

    If you wish, you can now return to the browser and delete the branch from the merge request.

Want to Learn More?