Pull Request Guide
This document introduces the process of submitting pull requests to the DragonOS project and its sub-projects.
If you are not yet familiar with our GitHub workflow, please read the GitHub Workflow first.
Before submitting a pull request
This guide is for people who have finished their development work locally. If you want to know how to set up a development environment and how to contribute to the DragonOS community, go to Contributing to Development.
If this is your first contribution to the DragonOS community, please start with Contributing to Development.
Make sure your pull request follows our best practices. These include following the project conventions, submitting small pull requests and commenting your code thoroughly.
Run local tests
Before you submit a pull request, run the following commands locally:
- Format the code (
make fmtorcargo fmt) - Run the static tests (for the DragonOS repository,
cd kernel && make test)
The pull request process
- Create a pull request
- Pass the automated tests
- Get an "Approve" from a reviewer and from the code owners
Is this feature or pull request necessary?
Sometimes we come up with an idea, or find a "BUG" (note the quotation marks). Before you start developing, the best approach is to discuss it with other members of the community!
The feature may be unnecessary, or it may not be a bug. A discussion will lead you to a better solution!
Feel free to open an issue or start a discussion in the DragonOS repository to talk it over!
Keep it simple, YAGNI, minimum viable product
Sometimes we need to remind each other of the core principles of software design: "keep it simple", "you aren't gonna need it" (YAGNI), "minimum viable product" (MVP), and so on.
Adding things that "we may need in the future (but which are not used now and are hard to verify fully)" goes against our development principles.
Add what you need now, and leave room for what may be needed in the future, but do not implement it now!
Small is beautiful: small commits, small requests
Small commits and small requests are reviewed faster, and they are more likely to be correct than large ones.
Attention is a scarce resource.
If your request takes 60 minutes to review, the reviewer's attention during the last 30 minutes may not be as sharp as during the first 30 minutes.
If it needs one large continuous block of time to review, it may never get reviewed at all!
Split commits
Split your request into several commits at each logical breakpoint.
Several logically meaningful commits help show the reviewer how you developed the change and what you were thinking.
Try hard to group logically different ideas into separate commits.
For example, if you find that Feature-X needs some refactoring before it fits, make one commit that only does that refactoring,
and then make another commit for Feature-X.
Find a balance in the number of commits.
A request with 25 commits is still hard to review, so use your best judgment.
Split pull requests
Alternatively, returning to our refactoring example, you can create a new branch, do the refactoring there, and then open a pull request for that change.
If you can submit the standalone, mergeable parts of your work as separate pull requests, you avoid the painful problem of constantly rebasing.
The mainline of the DragonOS repository keeps moving, so submit small pull requests and small changes as early as possible. (Once your pull request is merged into the mainline, the tedious rebase work is someone else's problem.)
Several small requests are usually better than several commits.
Do not worry about drowning us with too many small pull requests. We would rather have 100 small, obvious pull requests than 10 unreviewable monsters.
We want every pull request to work on its own, so when you split your work, use your best judgment to decide between a separate pull request and a separate commit.
As a rule of thumb, if your request is directly related to Feature-X and touches nothing else, it should probably be part of the Feature-X request.
If you can explain why you are doing something that looks useless, for example: "I promise it makes the Feature-X change easier", we will probably accept your pull request.
Open separate pull requests for fixes and general features
Put changes that are unrelated to the feature you are developing into a separate pull request.
Often, while implementing Feature-X, you will come across poor comments, badly named functions, bad structure, weak type safety and similar problems.
You should absolutely fix these problems (or at least open an issue), but do not put them in the same request as your feature. Otherwise your diff will contain too many changes, and your reviewer will not see the wood for the trees.
Look for opportunities to extract features.
For example, if you notice that you are touching many modules, think about the dependencies you are introducing between packages.
Could some of what you are doing be made more general, and moved out of and up from the Feature-X package?
Do you need to use a function or type that is unrelated to other packages?
If so, wrap/extract that code separately!
Similarly, if Feature-X is similar in form to Feature-W submitted last month, and you are copying some tricky content from Feature-W, consider extracting the core logic and using it in both Feature-W and Feature-X.
(Do this in a separate commit or pull request.)
Do not open a pull request that covers the whole repository
Often a new contributor will find problems in many places across the repository and submit a single pull request that fixes all of them at once.
Perhaps the latest version of Rust has a cool new function that everyone should be using, or a function has recently been deprecated and calls to it should be replaced with its replacement. Sometimes contributors run a linter or security scanner to find issues, or fix particular typos in comments or variable names.
The problem with this approach is that different parts of the repository are maintained by different people, so changes to those different parts need approval from different people. A pull request with 20 one-line changes scattered across the repository may end up needing 5 or more than 10 approvals before it can be merged. (Although a handful of people can approve changes to most of the repository, these people are usually the busiest and hardest to get a review from, especially when you are a new contributor with no connections in the community.)
If you really want to try to get such a pull request merged, the best thing to do is to break it up into separate pull requests by the modules it touches. You can look at the triagebot.toml file in the repository to see who owns that piece of code, and split your changes into several pull requests accordingly.
Comments matter
In your code, whenever someone might not understand why you did something (or you will forget why later), add a comment. Many code review comments are about precisely this issue.
If you think there is something fairly obvious that we could follow up on, please add a TODO.
Read the Rust Coding Style and follow its general rules on comments.
Tests
Nothing is more frustrating than starting a review and finding that the tests are inadequate or missing.
If your pull request is poorly tested or not tested at all, reviewers will be annoyed, or will not review your code at all!
Very few pull requests can change code without touching tests.
If you do not know how to test Feature-X, ask! We will be glad to help you design something that is easy to test, or to suggest suitable test cases.
Commit message guidelines
Please note that the title of your pull request should follow the Conventional Commits specification. See the Code Commit Guidelines.
Pull request comments do not appear in the commit history.
Commits and their commit messages are the permanent record of the changes in your pull request, and their commit messages should accurately describe what and why.
A commit message consists of two parts: the subject and the body.
The subject is the first line of the commit message, and for small or trivial changes this is usually the only part you need.
These can be done as "one-liners" with the git commit -m or --message flags, but only when the commit can be fully described in those few words.
The body of the commit message is the text below the subject that appears when you run git commit without the -m flag, which opens the commit message for editing in your editor.
Typing a few explanatory sentences is very useful for your review and for the long-term maintenance of the project as a whole.
commit type: this is the subject of the commit message
Any text here is the body of the commit message
some text
more text
...
# Please enter the commit message for your changes. Lines starting with '#' will be ignored, and an empty message aborts the commit.
#
# On branch example
# Changes to be committed:
# ...
#Use the following guidelines to help write well-formatted commit messages.
- Use Conventional Commits
- Try to keep the subject line under 50 characters; do not exceed 72 characters
- Capitalize the first word of the commit message subject, unless it begins with a lowercase symbol or other identifier
- Do not end the commit message subject with a period
- Use the imperative mood in the commit message subject
- Add a blank line before the commit message body
- Wrap the commit message body at 72 characters
- Do not use GitHub keywords or (@) mentions in commit messages
- Use the commit message body to explain what and why
Use Conventional Commits
For the detailed Conventional Commits specification and DragonOS's specific notes on it, see the Code Commit Guidelines.
Try to keep the subject line under 50 characters; do not exceed 72 characters
The 50-character subject line limit keeps the message summary as concise as possible.
It should be just enough to describe what is being done.
The 72-character hard limit is there to align with the maximum body width.
When you look at the repository history with git log, git pads the body text with extra spaces.
Keeping the width at 72 characters makes sure the body text is centered and easy to read in an 80-column terminal.
Providing extra context
You can use fewer characters to provide extra context by prefixing your commit message with the [type] or [area] affected by your pull request.
These labels are usually common labels that other members of the DragonOS community will understand.
For example:
feat(mm/allocator): add the xxxx allocatorfeat(api)!: send an email to the customer when a product is shippedfix(epoll): fix epoll not waking up the target process in the xxx case
These can be elaborated further in the body, describing the content of this pull request or commit.
Capitalize the first word of the commit message subject, unless it begins with a lowercase symbol or other identifier
The commit message subject is like a condensed sentence.
The first word should be capitalized, unless the message begins with a symbol, initialism or other identifier, which should usually be lowercase.
Do not end the commit message subject with a period
This is mainly to save space, and it also helps keep the subject line as short and concise as possible.
Use the imperative mood in the commit message subject
The imperative mood can be thought of as giving a command; it is a present-tense statement that describes exactly what is being done.
Good examples:
- Fix the x error in y
- Add foo to bar
- Revert the commit "baz"
- Update the pull request guide
Bad examples:
- Fixed the x error in y
- Added foo to bar
- Reverted the wrong commit "baz"
- Updated the pull request guide
- Fix more issues
A good general guideline for forming an imperative commit subject is that it should fill this sentence:
If applied, this commit will <your subject line here>Examples:
- If applied, this commit will fix the x error in y
- If applied, this commit will add foo to bar
- If applied, this commit will revert the commit "baz"
- If applied, this commit will update the pull request guide
Add a blank line before the commit message body
Git uses the blank line to determine which part of the commit message is the subject and which is the body.
The text before the blank line is the subject, and the text after it is considered the body.
Wrap the commit message body at 72 characters
Git's default column width is 80 characters.
When viewing the git log, git adds extra spaces around the body text.
This leaves you with 76 usable characters, but the text will look "lopsided".
To make the text centered and easy to read in an 80-column terminal, git pads artificially with the same amount of space on the other side, leaving 72 usable characters on each line.
Think of them as the margins of a word document.
Do not use GitHub keywords or (@) mentions in commit messages
GitHub keywords
Using a GitHub keyword followed by #<issue number> in a commit message automatically closes the corresponding issue.
[GitHub keywords] are a convenience for closing issues in pull requests, but when used in commit messages they can have unintended side effects: they usually close things that they should not have closed.
Blocked keywords:
- close
- closes
- closed
- fix
- fixes
- fixed
- resolve
- resolves
- resolved
(@) mentions
(@) mentions in commit messages send a notification to that user, and keep sending one every time the pull request is updated.
Use the commit message body to explain what and why
Commits and their commit messages are the permanent record of the changes in your pull request.
Describe why things changed and what impact they may have.
You are providing context for the reviewer and for the next person who needs to touch your code.
If something is resolving a bug, or is a response to a specific issue, you can link to it as a reference in the body itself.
These kinds of breadcrumbs are essential for tracking down future bugs or regressions, and further help explain why this commit was created.
Further reading:
- How to Write a Git Commit Message - Chris Beams
- Distributed Git - Contributing to a Project (commit guidelines)
- What's with the 50/72 rule? - Preslav Rachev
- A Note About Git Commit Messages - Tim Pope
Pushing back is okay
Sometimes reviewers make mistakes. If you have good reasons to stand by your approach, you have the right to discuss the merits of the requested change with the reviewer. Both reviewers and reviewees should discuss these issues politely and respectfully.
You may be overruled, but you may also succeed. We are all fairly reasonable people.
Another phenomenon in open source projects (where anyone can comment on any issue) is "pack mentality": your pull request receives numerous comments from numerous people, making it hard to keep up. In this case, you can ask the primary reviewer (assignee) whether they would like you to create a new branch to clean up all the comments. You do not have to fix every issue raised by every commenter, but you should give an explanation for reasonable comments.
Trivial edits
Every incoming pull request needs to be reviewed, checked, and then merged.
Although automation can help with this, each contribution also has an engineering cost. So if you find a grammar or spelling error in a file, there are probably more similar errors in that file, and you can make your request go further by checking the formatting, checking that links are valid, and fixing errors, then submitting all the fixes at once.
Some questions to consider:
- Can the file be improved further?
- Does this trivial edit greatly improve the quality of the content?
Workflow
DragonOS uses triagebot to manage the review state of pull requests; its configuration lives in the repository's triagebot.toml. The state of a pull request is represented by labels, which triagebot switches automatically based on review events:
- Create the pull request. triagebot adds the
S-等待审查(awaiting review) label to new pull requests. - When a reviewer needs to be designated, comment
@<bot account> assignorr? @usernamein the pull request. The list of owners for each directory is in the[assign.owners]and[assign.adhoc_groups]sections oftriagebot.toml. - The reviewer reviews your code and leaves comments. If the reviewer submits "request changes", triagebot replaces the label with
S-等待作者修改(awaiting author's changes). - Push your changes to the same branch, then re-request a review from the reviewer. triagebot switches the label back to
S-等待审查. - Repeat these steps until the review has no outstanding issues. A reviewer with merge permission will then merge your code into the mainline.
Pull requests labeled S-等待作者修改 or ambiguous cannot be merged. ambiguous is added by the issue checker when the pull request title does not follow the Code Commit Guidelines, so please fix the title accordingly.