Let's merge a remote
Tags: opensource
Published: 2020-10-18 16:33:17

This week was comprised of so much stuff, from the wild commute and hours I'm still working to the double feature of GitHub projects I worked on (more on that in another blog post). Frankly, I don't know how I found the time for it all - but we pull through here!

This week the plan was to add a feature to our apps that allowed users to ignore links that are present in a specified file.

Also, the goal was to get used to using git remotes which were not terribly difficult to work with.

First, I added an issue to [Yifan's](https://github.com/Joy3van/linked-out/issues/1) repo, asking to add the feature - he was quickly responsive and I moved forward!

The feature itself was fairly annoying to implement - not because the concept was difficult or because programmatically it was hard to do - don't forget that I already had the code for reading the links file and extracting them - the difficult part was comparing the arrays of links and removing the links in the original array.

```
let urlArr = chunky.match(urlRegex);
        if (options.ignore){ // if ignore is used, we loop through the ignore array and compare that to the array of links, removing links if they match
            urlArr = urlArr.filter(url => !ignArr.includes(url));
        }
        urlArr.forEach(url => {
            linkCheck(url);
        })
    });
```

This doesn't look hard from my code, all I really did was add an if statement to see if the user put in the ignore option, and filtered the array to keep only the links that DON'T match the array of links to ignore.

Honestly, once I figured out how to properly use ``.filter`` it was simple - my main problem was trying all sorts of other methods because I wanted to stick as closely as possible to Yifan's coding style. Using many ``.forEach()`` loops to loop through arrays. Once I did some research and used ``.filter``, the rest came easily.

In order to have my edits added to Yifan's repo, I [notified](https://github.com/Joy3van/linked-out/issues/1#issuecomment-711219863) him of my edits and he [added](https://github.com/Joy3van/linked-out/commit/f2a0a778598b04b466ded0c3126795695bbfc838) them with some changes of his own.

It's at this point I should mention that Yifan also asked to add the same feature to [my repo](https://github.com/fluentinstroll/Link-Checker/issues/7) and I graciously accepted.

Working with remotes in a "repo owner" capacity, I used ``remote`` to take a look at Yifan's changes and approved them, while also making my own changes which you can see in [these commits.](https://github.com/fluentinstroll/Link-Checker/pull/8/commits)

My changes just consisted of adding the functionality description to the [readme](https://github.com/fluentinstroll/Link-Checker/pull/8/commits/008f99e900b1f2b6a2c412e226c5f3a3ac2485f7) of the project. 

I also tried to add some error handling to the app because when the user adds a filename for ``--ignore`` and it doesn't exist, an error gets thrown that is fairly difficult to read. I would like to add a more readable error through ``try{}catch{}`` but in my attempts to do this and my research into how it works with ``async`` functions, it seems like you just can't without changing the code greatly which I wouldn't want to do since it basically involves butchering Yifan's commit. At a later date, I'll take another look at the error handling.

```
 /* trying to add error handling for when the file doesn't exist, but it seems because it's asynchronous, we cannot actually do it because the error will always be reported on the system level before we can catch it 

thinking of a way to fix this including making this function synchronous */
```
- a comment excerpt from my code

Using remote with git is great because I can just take a look at another person's branch to check on it and make my own branch to edit it which makes collaborating so much easier. The only real issue I had with using remotes was getting Yifan to actually add my change to his repo. So when I create a remote and ask Yifan to take a look at it, it's at his leisure when he wants to. Though I suppose that could be an upside and also isn't dissimilar from asking for a pull request. I wonder if a pull request is a better way to merge commits though, simply because it's easier to review on GitHub and is more of an open forum to talk about the changes vs a remote that just sits in my repo that the maintainer has to look at and review.

This blog post was all about changing other students' repos and merging our remotes together to form a better app in the end. I learned all about how to create a remote of another student's branch and the process of collaborating with other students through GitHub in a more in-depth way. Remotes are a very useful way to review and work on other collaborators' projects and it's very likely I'll be using them in the future with other projects.