Hey there,
In today's blog, I would like to explain how to create pull request templates. If you are a developer who works within a team or even just someone who is active in the open-source community, I assume you are already familiar with the term itself. Pull request
is a feature that makes it easier for developers to collaborate on the same project. The idea behind is that you create a copy of the project in your local machine then do your changes and create a pull request with your local changes to ask for approval to be merged in the main project.
It is completely fine if you ask yourself what in the earth is pull request
, I am not pulling anything. Well, I feel you. I had the exact same feeling at the beginning until I learnt that pull request actually stands for asking someone to pull your code into the main project. Makes sense right? I thought so.
Why should you create a template for pull requests?
Developers might already know what pull request is but that doesn't necessarily mean that we know how to use it.
The ideal pull request should have a clear, concise structure where the contributor explains:
- Content of pull request
- The improvements that are applied to already existing code
- Ways to reproduce or test the new functionalities
Those are some of the major topics that can be considered to be addressed in almost every pull request. If you follow the word, believe me, your colleagues will appreciate you even more.
If you also agree on providing preliminary information about your pull request reduces the load on reviewers shoulders, we can already have a look at how we can create a template to include in every pull request.
First of all, create a file called pull_request_template.md
at the root of the project.
As the file is placed on the root of the project, it is visible to others. If for some reason you don't want to expose the file, you can store it under the
.github
folder.
Then its time to make the changes. It is your responsibility to think about which sort of questions or statements you want to include. I have thought of my use cases and the best practices, which led me to write something like this:
## <p align="center">Pull Request Check List</p>
#### Before someone reviews this PR please make sure that all above are checked:
- [ ] Your code builds without any error and/or warnings
- [ ] No commented out lines and/or forgotten console logs
- [ ] No hardcoded strings, all the strings are declared as variables
- [ ] You feel confident that this code is clean enough to merge
### I have tested this feature on following devices:
- [ ] Mobile
- [ ] Tablet
- [ ] Desktop
### I have tested this feature on following browsers:
- [ ] Chrome
- [ ] Firefox
- [ ] Safari
- [ ] Brave
### Thanks a lot for your contribution!
With this template, I inform contributors beforehand to check things mentioned there. If you are already familiar with markdown, I guess you get what goes on here. For those who are new to markdown, - [ ]
creates a basic HTML checkbox and leaves it empty. While - [x]
creates checkbox and fills it. Hashtag signs stand for headers. For instance, #
is equivalent to <h1>
. I assume you can already guess what is the equivalent of ##
. At the end this markdown would generate something like this:
As you see on the very first line, I have used plain HTML with a slight difference in syntax. Even though markdown supports basic HTML and inline CSS properties, you shouldn't be surprised to see that names would change. In my example, I have used align
instead of style={{textAlign:"center"}}
which is not supported. Check this page out to see how flexible markdown is!
Before finishing, I would like to make sure that my contributors do not accidentally remove the template. To ensure that, I will add a warning text at the top and comment out to not expose it when pull request is live.
[//]: # "----------- PLEASE DO NOT CHANGE ANYTHING BELOW THIS LINE -----------"
Conclusion
You might have never thought of creating a pull request template for your project but believe me you will regret that you didn't do it earlier! Since we have started to use templates in our private projects, we have saved a lot of time as a team. The main reason is that without the template we had to ensure certain conditions were met by the pull request manually. Now, it is automated and we save time for other important things!
Please do not hesitate to share your pull request template in the comments. In the meantime, you can already check here to see how this template looks like. Until next time, take care!