2017-06-27 04:33:23 +02:00
|
|
|
# Reviewing Zulip code
|
2016-10-19 10:26:51 +02:00
|
|
|
|
2021-08-20 21:53:28 +02:00
|
|
|
Code review is a key part of how Zulip does development! If you've
|
2017-06-27 04:33:23 +02:00
|
|
|
been contributing to Zulip's code, we'd love for you to do reviews.
|
2021-08-20 21:53:28 +02:00
|
|
|
This is a guide to how. (With some thoughts for writing code too.)
|
2017-06-27 04:33:23 +02:00
|
|
|
|
2021-02-19 16:04:19 +01:00
|
|
|
## Protocol for authors
|
|
|
|
|
|
|
|
When you send a PR, try to think of a good person to review it --
|
|
|
|
outside of the handful of people who do a ton of reviews -- and
|
|
|
|
`@`-mention them with something like "`@person`, would you review
|
|
|
|
this?". Good choices include
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- someone based in your timezone or a nearby timezone
|
|
|
|
- people working on similar things, or in a loosely related area
|
2021-02-19 16:04:19 +01:00
|
|
|
|
|
|
|
Alternatively, posting a message in
|
|
|
|
[#code-review](https://chat.zulip.org/#narrow/stream/91-code-review) on [the Zulip
|
2021-07-26 07:04:26 +02:00
|
|
|
development community server](https://zulip.com/developer-community/), would
|
2021-02-19 16:04:19 +01:00
|
|
|
help in reaching out to a wider group of reviewers. Either way, please be
|
|
|
|
patient and mindful of the fact that it isn't possible to provide a
|
|
|
|
quick reply always, but that the reviewer would get to it sooner or later.
|
|
|
|
Lastly, ensuring the your PR passes CI and is organized into coherent
|
|
|
|
commits would help save reviewers time, which could otherwise be used
|
|
|
|
to dive right into reviewing the PR's core functionality.
|
|
|
|
|
2021-03-15 03:20:04 +01:00
|
|
|
### Responding to a review feedback
|
|
|
|
|
|
|
|
Once you've received a review and resolved any feedback, it's critical
|
2021-08-20 21:53:28 +02:00
|
|
|
to update the GitHub thread to reflect that. Best practices are to:
|
2021-03-15 03:20:04 +01:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- Make sure that CI passes and the PR is rebased onto recent `main`.
|
|
|
|
- Post comments on each feedback thread explaining at least how you
|
2021-03-15 03:20:04 +01:00
|
|
|
resolved the feedback, as well as any other useful information
|
|
|
|
(problems encountered, reasoning for why you picked one of several
|
|
|
|
options, a test you added to make sure the bug won't recur, etc.).
|
2021-08-20 21:45:39 +02:00
|
|
|
- Mark any resolved threads as "resolved" in the GitHub UI, if
|
2021-03-15 03:20:04 +01:00
|
|
|
appropriate.
|
2021-08-20 21:45:39 +02:00
|
|
|
- Post a summary comment in the main feed for the PR, explaining that
|
2021-03-15 03:20:04 +01:00
|
|
|
this is ready for another review, and summarizing any changes from
|
|
|
|
the previous version, details on how you tested the changes, new
|
2021-08-20 21:53:28 +02:00
|
|
|
screenshots/etc. More detail is better than less, as long as you
|
2021-03-15 03:20:04 +01:00
|
|
|
take the time to write clearly.
|
|
|
|
|
|
|
|
If you resolve the feedback, but the PR has merge conflicts, CI
|
|
|
|
failures, or the most recent comment is the reviewer asking you to fix
|
|
|
|
something, it's very likely that a potential reviewer skimming your PR
|
|
|
|
will assume it isn't ready for review and move on to other work.
|
|
|
|
|
|
|
|
If you need help or think an open discussion topic requires more
|
|
|
|
feedback or a more complex discussion, move the discussion to a topic
|
2021-08-20 21:53:28 +02:00
|
|
|
in the Zulip development community server. Be sure to provide links
|
2021-04-25 22:54:23 +02:00
|
|
|
from the GitHub PR to the conversation (and vice versa) so that it's
|
2021-03-15 03:20:04 +01:00
|
|
|
convenient to read both conversations together.
|
2021-03-06 06:11:06 +01:00
|
|
|
|
2017-06-27 04:33:23 +02:00
|
|
|
## Principles of code review
|
|
|
|
|
|
|
|
### Anyone can review
|
|
|
|
|
|
|
|
Anyone can do a code review -- you don't have to have a ton of
|
|
|
|
experience, and you don't have to have the power to ultimately merge
|
|
|
|
the PR. If you
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- read the code, see if you understand what the change is
|
2017-06-27 04:33:23 +02:00
|
|
|
doing and why, and ask questions if you don't; or
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- fetch the code (for Zulip server code,
|
2017-06-27 04:33:23 +02:00
|
|
|
[tools/fetch-rebase-pull-request][git tool] is super handy), play around
|
|
|
|
with it in your dev environment, and say what you think about how
|
|
|
|
the feature works
|
|
|
|
|
|
|
|
those are really helpful contributions.
|
|
|
|
|
|
|
|
### Please do reviews
|
|
|
|
|
2021-02-19 16:04:19 +01:00
|
|
|
Doing code reviews is an important part of making the project grow.
|
2017-06-27 04:33:23 +02:00
|
|
|
It's also an important skill to develop for participating in
|
2021-08-20 21:53:28 +02:00
|
|
|
open-source projects and working in the industry in general. If
|
2017-06-27 04:33:23 +02:00
|
|
|
you're contributing to Zulip and have been working in our code for a
|
|
|
|
little while, we would love for some of your time contributing to come
|
|
|
|
in the form of doing code reviews!
|
|
|
|
|
|
|
|
For students participating in Google Summer of Code or a similar
|
|
|
|
program, we expect you to spend a chunk of your time each week (after
|
|
|
|
the first couple of weeks as you're getting going) doing code reviews.
|
|
|
|
|
|
|
|
### Fast replies are key
|
|
|
|
|
|
|
|
For the author of a PR, getting feedback quickly is really important
|
2021-08-20 21:53:28 +02:00
|
|
|
for making progress quickly and staying productive. That means that
|
2017-06-27 04:33:23 +02:00
|
|
|
if you get @-mentioned on a PR with a request for you to review it,
|
|
|
|
it helps the author a lot if you reply promptly.
|
|
|
|
|
|
|
|
A reply doesn't even have to be a full review; if a PR is big or if
|
|
|
|
you're pressed for time, then just getting some kind of reply in
|
|
|
|
quickly -- initial thoughts, feedback on the general direction, or
|
|
|
|
just saying you're busy and when you'll have time to look harder -- is
|
|
|
|
still really valuable for the author and for anyone else who might
|
|
|
|
review the PR.
|
|
|
|
|
|
|
|
People in the Zulip project live and work in many timezones, and code
|
|
|
|
reviewers also need focused chunks of time to write code and do other
|
2021-08-20 21:53:28 +02:00
|
|
|
things, so an immediate reply isn't always possible. But a good
|
2017-06-27 04:33:23 +02:00
|
|
|
benchmark is to try to always reply **within one workday**, at least
|
2021-08-20 21:53:28 +02:00
|
|
|
with a short initial reply, if you're working regularly on Zulip. And
|
2017-06-27 04:33:23 +02:00
|
|
|
sooner is better.
|
|
|
|
|
2016-10-19 10:26:51 +02:00
|
|
|
## Things to look for
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _The CI build._ The tests need to pass. One can investigate
|
2016-10-19 10:26:51 +02:00
|
|
|
any failures and figure out what to fix by clicking on a red X next
|
|
|
|
to the commit hash or the Detail links on a pull request. (Example:
|
2021-03-15 18:39:44 +01:00
|
|
|
in [#17584](https://github.com/zulip/zulip/pull/17584),
|
|
|
|
click the red X before `49b10a3` to see the build jobs
|
|
|
|
for that commit. You can see that there are 7 build jobs in total.
|
|
|
|
All the 7 jobs run in GitHub Actions. You can see what caused
|
2018-12-28 12:51:13 +01:00
|
|
|
the job to fail by clicking on the failed job. This will open
|
|
|
|
up a page in the CI that has more details on why the job failed.
|
2021-03-15 18:39:44 +01:00
|
|
|
For example [this](https://github.com/zulip/zulip/runs/2092955762)
|
|
|
|
is the page of the `Ubuntu 18.04 Bionic (Python 3.6, backend + frontend)` job.
|
|
|
|
See our docs on [continuous integration](../testing/continuous-integration.md)
|
2018-12-28 12:51:13 +01:00
|
|
|
to learn more.
|
2016-10-19 10:26:51 +02:00
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Technical design._ There are a lot of considerations here:
|
2016-10-19 10:26:51 +02:00
|
|
|
security, migration paths/backwards compatibility, cost of new
|
|
|
|
dependencies, interactions with features, speed of performance, API
|
2021-08-20 21:53:28 +02:00
|
|
|
changes. Security is especially important and worth thinking about
|
2016-10-19 10:26:51 +02:00
|
|
|
carefully with any changes to security-sensitive code like views.
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _User interface and visual design._ If frontend changes are
|
2016-10-19 10:26:51 +02:00
|
|
|
involved, the reviewer will check out the code, play with the new
|
|
|
|
UI, and verify it for both quality and consistency with the rest of
|
2021-08-20 21:53:28 +02:00
|
|
|
the Zulip UI. We highly encourage posting screenshots to save
|
2016-10-19 10:26:51 +02:00
|
|
|
reviewers time in getting a feel for what the feature looks like --
|
|
|
|
you'll get a quicker response that way.
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Error handling._ The code should always check for invalid user
|
2021-08-20 21:53:28 +02:00
|
|
|
input. User-facing error messages should be clear and when possible
|
2016-10-19 10:26:51 +02:00
|
|
|
be actionable (it should be obvious to the user what they need to do
|
|
|
|
in order to correct the problem).
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Testing._ The tests should validate that the feature works
|
2016-10-19 10:26:51 +02:00
|
|
|
correctly, and specifically test for common error conditions, bad
|
|
|
|
user input, and potential bugs that are likely for the type of
|
2021-08-20 21:53:28 +02:00
|
|
|
change being made. Tests that exclude whole classes of potential
|
2016-10-19 10:26:51 +02:00
|
|
|
bugs are preferred when possible (e.g., the common test suite
|
2020-06-25 17:35:25 +02:00
|
|
|
`test_markdown.py` between the Zulip server's [frontend and backend
|
2019-09-30 19:37:56 +02:00
|
|
|
Markdown processors](../subsystems/markdown.md), or the `GetEventsTest` test for
|
2017-06-27 04:33:23 +02:00
|
|
|
buggy race condition handling).
|
2016-10-19 10:26:51 +02:00
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Translation._ Make sure that the strings are marked for
|
2016-12-14 07:38:54 +01:00
|
|
|
[translation].
|
2016-12-14 07:36:57 +01:00
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Clear function, argument, variable, and test names._ Every new
|
2016-10-19 10:26:51 +02:00
|
|
|
piece of Zulip code will be read many times by other developers, and
|
|
|
|
future developers will grep for relevant terms when researching a
|
|
|
|
problem, so it's important that variable names communicate clearly
|
|
|
|
the purpose of each piece of the codebase.
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Duplicated code._ Code duplication is a huge source of bugs in
|
2016-10-19 10:26:51 +02:00
|
|
|
large projects and makes the codebase difficult to understand, so we
|
2021-08-20 21:53:28 +02:00
|
|
|
avoid significant code duplication wherever possible. Sometimes
|
2016-10-19 10:26:51 +02:00
|
|
|
avoiding code duplication involves some refactoring of existing
|
|
|
|
code; if so, that should usually be done as its own series of
|
|
|
|
commits (not squashed into other changes or left as a thing to do
|
|
|
|
later). That series of commits can be in the same pull request as
|
|
|
|
the feature that they support, and we recommend ordering the history
|
2021-08-20 22:54:08 +02:00
|
|
|
of commits so that the refactoring comes _before_ the feature. That
|
2016-10-19 10:26:51 +02:00
|
|
|
way, it's easy to merge the refactoring (and minimize risk of merge
|
|
|
|
conflicts) if there are still user experience issues under
|
|
|
|
discussion for the feature itself.
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Completeness._ For refactorings, verify that the changes are
|
2021-08-20 21:53:28 +02:00
|
|
|
complete. Usually one can check that efficiently using `git grep`,
|
2016-10-19 10:26:51 +02:00
|
|
|
and it's worth it, as we very frequently find issues by doing so.
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Documentation updates._ If this changes how something works, does it
|
2021-08-20 21:53:28 +02:00
|
|
|
update the documentation in a corresponding way? If it's a new
|
2016-10-19 10:26:51 +02:00
|
|
|
feature, is it documented, and documented in the right place?
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Good comments._ It's often worth thinking about whether explanation
|
2016-10-19 10:26:51 +02:00
|
|
|
in a commit message or pull request discussion should be included in
|
|
|
|
a comment, `/docs`, or other documentation. But it's better yet if
|
|
|
|
verbose explanation isn't needed. We prefer writing code that is
|
|
|
|
readable without explanation over a heavily commented codebase using
|
|
|
|
lots of clever tricks.
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Coding style._ See the Zulip [code-style] documentation for
|
2021-08-20 21:53:28 +02:00
|
|
|
details. Our goal is to have as much of this as possible verified
|
2016-10-19 10:26:51 +02:00
|
|
|
via the linters and tests, but there's always going to be unusual
|
|
|
|
forms of Python/JavaScript style that our tools don't check for.
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Clear commit messages._ See the [Zulip version
|
2016-10-19 10:26:51 +02:00
|
|
|
control][commit-messages] documentation for details on what we look
|
|
|
|
for.
|
|
|
|
|
2017-06-27 04:33:23 +02:00
|
|
|
### Zulip server
|
|
|
|
|
|
|
|
Some points specific to the Zulip server codebase:
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Testing -- Backend._ We are trying to maintain ~100% test coverage
|
2017-06-27 04:33:23 +02:00
|
|
|
on the backend, so backend changes should have negative tests for
|
|
|
|
the various error conditions.
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _Testing -- Frontend._ If the feature involves frontend changes,
|
2021-08-20 21:53:28 +02:00
|
|
|
there should be frontend tests. See the [test
|
2017-06-27 04:33:23 +02:00
|
|
|
writing][test-writing] documentation for more details.
|
|
|
|
|
2021-08-20 22:54:08 +02:00
|
|
|
- _mypy annotations._ New functions should be annotated using [mypy]
|
2021-08-20 21:53:28 +02:00
|
|
|
and existing annotations should be updated. Use of `Any`, `ignore`,
|
2018-12-17 06:13:21 +01:00
|
|
|
and unparameterized containers should be limited to cases where a
|
2017-06-27 04:33:23 +02:00
|
|
|
more precise type cannot be specified.
|
|
|
|
|
2016-10-19 10:26:51 +02:00
|
|
|
## Tooling
|
|
|
|
|
2017-06-27 04:33:23 +02:00
|
|
|
To make it easier to review pull requests, if you're working in the
|
|
|
|
Zulip server codebase, use our [git tool]
|
2016-10-19 10:26:51 +02:00
|
|
|
`tools/fetch-rebase-pull-request` to check out a pull request locally
|
2021-09-01 03:13:20 +02:00
|
|
|
and rebase it onto `main`.
|
2017-06-27 04:33:23 +02:00
|
|
|
|
|
|
|
If a pull request just needs a little fixing to make it mergeable,
|
|
|
|
feel free to do that in a new commit, then push your branch to GitHub
|
|
|
|
and mention the branch in a comment on the pull request. That'll save
|
|
|
|
the maintainer time and get the PR merged quicker.
|
2016-10-19 10:26:51 +02:00
|
|
|
|
2020-08-11 01:47:54 +02:00
|
|
|
## Additional resources
|
2016-12-14 07:38:54 +01:00
|
|
|
|
|
|
|
We also strongly recommend reviewers to go through the following resources.
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- [The Gentle Art of Patch Review](https://sage.thesharps.us/2014/09/01/the-gentle-art-of-patch-review/)
|
2016-12-14 07:38:54 +01:00
|
|
|
article by Sarah Sharp
|
2021-08-20 21:45:39 +02:00
|
|
|
- [Zulip & Good Code Review](https://www.harihareswara.net/sumana/2016/05/17/0)
|
2016-12-14 07:38:54 +01:00
|
|
|
article by Sumana Harihareswara
|
2021-08-20 21:45:39 +02:00
|
|
|
- [Code Review - A consolidation of advice and stuff from the
|
2021-08-20 22:49:36 +02:00
|
|
|
internet](https://gist.github.com/porterjamesj/002fb27dd70df003646df46f15e898de)
|
2017-02-13 22:51:29 +01:00
|
|
|
article by James J. Porter
|
2021-08-20 21:45:39 +02:00
|
|
|
- [Zulip code of conduct](../code-of-conduct.md)
|
2019-04-06 02:58:44 +02:00
|
|
|
|
2019-09-30 19:37:56 +02:00
|
|
|
[code-style]: ../contributing/code-style.md
|
2019-04-06 02:58:44 +02:00
|
|
|
[commit-messages]: ../contributing/version-control.html#commit-messages
|
2019-09-30 19:37:56 +02:00
|
|
|
[test-writing]: ../testing/testing.md
|
|
|
|
[mypy]: ../testing/mypy.md
|
2019-04-06 02:58:44 +02:00
|
|
|
[git tool]: ../git/zulip-tools.html#fetch-a-pull-request-and-rebase
|
2019-09-30 19:37:56 +02:00
|
|
|
[translation]: ../translating/translating.md
|