DPS909 Blog - Lab 4: Using Git Remotes and Merges
Tags: opensource
Published: 2022-10-04 07:22:57

This week in my Open-Source course (DPS909), we were introduced to the concept of git remotes and merges. The purpose of this lab was to help us to practice using git remotes and merges to collaborate with our peers on some code changes.

[Lab 3](https://dev.to/alexsam29/dps909-blog-lab-3-managing-simultaneous-changes-988) was a change of pace as we worked on our own repos and did not collaborate with anyone. Now with lab 4, it's back to collaborating and adding features to other people's projects.

## My Contribution
I decided to collaborate with [Neil](https://github.com/NeilAn99) and contribute to [his static site generator](https://github.com/NeilAn99/nan1-ssg).

### Feature Added
I wanted to add support for JSON formatted configuration files. The `config` file would contain all of the options that the tool supports. Instead of having users specify all of the SSG options as command line arguments, they can just specify the `config` file. So I created an [issue](https://github.com/NeilAn99/nan1-ssg/issues/13) and created a draft pull request so the owner can see the work I'm doing.

#### Code Changes
Implementing this feature was not too difficult. The main problem was to figure out a way to read and parse a JSON file and then assign those values to the appropriate option.

First, I [added](https://github.com/NeilAn99/nan1-ssg/pull/14/files#diff-58417e0f781b6656949d37258c8b9052ed266e2eb7a5163cad7b0863e6b2916aR10) an additional option so that the tool will accept `-c`/`--config` flags.

I then [added](https://github.com/NeilAn99/nan1-ssg/pull/14/files#diff-58417e0f781b6656949d37258c8b9052ed266e2eb7a5163cad7b0863e6b2916aR20) a conditional statement that will check if a `config` file path was specified. If it was, then a [new function](https://github.com/NeilAn99/nan1-ssg/pull/14/files#diff-58417e0f781b6656949d37258c8b9052ed266e2eb7a5163cad7b0863e6b2916aR45-R60) called `readConfigFile` will parse the JSON file if it exists. The parsed values then get [passed into](https://github.com/NeilAn99/nan1-ssg/pull/14/files#diff-58417e0f781b6656949d37258c8b9052ed266e2eb7a5163cad7b0863e6b2916aR24) `generateHTML` to generate the appropriate HTML files.

## Contribution to My Project
I had an [issue](https://github.com/alexsam29/ssg-cli-tool/issues/17) that was created on my repo that wanted to add similar feature.

A draft [pull request (PR)](https://github.com/alexsam29/ssg-cli-tool/pull/18) was created for this issue, so I was following every commit to make sure everything was going smoothly.

Once the PR was marked 'ready for review', I added a git remote to test the files changes locally on my machine.  I didn't have much trouble working with git remotes because I had unknowingly used this feature before through Visual Studio Code's GitHub extension. The only adjustment I had to make was using the command line to create the remote instead of the GUI.

I did find [one issue](https://github.com/alexsam29/ssg-cli-tool/pull/18#pullrequestreview-1127770237) with the PR which had to do with error handling. I suggested adding an error message to handle non-existent `config` files.

This issue was swiftly addressed and fixed. I then used the git remote to test one final time before approving the changes and merging.

## Conclusion
This lab went pretty smoothly. I didn't have any problems adding features to another repository or creating the PR.  Most likely because I was familiar with the tech stack and language in use. I also unknowingly had experience using git remotes, so again, I had no problems with testing the PR on my repo. I just need to get more accustomed to using the command line for git remotes, instead of relying on git GUI solutions.