Skip to content

Writing a Good Pull Request

Rachel Fenichel edited this page May 1, 2020 · 15 revisions

⁉️ Needs review ⁉️

TODO: Add links to styleguides & blockly api guidelines

🦘 RE: style guide section, I think its hard to set a style guide for example code as different ecosystems have different patterns, Codelabs too, it's markdown, little style guidance there. For plugins, definitely worth mentioning that we abide by the Google JavaScript style guide: https://google.github.io/styleguide/jsguide.html

🐙 In the page on writing a codelab I wrote a short section on writing style, said code should follow the google style guide, and added a link to Technical Writing One so that we don't have to rewrite everything they've said about good technical writing.


Pull requests are like life blood of a repository, they keep everything healthy and moving. This page details how to create a PR that is complete and easy to review, which makes it more likely that your PR will get merged!

What follows are a few steps you can take to make sure you create the best PR possible.

  1. Communicate
  2. Get Set Up
  3. Keep it Small
  4. Keep it Clean
  5. Test your Change
  6. Communicate (pt2)

Communicate

Before you jump in and start writing code, it's helpful to communicate with the core team so they know what you're interested in.

If there is an issue you are interested in, which is in your jurisdiction and has the correct status, the communication is simple! Just put a comment on the issue saying you're going to start to work on it. This makes sure that we don't have multiple people working on the same thing.

Alternatively, if you have an idea which is not covered by an issue, please write one up before you begin work. This gives the team a chance to discuss how best to build out the change before you start building. So it will save you work in the long run.

Get Set Up

If you've contributed to a GitHub repository before, the process for getting set up will be familiar to you. It's important to note that in this repo we work off of the master branch. This is different than the Blockly core repo, where work is done off of develop.

If you haven't contributed to a GitHub project before, you can use these steps to get started:

  1. Fork and clone the blockly-samples repository. GitHub has a wonderful tutorial about forking a repo. To apply it to blockly-samples, just replace every instance octocat/Spoon-Knife with google/blockly-samples.
  2. Sync your fork with this repo. GitHub provides a tutorial for syncing a fork as well.
  3. Create a new branch by running the below command in a terminal. The name should help you remember what you're working on.
    git checkout -b myBranchName
    
  4. Make your changes. Be sure to follow the rest of the recommendations in this doc!
  5. Save your changes. You can use the below commands to commit your work.
    git commit -am "My commit message"
    git push origin myBranchName
    

Keep it Small

Always try to keep your changes small and focused. We would much rather review multiple smaller PRs than review one giant PR. Some good rules of thumb are:

  • Fix one problem. Don't try to tackle multiple issues at once.
  • Limit the scope. Usually a PR should take < 8hrs (depending on your familiarity with the codebase).
  • Use commits. If your PR feels a little big, split the changes into logical groups using git commits.

Keep it Clean

Style is important to us in this repository because it makes the project easier to maintain in the long run. Be sure to read the styleguide for your specific category of project before you get to work:

  • [Plugin styleguide]
  • [Example styleguide]
  • [Codelab styleguide]

If you are writing a plugin you should also read through the [Guidelines on Using Blockly APIs].

Test your Change

Before you put up a PR you should always test that your changes are working, so that you don't have to go back and fix things later. Here are some ideas for testing the different categories of projects:

  • For plugins you should write automated mocha tests covering your changes.
  • For examples you should manually test all of your demonstrated functionality.
  • For codelabs you should run through the entire tutorial and test any example code you provide.

Communicate

This is the last and arguably the most important part of creating a PR! Writing up the summary.

This is your chance to show the team how well you've followed the above steps, and how excited you are about getting your change in. Writing a great PR summary also helps other developers review your changes, making it more likely that it will get accepted faster!

Your summary should include things like:

  • What issue your PR is related to.
  • What change your PR adds.
  • How you tested your change.
  • Anything you want reviewers to scrutinize.
  • Any other information you think reviewers need.

If you follow the PR template when your create your request you should be good to go! Just remember to be as concise and complete as possible.

Happy Coding!

Clone this wiki locally