How to Contribute to Open Source
Armed with a computer, some git knowledge, and an idea, any of us can contribute to the frameworks and packages that we use every day. Cool as that may be, it can initially be a daunting experience.
So let's go on a journey together, as we take an idea for Laravel Prompts from musings to merging. Learning the basic processes will put you in good stead for contributing your own ideas.
Progress
Series Info
- Episodes
- 13
- Run Time
- 1h 49m
- Difficulty
- Intermediate
- Last Updated
- May 31, 2024
- Version
- Latest
Series Episodes
- The Pull Request (10)
Selecting a Project
So what are we going to contribute? Let's take a look at Laravel Prompts, a cool package that allows you to create beautiful CLI applications. There's a little feature I've been wanting to add for some time now that will make for a great Pull Request.Forking and Installation
Before we can write any code, we need to install Prompts locally. This involves a little bit of git work, so we'll go through these steps together that you can then apply to any project you wish to contribute to.Getting a Feel for the Code
You're going to be contributing to a project you've never worked on, with maintainers you've never worked with - already an uphill battle. That's why it's super important to get familiar with the codebase before you start hacking away at it. Let's take a brief look at how Prompts works.Build It Backwards
One of my favorite ways to code is to create the final API before writing the implementation. This approach lends to clean code that is a joy to use. Let's write a script to demo usage of our steps idea.Script Driven Development
Now that we have a script in place, we can use it to craft the implementation, which is sort of a play on TDD. We'll run the script each time we change the code until our script executes successfully.Working on Reverting
Let's turn our attention to how reverting a step works. There are several scenarios we need to consider, so we'll keep hacking away using our playground script until we get the desired output in the terminal.Prove Your Work Works
The majority of projects you'll contribute to will have tests in place, and the maintainers will expect you to add backing tests before they'll merge your contribution. Let's look at how Prompts' tests are organised and then begin to craft our own to back up the functionality we've added for steps.Refactor for Readability
With tests in place, we can now confidently refactor to clean up our contribution before publishing it for the world to see. With each change we make, we'll re-run our step tests to make sure everything still works until we're happy with how the code looks and feels.Writing a Pr Description
The time has come - it's time to create our Pull Request. As important as the code is, it's equally important that our PR description makes it easy for the maintainer and others to see exactly what we're trying to achieve. Let's take a look at the PR description I put together for steps.Fixing Failing Actions
Gasp! Shock! Panic! The Github Actions are failing! Don't worry, it's usually just a simple tweak to get them green. In this case, Prompts uses PHPStan for type checking, so we'll need to run PHPStan locally and fix the errors we're seeing.
- Maintainer Feedback (2)
Implementing Feedback: Part 1
If your PR is more than a few lines of code, it's likely that the maintainer will have feedback with changes they'd like to see. In our case, we have some fairly extensive changes to make, so let's deal with those changes (both physically and emotionally) in the next couple of episodes.Implementing Feedback: Part 2
Along with changing terminology from steps to form, Jess has also requested that we implement a cool idea she had for chaining prompts directly rather than passing closures each time. Let's see if we can get that working to complete our feedback checklist.
- Wrapping Up (1)
