Open Source 101: My First PR to Hertz
Tags: go, webdev, beginners, opensource
Published: 2022-11-02 03:34:26

## 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)](https://github.com/cloudwego/hertz) 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](https://github.com/hertz-contrib/registry/pull/8)

&nbsp;

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

![Find the open source library you are interested in](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6ojmae53rpx5h69brae.png)



&nbsp;
### Search Github
First of all, we can choose some open source libraries that we are interested in, such as [Hertz](https://github.com/cloudwego/hertz) mentioned above.
&nbsp;

### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3x3hyovsiamz0irwbax.png)



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

&nbsp;


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

![issue list](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d87h5hsz4x639rdh44ty.png)


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


&nbsp;

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r9yuuzaizr54ib6op490.png)

&nbsp;
### Apply for issues
If you find this issue interesting, you can take the initiative to apply to complete the issue.

![Apply for issues](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4rrk8pcydsixokbq50un.png)



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

&nbsp;
## Step 2：Wirte the code

![Wirte the code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jcvt7mgc86lxxircruqr.png)


&nbsp;
### Fork target repository

![Fork target repository](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0q0w0a6pndhitufd0v39.png)
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.
&nbsp;
### Clone Target Repository
Now our repository contains the repository we forked, we need to clone it to our local machine. 

![Clone Target Repository](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/79ftsxkv7ip1p1g5npli.png)

```git
git clone [YOUR HTTPS ADDRESS]
```
&nbsp;
### 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
git checkout -b [BRANCH NAME]
```
&nbsp;
### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7y978mcz5kp7bztdk6k.png)
&nbsp;
### 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 .
&nbsp;
### 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qr935cwiw21319osopbz.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eg26uvg6w7ywurllazsn.png)

After filling in the PR information, congratulations, you can create your own PR! 🥰🥰
&nbsp;
### 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
git remote add upstream [HTTPS]
```
2. Get changes from the original repository
```git
git fetch upstream
```
3. Merge changes
```git
git merge upstream/main
```
4. Resolve conflicts and push to your own development branch
&nbsp;
## 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
1. unit test needs to be completed .
2. Doc needs supplements .
3. There is a problem with the code implementation .
4. Etc
For example: README needs to be added in more detail


![The suggestion made by the original repository maintainer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tek21bxay6cpfgzbq4b5.png)
&nbsp;

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z9dhvw5malmqyn2m51nz.png)

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


![Pull request successfully merged](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pz9lmpca6rwshysvbay.png)

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

## Reference
- [Hertz(an open-source Golang 's Http high performance framework)](https://github.com/cloudwego/hertz)
- [GitHub Actions Documentation - GitHub Docs](https://docs.github.com/en/actions)
- [Connection refused? Docker networking and how it impacts your image](https://pythonspeed.com/articles/docker-connection-refused/)
- [What is Consul? | Consul by HashiCorp](https://www.consul.io/docs/intro)