DEV Community

LemonFish
LemonFish

Posted on

Open Source 101: My First PR to Hertz

Introduce

Recently, with the enthusiastic help of Hertz community friends, I tried to submit a pull request to Hertz(an open-source Golang 's Http high performance framework) to support Hertz in using Consul for service registration and discovery. Here, I will briefly record the whole process from PR to merged, which is convenient for myself and other friends in need.

The link of PR: feat: Support Hertz to use Consul for service discovery and registration

 

Step 1: Find the open source library you are interested in

Find the open source library you are interested in

 

Search Github

First of all, we can choose some open source libraries that we are interested in, such as Hertz mentioned above.
 

View Issues

Then looking at the Issues list, we can see that there are 22 issues waiting to be resolved 👀.

At present, there are still many interesting issues which may be of interest to you.

view issue

The Hertz community usually releases some newbie tasks from time to time, so we can start with some simple tasks first.

 

Among them, we found that one of the issues is that Hertz is preparing to expand the service registration and discovery .

issue list

Issue:https://github.com/cloudwego/hertz/issues/197

 

Looking at the details of this issue, we can see that it includes the following parts

  1. The description and purpose of the issue
  2. Where is the code repository?
  3. Referrable API
  4. Etc

issue description

 

Apply for issues

If you find this issue interesting, you can take the initiative to apply to complete the issue.

Apply for issues

Right now , we have taken the development task for the issue and can work on it next.

 

Step 2:Wirte the code

Wirte the code

 

Fork target repository

Fork target repository
We first need to fork the repository you want to contribute to your own repository, by forking we can code and not affect the original repository.
 

Clone Target Repository

Now our repository contains the repository we forked, we need to clone it to our local machine.

Clone Target Repository

git clone [YOUR HTTPS ADDRESS]
Enter fullscreen mode Exit fullscreen mode

 

Create a new branch

After cloning, we need to create a new branch for our development.
For new features, we can use feat/xxx as the branch name.

git checkout -b [BRANCH NAME]
Enter fullscreen mode Exit fullscreen mode

 

Develop and push remote branches

Usually the development needs include implementation code, unit test , README, etc
After some development is done, we can start git trifecta

  • git status
  • git add [YOUR FILE]
  • git commit -m [YOUR COMMIT MESSAGE]
  • git push origin [YOUR BRANCH]
    • Before performing git push , you can use git remote to see the name of your remote repository.

git remote
 

Unit test combined with github action

Generally, open source libraries will be combined with github actionfor unit test pipeline, the directory of repository will have .github/workflows/xxx.yml file and some other files . Through these files we can perform our unit test in the pr , push and other stages.

Therefore, we need to update these files to ensure that we can pass our own unit test .
 

Creating a Pull Request

After the push is complete, we can see the following prompt in our fork repository Compare & pull request

Creating a Pull Request

Next we can fill in the information about the PR , usually we need to describe the following information

  1. What type of PR is this? (feature, fix, etc.)
  2. What does this PR do?
  3. Does this PR address certain issues?

Open a pull request

After filling in the PR information, congratulations, you can create your own PR! 🥰🥰
 

Synchronize changes to the original repository

During our development, there may be other developers who have already merged their PRs into the main branch.

Then we need to merge the changes into our own development branch.

Here are some steps you can take :

  1. Add original repository as upstreamrepository
git remote add upstream [HTTPS]
Enter fullscreen mode Exit fullscreen mode
  1. Get changes from the original repository
git fetch upstream
Enter fullscreen mode Exit fullscreen mode
  1. Merge changes
git merge upstream/main
Enter fullscreen mode Exit fullscreen mode
  1. Resolve conflicts and push to your own development branch   ## Step 3: Fix the suggestion made by the original repository maintainer After submitting the PR , we need to make sure that all unit tests pass. At the same time, there will also be some suggestions from the maintainer of the original repository, which need us to solve
  2. unit test needs to be completed .
  3. Doc needs supplements .
  4. There is a problem with the code implementation .
  5. Etc For example: README needs to be added in more detail

The suggestion made by the original repository maintainer
 

Step 4: Wait for PR Merged

After all verification steps are completed, you need to wait for the original repository maintainers to approve and merge your pull request .

Wait for PR Merged

When your PR is officially adopted, there will be the following tips.

Pull request successfully merged

Finally, congratulations on taking your first step towards open source ! ❤️
 

Reference

Top comments (0)