89
All change lists must be reviewed. Period. “Review your code like a Googler” 2013 Dariusz Łuksza Dariusz Łuksza, CollabNet [email protected] @dluksza

Review your code like a Googler

Embed Size (px)

DESCRIPTION

Presentation about Code Review and Gerrit given at Confitura 2013 conference. Shows how to start with Gerrit, how configure Ecipse Mylyn Gerrit Connector plugin and how perform code reviews directly in the IDE

Citation preview

Page 1: Review your code like a Googler

All change lists must be reviewed. Period.

“Review your code like a Googler”

2013 Dariusz Łuksza

Dariusz Łuksza, [email protected]

@dluksza

Page 2: Review your code like a Googler

2013 Dariusz Łuksza

Are you Git?

pre-requirements

Page 3: Review your code like a Googler

First rule of Code Review:

2013 Dariusz Łuksza

Your code is not your wife...

pre-requirements

Page 4: Review your code like a Googler

First rule of Code Reviewand OpenSource:

2013 Dariusz Łuksza

Your code is not your wife...

pre-requirements

Page 5: Review your code like a Googler

2013 Dariusz Łuksza

Your code is not your wife...you can share it!

pre-requirements

First rule of Code Reviewand OpenSource:

Page 6: Review your code like a Googler

2013 Dariusz Łuksza

I'm here for You!

Page 7: Review your code like a Googler

2013 Dariusz Łuksza

Next ~47min.

● Code Review & Types● Post-commit vs pre-commit● The Gerrit● EGit + Mylyn Review Gerrit Connector● Command line→ ● Code Review Tips● Q&A

Code reviews with Gerrit by Mateusz Szczap@ Marmolana 14:50

Page 8: Review your code like a Googler

2013 Dariusz Łuksza

Code Review

Page 9: Review your code like a Googler

post-commit review(formal code review)

2013 Dariusz Łuksza

Page 10: Review your code like a Googler

post-commit review(formal code review)

2013 Dariusz Łuksza

Page 11: Review your code like a Googler

2013 Dariusz Łuksza

Flickr: markcph

post-commit review(formal code review)

Page 12: Review your code like a Googler

2013 Dariusz Łuksza

Flickr: markcph

post-commit review(formal code review)

Coffee, absolute must have during formal code reviews

Page 13: Review your code like a Googler

2013 Dariusz Łuksza

Flickr: sebastian_bergmann

post-commit review(formal code review)

Page 14: Review your code like a Googler

2013 Dariusz Łuksza

Flickr: bike

post-commit review(formal code review)

Page 15: Review your code like a Googler

2013 Dariusz Łuksza

review on request(post- or pre-commit)

Page 16: Review your code like a Googler

2013 Dariusz Łuksza

review on request(post- or pre-commit)

90 minlater

OK, so whereI was before...

Hi Jeff, could you review my changes

before I submit

I need a review...

OK, lets go!

Can I interrupt youfor a moment?You already

interrupted me...

Sure you can,what is it?

this loop iteratesover… mhm... and then

it brakes...

