Contributing to Open Source : Week 6

Alejandra Bricio
2 min readJan 5, 2021

(This story is part of the weekly assignments for my internship at Nearsoft. I hope that some of the insights I learned this week can help others in their learning journey.)

Photo by “My Life Through A Lens” on Unsplash

Issues and pull requests

This week, I worked the following issue:

  ╔═══════════╦═══════════════════════════════════╦══════════════╗
║ project ║ issue ║ status ║
╠═══════════╬═══════════════════════════════════╬══════════════╣
║ smug ║ Add `create` and `edit` commands ║ PR Opened ║
╚═══════════╩═══════════════════════════════════╩══════════════╝

How I was trying to contribute

For the smug issue (Go), I added the ability to create and edit configuration files with the smug command.

To create a file:

func (smug Smug) Create() error {
exists, err := IsFileExists(smug.configPath)
if err != nil {
return err
}
if exists {
return errors.New("File already exists")
}
file, err := os.Create(smug.configPath)
defer file.Close()
return err
}

To edit a file:

func (smug Smug) Edit() error {
editor := os.Getenv("EDITOR")
if editor == "" {
editor = "vim"
}
cmd := exec.Command(editor, smug.configPath)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
return err
}

For example, smug create <project> will create a file at ~/.config/smug/project.yml and, smug edit <project> will open that same file in the $EDITOR (or in vim, if there’s no EDITOR environment variable set.)

Any positive or negative results

Functionality for both Create and Edit are completed and also tests for Create. However, tests for Edit are a work in progress only because the test would naturally try to open a vim editor, and then it blocks the rest of the processes.

Here are a few things I tried so far:

  • Make the edit test concurrent so all three processes run at the same time. But the C/I still gets blocked with Vim open, even though all the tests pass.
  • Use a goroutine with time.Sleep(), look for the vim process, and terminate it gracefully with: kill -s 15 -p in order to avoid an exit error and continue with the tests.

Both of these didn’t work. Next, I will try to implement aMockCommander that mocks the edit of a file in order to avoid opening an external program.

What did I learn this week?

I learned about goroutines which are “a lightweight thread of execution.” Also, I continued reading Grokking Algorithms by Aditya Y. Bhargava. I improved my knowledge of Data Sctructures and Algorithms. I learned about SOLID and OOP Principles.

--

--

Alejandra Bricio

26 yo. Self-Taught Software Developer. I write about Career Change, Women in Tech and anything exciting I’m working on.