My first Open Source contribution!
Tags: opensource
Published: 2023-09-22 19:02:37

This week I made code contribution to my classmate [Yumei](https://dev.to/wanggithub0)'s GitHub repo, [ConvertTxtToHtml](https://github.com/WangGithub0/ConvertTxtToHtml). ConvertTxtToHtml is written in Java and is a command-line program which converts .txt files to .html. I added a two new features to the program:

- to allow .md files as input in addition to .txt files
- to convert md syntax links to html syntax links

Here is the process I went through to make my contribution:

1) First I filed an issue on her [main project GitHub](https://github.com/WangGithub0/ConvertTxtToHtml). This allowed her to give me feedback on how she would like me to handle the issue.

2) Next I [forked the project](https://github.com/kliu57/ConvertTxtToHtml) on GitHub, and cloned my fork. I created a [branch](https://github.com/kliu57/ConvertTxtToHtml/tree/issue-7) for my work and named it issue-7 after the issue I filed earlier.

3) On my local machine, I tested the existing program to make sure there were no bugs. I read the code thoroughly to understand how it worked, and to familiarize myself with her coding style and formatting style. Then I added my new features, taking care to make as little change to the existing program as possible. To do this, I created private helper functions to separate my code, and then called those functions in a few locations in her existing code. I also added comments, and updated the existing [README](https://github.com/kliu57/ConvertTxtToHtml/blob/issue-7/README.md) file to include my changes. After testing my changes and adding a test file to her folder of test files, I pushed the changes to my branch.

4) I created a [Pull Request](https://github.com/WangGithub0/ConvertTxtToHtml/pull/8) in her main project repo and submitted my branch. I described what changes I made and asked for her review and her feedback on any changes she required.

5) Yumei commented on my pull request with changes she wanted me to make:

- fix a bug where `[someText][linkText](http://linkgoeshere)` would display someText as a link rather than linkText
- make link conversion only occur for .md files (not .txt files)

6) I fixed the issues she brought up, and pushed the changes to my branch. I then replied to her comment that each item was fixed.

7) Yumei commented that my changes looked good and merged my [Pull Request](https://github.com/WangGithub0/ConvertTxtToHtml/pull/8). Since I used the keyword "Closes #7" in my pull request, the issue I raised was automatically closed.

---

Initially I had some problem trying to figure out the best way to convert links from md to html. I did some research online and decided to use regular expressions. I did a lot of testing with the Pattern and Matcher classes so that I understood how to use regex to identify patterns in a string. Then I wrote my private helper function which converted links from md to html.

Aside from learning how to use regex to parse strings in Java, I also learned to do more thorough testing. Yumei found a bug which I could have caught myself if I had tested with more edge cases. Next time I make a contribution, I will create a series of test input files to test multiple edge cases and document my testing in a file so that I ensure I test all the scenarios.

---

Yumei also contributed to my Open Source application, which was a similar program, [go-go-web](https://github.com/kliu57/go-go-web), but written in Python. She raised [an issue](https://github.com/kliu57/go-go-web/issues/6) and submitted a [Pull Request](https://github.com/kliu57/go-go-web/pull/7) to my repo. Here are the steps I took to review and merge her pull request.

1) Read the details of her [Pull Request](https://github.com/kliu57/go-go-web/pull/7). It include the following features:

- support for .md files
- converting md syntax bold and italics text to html syntax bold and italics text
- changes to version file and README file

2) I cloned her branch to my local so that I could review the code. I used the following command:
```
git clone --single-branch --branch <branchname> <remote-repo>
```

3) I read and tested her code. I found a bug, which I took screenshots of and asked her to fix in a comment to her [Pull Request](https://github.com/kliu57/go-go-web/pull/7). The bug was that the italics conversion was erasing a space. I also asked her to add a test file that tests both the bold and italics conversion.

4) She fixed the issues I mentioned and I merged the [Pull Request](https://github.com/kliu57/go-go-web/pull/7).