if (req != null) { for (i = 0; …if (...) break;

...

I finished my task and need finalcode review... would you like

to look on it?

emmmm … OK...

153 minlater

9 minlater

finally I can getback to my task...

… and then...

Page 17: Review your code like a Googler

2013 Dariusz Łuksza

asynchronous review with Gerrit

(pre-commit)

Page 18: Review your code like a Googler

2013 Dariusz Łuksza

Gerrit Code Review this loop iterates

over… mhm... and thenit brakes...

if (req != null) { for (i = 0; …if (...) break;

...

found it!! HAHAHA

OK, so now,commit and

push for review!

… step into...step over...

… step over...step over...

It's time to check othersreview requests

I'm invincible!!

Great! There are requestsfrom Tom, Sara and Jim...

let me see...

Page 19: Review your code like a Googler

post-commitvs.

pre-commit

2013 Dariusz Łuksza

Page 20: Review your code like a Googler

Flickr: bike2013 Dariusz Łuksza

post-commit vs. pre-commit

Flickr: sriram

VS.

Page 21: Review your code like a Googler

2013 Dariusz Łuksza

The Gerrit

Page 22: Review your code like a Googler

The Gerrit

● Created for Android OpenSource project● Designed to bring Google's code review feeling to

Android community● Pure Java based● Has vibrant community● Used in many OpenSource project's and Enterprise

companies● Can be used as regular Git server without code review● Supports branch based permissions● It is getting more and more extend-able

2013 Dariusz Łuksza

Page 23: Review your code like a Googler

2013 Dariusz Łuksza

Who uses Gerrit?

Page 24: Review your code like a Googler

2013 Dariusz Łuksza

let's play with Gerrit

Page 25: Review your code like a Googler

Demo Time!

Preconditions:– You are joining new team with already existing

project

– Somebody already creates yours account in LDAP

– You already generated yours SSH key

– Already have Eclipse Kepler with EGit and Mylyn Gerrit connector installed

2013 Dariusz Łuksza

Page 26: Review your code like a Googler

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Meet Fred

Page 27: Review your code like a Googler

First login into Gerrit

2013 Dariusz Łuksza

First login into Gerrit

2013 Dariusz Łuksza

fredInsert yours credentials here

Page 28: Review your code like a Googler

First login into Gerrit

2013 Dariusz Łuksza

First login into Gerrit

2013 Dariusz Łuksza

fred

Yours SSH public key goes here,remember to click 'Add'

Page 29: Review your code like a Googler

First login into Gerrit

2013 Dariusz Łuksza

First login into Gerrit

2013 Dariusz Łuksza

fred

Finally, click 'Continue'

Page 30: Review your code like a Googler

First login into Gerrit

2013 Dariusz Łuksza

First login into Gerrit

2013 Dariusz Łuksza

fredYou are logged in

Page 31: Review your code like a Googler

Configure Mylyn Connector

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Add task repository

Page 32: Review your code like a Googler

Configure Mylyn Connector

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

If you don't have Gerrit connector on the list, use 'Install More Connectors' button

Select Gerrit and click 'Next'

Page 33: Review your code like a Googler

Configure Mylyn Connector

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Provide server data

Validate before save

Finally, click 'Finish' to save new connection

Page 34: Review your code like a Googler

Configure Mylyn Connector

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Of course I would like to create query for this connector

Page 35: Review your code like a Googler

Configure Mylyn Connector

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Name the query

For our simple use case 'All open changes' will be enough

Page 36: Review your code like a Googler

Configure Mylyn Connector

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

After successful configuration you will see task repository and query in proper Eclipse views

Page 37: Review your code like a Googler

Cloning project from Gerrit

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 38: Review your code like a Googler

Clone project from Gerrit

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 39: Review your code like a Googler

Clone project from Gerrit

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 40: Review your code like a Googler

Clone project from Gerrit

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 41: Review your code like a Googler

Clone project from Gerrit

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 42: Review your code like a Googler

Clone project from Gerrit

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 43: Review your code like a Googler

Clone project from Gerrit

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Because in git repository there is no Eclipse configuration file (like eg. .project) we need to import it as 'general project'

Page 44: Review your code like a Googler

Clone project from Gerrit

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 45: Review your code like a Googler

Clone project from Gerrit

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Now we can import nested Maven projects

Page 46: Review your code like a Googler

Clone project from Gerrit

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 47: Review your code like a Googler

Clone project from Gerrit

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 48: Review your code like a Googler

Create new feature branch

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 49: Review your code like a Googler

Create new feature branch

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 50: Review your code like a Googler

Create first change

2013 Dariusz Łuksza2013 Dariusz Łuksza

fredChange something in repository

Page 51: Review your code like a Googler

Create first change

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Remember to check generation of 'Change-Id' tagLeave this line as it is,

EGit will generate 'Change-Id' for you

Page 52: Review your code like a Googler

Create first change

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Now push yours changes to Gerrit

Page 53: Review your code like a Googler

Create first change

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Provide name of branch to which change should be merged after successful review

Page 54: Review your code like a Googler

Create first change

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 55: Review your code like a Googler

Create first change

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

After some time you will see yours change on list of open changes

Page 56: Review your code like a Googler

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Meet Roman

Page 57: Review your code like a Googler

Review change

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Page 58: Review your code like a Googler

Review change

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Double click on file will open a compare view

Page 59: Review your code like a Googler

Review change

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Page 60: Review your code like a Googler

Review change

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

You can provide comments directly for each code line

Page 61: Review your code like a Googler

Review change

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Page 62: Review your code like a Googler

Review change

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Page 63: Review your code like a Googler

Review change

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

As you see Jenkins already have an opinion about this change

Page 64: Review your code like a Googler

Review change

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

You can publish yours comments using 'Publish Comments...' button

Page 65: Review your code like a Googler

Review change

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Now you can provide yours vote and comment for this change

Page 66: Review your code like a Googler

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Switch back to Fred

Page 67: Review your code like a Googler

View incoming comments

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

You will be informed about new comments on yours reviews

Page 68: Review your code like a Googler

Abandon change

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

If you push something by accident you can always abandon such change

Page 69: Review your code like a Googler

Abandon change

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Page 70: Review your code like a Googler

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Pushing multiple changes

Page 71: Review your code like a Googler

Push multiple commits

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Create two or more commits in a rowand use standard EGit 'Push to Gerrit...' flow

Page 72: Review your code like a Googler

Push multiple commits

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Gerrit will create separate review requests for each commit

Page 73: Review your code like a Googler

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Switch to Roman

Page 74: Review your code like a Googler

Review connected changes

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Of course you will see two open changes, let's review last one!

Page 75: Review your code like a Googler

Review connected changes

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Jenkins already verified this change, so let's merge it!

Page 76: Review your code like a Googler

Review connected changes

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Page 77: Review your code like a Googler

Review connected changes

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Last step is to push 'Submit' button

Page 78: Review your code like a Googler

Review connected changes

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Change was submitted, but it is not merged because it's parent change is still under review. It will be automatically merged after parent will be accepted

Page 79: Review your code like a Googler

Review connected changes

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Let's review second change

Page 80: Review your code like a Googler

Review connected changes

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Let's review second change

Page 81: Review your code like a Googler

Review connected changes

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Of course it was merged successfully

Page 82: Review your code like a Googler

Review connected changes

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Of course it was also merged successfully

Wat is going with previously submitted change?

Page 83: Review your code like a Googler

2013 Dariusz Łuksza2013 Dariusz Łuksza

roman

Roman goes to Bahama(continue other's work)

Page 84: Review your code like a Googler

Continue other's work

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

All changes are stored in Gerrit, you can fetch each patch set version when ever you want to

Page 85: Review your code like a Googler

Continue other's work

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Provide meaningful branch name and click 'Finish'

Page 86: Review your code like a Googler

Continue other's work

2013 Dariusz Łuksza2013 Dariusz Łuksza

fred

Done, you have Roman's changes locally and can continue his work

Page 87: Review your code like a Googler

Code Review Tips● Be constructive, don't hate, always propose or point to

solution

● Don't take comments personally, they are only about code and how you can improve, code and your skills

● Code review is like refactoring of code that you have written long time ago … you need to understand author's intention

● It's like TDD, review code before it hit main repository. This will guarantee the best application quality

● Do code review on daily basis … remember when you are not reviewing other's code then application is not progressing

2013 Dariusz Łuksza

Page 88: Review your code like a Googler

2013 Dariusz Łuksza

Dariusz Łuksza, [email protected]

@dluksza

“Review your code like a Googler”

Q&ASlides can be found at: http://goo.gl/R3Vfk

Page 89: Review your code like a Googler

2013 Dariusz Łuksza

BTW. Don't forget about DevCrowd conference in Szczecin in 2014. More

info you can found at: http://devcrowd.pl