Skip to end of metadata
Go to start of metadata

Prerequisite: Set Up

The actions described in this section depend on having the requisite set of tools and settings on your development machine. See Setting Up Your Development Environment.

Note: replace openecomp.org with onap.org in all screen captures - reason: https will authenticate against the actual onap.org domain but ssh will redirect from either.

Reference: Gerrit Code Review for Git

ONAP uses Gerrit to automate the process of reviewing all code changes before they are committed to the Git repository. Here is a tutorial and reference on using Gerrit: https://gerrit.onap.org/r/Documentation/index.html.

Using the Command Line to Clone the Repository

  1. Move to the folder at the root of your development directory. For example:
    cd C:\Users\<user>\Documents\work
     
  2. Add a remote pointer to the Gerrit server that hosts your repository using either SSH or HTTPS. (Note: <REPONAME>s are given in various Development Guides.
    Using SSH:
    git remote add origin ssh://USERNAME@gerrit.openecomp.org:29418/<REPONAME>

    Using HTTPS:
    With HTTPS, first you will need the Gerrit HTTP-generated password for each HTTPS operation with Gerrit/Git.

    git remote add origin 
    https://USERNAME@gerrit.onap.org/r/a/<REPONAME>
     
  3. Now clone the remote repository. Since we clone in the current folder, it will create a subfolder with the remote copy.
    Using SSH:
    git clone ssh://USERNAME@gerrit.openecomp.org:29418/<REPONAME>

    Using HTTPS:
    With HTTPS, first you will need the Gerrit HTTP-generated password for each HTTPS operation with Gerrit/Git.

    git clone https://USERNAME@gerrit.onap.org/r/a/<REPONAME>

Using IntelliJ to Clone From, and Commit To, Gerrit/Git

Visit https://gerrit.onap.org and log in, using your Linux Foundation identity. Here, you will be able to view the names of Projects to which you have access.

On top of the project listing, the web site provides you the command to clone the whole project, such as:


The project can be downloaded in either of two ways, via HTTP url or SSH url.

IntelliJ and SSH URL (Recommended)

To download the project using an SSH URL, you need to have already added your SSH key into the Gerrit website.

Having added your key, visit https://gerrit.onap.org/r/#/admin/projects/ and select the project you are working on. The Gerrit site will show the full URL for the project:


Next, within IntelliJ, select File -> New -> Project from Version Control -> Git to open the Clone Repository window. Enter the SSH URL from above, including the project name (mso in this example), and chose your local Parent Directory. IntelliJ will fill in the Directory Name for you. Click Clone to clone the project.


For the first downloading, a window will appear to authenticate the host.Click Yes to continue.


IntelliJ and HTTP URL (Alternate Method)

Open IntelliJ and click File -> Settings -> Version Control -> Gerrit. In the resulting dialog box, enter the Gerrit URL as shown above, along with your Linux Foundation username and password. To test whether the connection is good, you can click the Test button:

https: Required

The URL must use https:, not http:.

Once you have entered this information, click OK:


Then open File -> New -> Project from Version Control -> Git to open Clone Repository window. Enter the http url you have found above, but with https not with http, chose your local Parent Directory and Directory Name and click Clone to clone the project.


A window will pop up to input the user name and password. The user name is the username of your Linux Foundation account, and the password is the Gerrit HTTPS password generated during setup.

Commit Changes Locally

Once you have made changes in the code, before you push the changes, you should commit the code locally.

To do that, go to the Version Control window, under Local Changes, right click the changed files and click Commit Changes....


In the Commit Changes window, enter the Commit Message, select Sign-off commit option and click Commit button.


Pushing Changes for Review Using a Command Line (optional)

Here are the Git commands to add some files and make a commit with an associated message:

git add somefiles

git commit -am "My first Awesome commit"

Note that this is just an example and the commit message should be more explicit than that.

Now that everything is ready, you can sign off your commit:

git review -s

if asked for a remote gerrit run

git config --global gitreview.remote origin

You may be prompted for your Linux Foundation account password. To verify that the commit worked, this command will show you the commit message and the sign off entry:

See the exact commit message format at Commit Messages

git commit -as --amend


Automatic signature mode

You can automatically add the signature for all your commits by setting the git configuration:

git config --global format.signoff true

Verify you are setup with the correct account

vi ~/.gitconfig

[gitreview]

        username = youruser


Eventually, we can push the change to the gerrit server:

git review

Committer Actions

The code should now appear in the gerrit web interface. It needs a committer to approve it with a +2 rating, and to also move the verifed flag to +1. The committer does this by visiting the gerrit.onap.org site and logging in.


The committer may take any of several actions, such as clicking on the "Reply" button, adding reviewers, adding a review comment, and moving the flags to +2 and +1


Once a committer approves it, the code can be merged to the master branch.

Then go to the Terminal window, use command apt-get install git-review to install git-review plugin in the machine, if not already installed.


Once installed, under root location of the project enter command git config --list, make sure the email address listed is exactly the same as the one you used in your Linux Foundation account.


If your address is not present or not the same as the one defined in Linux Foundation account, enter command git config --global user.email "jondoe@somewhere.com".

Then enter command git commit -as --amend to show the commit message and the sign off entry, as shown below. Make sure the email address is the exactly the same as the email you used in the Linux Foundation account. If not, update the address.


Then enter command git review to upload the changed code into the Linux Foundation for reviewing.


Go to Gerrit window and refresh, the committed changes will be shown in the window. Right click the commit, you can find the tab to Add Reviewers for reviewing or Abandon the changes if you don't want it any more.


If you have been selected as the reviewer of the changes. You can right click the corresponding commit and click ReviewCode-Review to give your score and comments for the change.


Failed Commit / Resubmit

If issues are found, both contributors and committers can amend the review (use the top-left download link on the review screen to get the direct clone commands that would download the reviewed code in a local repository)

Similarly to the above steps, do the needed modifications, and push the changes (again after signing them) using git review

Note that you can also work on local branch, Gerrit will automatically use your local branch name as a Topic for the review, allowing you to share branches between team members.


Example Session

  ssh-add onap_rsa

  git clone ssh://username@gerrit.openecomp.org:29418/portal

or via https (note openecomp.org now redirects to onap.org)

obrienbiometrics:onap4 michaelobrien$ git clone https://gerrit.onap.org/r/a/mso

Cloning into 'mso'...

Username for 'https://gerrit.onap.org': michaelobrien

Password for 'https://michaelobrien@gerrit.onap.org': 

remote: Total 4596 (delta 0), reused 4596 (delta 0)

Receiving objects: 100% (4596/4596), 2.94 MiB | 1.68 MiB/s, done.

Resolving deltas: 100% (1985/1985), done.


  • No labels

14 Comments

  1. In intellij, I had to use http for the Gerrit setup, and then for the Git Clone, as opposed to https. When I tried with https, it never accepts either my onap, or my generated http password.

  2. I tried setting up the environment as suggested in this page using the 'IntelliJ and HTTP URL (Alternate Method)'. I ran into issues of Maven dependency resolving and authentication. So I did the following things to solve them:

  3. Had the same not authenticated issue with https cloning (ssh works fine) - turned out to just need a domain change to onap.org - thanks Shashank

    DOC-5 - Getting issue details... STATUS

    looks like a dig of both openecomp.org and onap.org point to the same IP

    openecomp.org. 10800 IN A 50.56.49.117

  4. I successfully cloned an ONAP repo using authenticated http.

    However, when I tried to setup the repo for git review by running:

     git review -s

    I got the following error:

        git_review.cmd.GitReviewException: Could not connect to gerrit at ssh://tianl@gerrit.onap.org:29418/aai/model-loader

    It appears that git review is trying to connect via SSH, but SSH is blocked by my proxy. Is it possible to configure git review to connect using HTTP?

    1. Try creating a remote named "gerrit" that points to http:

      git remote add gerrit https://gerrit.onap.org/r/p/<REPONAME>.git


      1. Thanks Skip Wonnell, I figured this out eventually.

        However, another solution is to configure gitreview to use "origin" as its origin by setting the following:

        $ git config --global gitreview.remote origin
  5. Following Tian's request, would we have any way to review via https? it's blocking us from pushing changes for review..

  6. FYI - the commit should not have the JIRA in the summary, but instead in the external references section. See Commit Messages for an example.

    1. I agree, I'll do a test commit without the JIRA in the title.

      Currently though adding the JIRA in the title links the JIRA to the review - and also launches the JIRA

      See the merge fix for AAI today in  AAI-134

      https://gerrit.onap.org/r/#/c/6749/

      click the link in gerritt

      [AAI-134] Removed duplicate invStatus

      If linking still occurs - then we don't need the commit comment link

      I'll try in 

      OOM-5 - Getting issue details... STATUS

      /michael

      1. Yeah the linking has been inconsistent when not using the summary.


        Andrew has been helping me and has told me these guidelines:

        1) Does the author = the person uploading and do they have the name and

        address correctly registered


        2) Is the subject line <= 50 characters


        3) Are < 33% of the body lines <= 72 characters


        4) Is there a JIRA key in the footer matching the following regex:

        ([A-Z][A-Z0-9]{1,9}-\\d+). It does not technically need to be prefixed

        with Issue-Id: it's just a good convention.


        5) Is there a Signed-off-by line in the footer of the person uploading

        the change

        1. I receive a "failed to check if issue exists" error from git review.   Is the Issue-ID field the correct location for the JIRA  number?   Im using this issue:   APPC-87 - Getting issue details... STATUS

          $  git log -1
          commit a241c44c21d99f0e91bf28eef218d404a98f87de
          Author: Skip Wonnell <xxxxx@xxxxx>
          Date:   Sat Aug 12 12:29:07 2017 -0500

              Update license plugin to exclude Json
              
              Change-Id: Ia18ab61c69de7f522e1483ebe85ae54dcc419c84
              Signed-off-by: Skip Wonnell <xxxxx@xxxxx>
              Issue-ID: APPC-87


          $  git review -D
          remote: Processing changes: refs: 1, done            
          remote: Failed to check whether or not issue APPC-87 exists        
          remote: java.io.IOException: RestClientException{statusCode=Optional.of(403), errorCollections=[]}        
          To ssh://skipwonnell@gerrit.onap.org:29418/appc.git
           ! [remote rejected] HEAD -> refs/drafts/master/jsonLicenseFix (Failed to check whether or not issue APPC-87 exists)
          error: failed to push some refs to 'ssh://skipwonnell@gerrit.onap.org:29418/appc.git'




          1. As per the guidelines given on (Commit Messages), Issue-ID should come before Change-Id. Signed-off-by should be the last statement in your "external references" section or in the footer. Though on the link page it doesn't talk about this sequence and what can break if not followed, but you can give a try by pushing Issue-ID above Change-Id.

      2. The multi-line commit structure works very well - reviews are still referenced back to the JIRA

        Follow

        CommitStructure

        and use a "git commit --amend" for reviews already in progress.

        /michael

  7. Suggest explaining on this page that reviews receive "Verified +1" by the automated build job if it succeeds, or Verified -1 if the build fails. Ideally (warning) reviewers should wait for the build to succeed before adding their +1 and +2 votes.