Learning to make pull requests
Tags: opensource, cpp
Published: 2021-09-24 23:32:02

This weeks lab continued on working with a classmate. However, this time instead of just pointing out an issue, we actually added our own feature for another person's application. For this week our task was to fork and clone a new branch of our partner's repo and add markdown support to our partner's SSG. Then make a pull request to the main repo.

I worked with Gus again and his [GAS-SSG](https://github.com/gusmccallum/GAS-ssg) for this lab. I decided for the markdown support, the syntax I would add would be the "# " header syntax. So I added an [Issue](https://github.com/gusmccallum/GAS-ssg/issues/15) for adding the markdown support and created a [pull request](https://github.com/gusmccallum/GAS-ssg/pull/16) with the forked branch I made. In the code I modified Gus' if statements that handled the file types to include a block that would look for the ".md" extension and also added a new file type code to represent markdown files. Furthermore, I made some adjustments to the file reader so that when it read a txt file it would handle the header/title features that were implemented by Gus. As for handling the markdown syntax, I added a makeHeader1() function that would take a string and add \<h1> tags to it.

After my initial iteration of the markdown support implementation Gus took a look at the code and found a few things I missed. In the main() I missed an if statement that was comparing the file types and had to add an else if for .md extensions. Otherwise it would have skipped all markdown files if the input was a folder. And I also made a redundant if statement by accident when I could have combined the two. I find it really helpful having someone else take a look at your code because some of the simplest mistakes can easily be over looked by you, but caught instantly by someone else. Once I finished these changes, Gus gave my branch the good to go and merged it with his main branch.

When Gus made a [pull request](https://github.com/joshuali7536/LennahSSG/pull/9) for my SSG, I found a few things I wanted him to change. First I wanted him to do the same thing as I did for his SSG; make the txt title/header functionality only work for txt files. Second, I noticed that he had if statements like this:
```
if (((line.find("**") || line.find("__") != string::npos) && fileType == 2)) {
      line = boldify(line);
}
if ((line.find("*") != string::npos || line.find("_") != string::npos) && fileType == 2) {
      line = italicize(line);
}
```
However, I wanted him to take the `fileType == 2` statement and just turn that into a parent if statement that would wrap the other two if statements. Like so:
```
if (filetype == 2){
    if (line.find("**") != string::npos || line.find("__") != string::npos){
          line = boldify(line);
    }

    if (line.find("*") != string::npos || line.find("_") != string::npos){
          line = italicize(line);
    }
}
```
From this I learned that trying to just explain code is very difficult through just comments. He had to retry a few times to get this the way I wanted. I learned to just give the example through code and talk to him through a proper messaging application like [Slack](https://slack.com/intl/en-ca/help/articles/209038037-Download-Slack-for-Windows) instead of just communicating through the comments on GitHub. 

Eventually I was happy with the code and tried to merge it with my main branch. But then I ran into some merging issues, I think what happened was because he forked my code a while ago, I made some changes where I deleted some files and I had some binary files as well because I didn't setup my .gitignore file properly initially. Thus, I wasn't able to merge the branches due to conflicting files. After some deleting and updating some files we managed to get the branches merged and everything worked fine. From this I learned the importance of keeping the branches up to date and making sure that the .gitignore file is setup properly to avoid binary files. I also learned how to remove the unwanted binary files through the console by running the following lines after a commit:
```
git rm -rf --cached .
git add .
```
All in all, this was a very helpful experience. I learned how to make a pull request with a cloned branch and learned how to solve merging conflicts (and how much a pain it is).