Chapter 2

New Contributors

Welcome, New Contributors!

This section is all about helping you get started with open source and Athens.

Let’s get started with learning how to use git

Subsections of New Contributors

Using Git

What is git?

Git is a free and open source distributed version control system. What does that really mean? It is a way to track changes to files on your computer. This is like keeping a detailed log of every time you change a file, what lines and characters were changed. So you could look at the log and see what changed, or undo those changes if you wanted or if you are working with others you can merge your changes together.

It’s a lot to take in, so don’t worry if you aren’t following yet.

If you want a more detailed walk through than we provide here, have a look at the Git Book.

Installing

Let’s start by getting git installed on you machine. You can check if it’s already installed by running git --version from the command line.

Follow your operating system specific instructions in Chapter 1.5 of the Git Book.

Basic concepts

Repository
This is a file structure on disk, like a database, it contains all files and the log of changes.
Staging
When you make changes inside a repository, they are untracked. You decide which changes to track, as you add changes they are added to the staging area. This let's you see all current changes before committing them.
Commit
After you are happy with the changes tracked in staging, you can commit them to the log we mentioned. You have a few options for writing a message that will be stored with the commit in the log, more on that later.
Branch
When you are in the repository the default out of the box is usually called `master`. This is the main branch of the repository (NOTE: if you are creating a new repository of your own, please change the default branch to `main`. `master` is an inappropriate and offensive), the main branch of the repository. Typically you will want to do your work on a new branch for each feature or bug. This allows you to see and work on different versions of the same code in one repository.
Checkout
To check out a branch, is to switch to view that branches version of the files in the repository.
Merge
When you want to incorporate another branch, `main` or someone else's feature for example, into your current branch you will merge the changes. This will apply the other changes on top of yours.
Remote
This is just a repository, that is accessible remotely. You can use the git command to push and pull changes to.
Push
Pushing to a remote will synchronize your locally committed changes to the remote.
Pull
Pulling from a remote will both fetch and merge the changes on the remote with the branch you have currently checked out.
Fetch
When you want to get some remote branch or changes, but not merge them yet, you can fetch them. Just ask the remote for the data and store it locally but not incorporate it into anything. You could then checkout the feature branch and run the code, or read over the changes.

Try it out

There is a great interactive tutorial, for free, available at Code Academy. Take some time to play with it and try out some of the commands.

Docs

Contributing To Docs

Contributing to docs is just as important, if not more important than, writing code. We use GoHugo to run this website. So if you’d like to improve it, here’s how you can run it locally:

  1. Install the Hugo binary: https://github.com/gohugoio/hugo#choose-how-to-install
  2. cd ./docs && hugo server

The Hugo server will run on http://localhost:1313 and it will automatically watch your files and update the website every time you make a change.

Alternatively you can run our custom docker image as outlined here

Github

Using GitHub

We use GitHub to host the remote copy of our repository and both track our issues and manage our pull requests. If you haven’t signed up before, take a minute to go do that now. We’ll be right here when you get back.

Issues

On GitHub we use the concept of an issue to record every change needed in our code base. This means ideas, bugs, features, support, even just discussions.

Never hesitate to open an issue if you have question about the code or think you may have found a bug. Sometimes people will find part of the documentation or instructions difficult to follow, let us know if this happens.

In particular for our project on GitHub, we have a template for Bug Reports and Feature Requests with one for Proposals .. proposed. When you click on ‘New Issue’ you will be given a choice of which template to start with, if they do not seem to fit your need there is an option to ‘Open a regular issue’ - which is blank.

GitHub Issue Tracker GitHub Issue Tracker GitHub Issue Template Selection GitHub Issue Template Selection

Forks

In order to keep things a bit tidy in our main repository, we all do work on what is called a fork before creating a pull request. A fork is essentially a copy of a repository that is owned by your GitHub account. You can create as many branches as you like there and don’t be shy with creating commits. We will squash them all into one before we merge, more on that below.

But first take a minute to read this awesome post on creating and maintaining a fork of the project. It even goes into adding other collaborators forks as remotes which you will find useful as you start working more and more with other contributors.

Pull requests

Brian Ketelsen created an awesome video on making your first open source pull request, for an overview of the process go watch that now. There’s also a great video series on contributing to an Open Source project by Kent C. Dodds.

When we receive a new pull request, it may take time for a maintainer or other contributor to get to it, but when we do a few things will happen.

You can expect at least a few comments, don’t let them discourage you though. We are all trying to help one another write the best code and documentation possible, all criticism should be considered constructive.

If you feel like it is not, please do not hesitate to reach out to one of the maintainers. We take our code of conduct very seriously.

Most likely one or more contributors and maintainers will leave a review on your pull request. You can discuss the changes requested in the pull request itself, or if you need help with something in particular you can reach out to us in the #athens channel on Gophers Slack.

After all requested changes are resolved a maintainer will give it a final look and as long as our continuous integration passed they will merge it with the main branch.

Project process

Let’s just go over a quick general guideline on contributing to Athens.

Find an issue

When you see an issue you would like to work on, if no one else has expressed interest please comment on the issue with something like:

  • I will take this
  • I would like to work on this

This let’s other contributors know someone is working on it, we all know free time is hard to get and don’t want anyone wasting theirs.

If you don’t see an issue for your bug or feature, please open one to discuss with the community. Some things may not be in the best interest of the project, or may have already been discussed.

If your issue is something very small, like a typo or broken link, you may skip straight the pull request.

Open a pull request

After you have created a branch on your fork, and made the changes. Please make sure all tests still pass, see DEVELOPMENT.md for details. Then after you push all changes up to your fork, head over to Athens to open a pull request. Usually, right after you have pushed a new branch and you visit the original repository, GitHub will prompt you to open a new pull request. Otherwise you can do so from the Pull Requests tab on the repository.

How To Contribute

Development Guide for Athens

The proxy is written in idiomatic Go and uses standard tools. If you know Go, you’ll be able to read the code and run the server.

Athens uses Go Modules for dependency management. You will need Go v1.12+ to get started on Athens.

See our Contributing Guide for tips on how to submit a pull request when you are ready.

Go version

Athens is developed on Go v1.12+.

To point Athens to a different version of Go set the following environment variable

GO_BINARY_PATH=go1.12.X
# or whichever binary you want to use with athens

Run the Proxy

If you’re inside GOPATH, make sure GO111MODULE=on, if you’re outside GOPATH, then Go Modules are on by default. The main package is inside cmd/proxy and is run like any go project as follows:

cd cmd/proxy
go build
./proxy

After the server starts, you’ll see some console output like:

Starting application at 127.0.0.1:3000

Dependencies

Services that Athens Needs

Athens relies on several services (i.e. databases, etc…) to function properly. We use Docker images to configure and run those services. However, Athens does not require any storage dependencies by default. The default storage is in memory, you can opt-in to using the fs which would also require no dependencies. But if you’d like to test out Athens against a real storage backend (such as MongoDB, Minio, S3 etc), continue reading this section:

If you’re not familiar with Docker, that’s ok. We’ve tried to make it easy to get up and running:

  1. Download and install docker-compose (docker-compose is a tool for easily starting and stopping lots of services at once)
  2. Run make dev from the root of this repository

That’s it! After the make dev command is done, everything will be up and running and you can move on to the next step.

If you want to stop everything at any time, run make down.

Note that make dev only runs the minimum amount of dependencies needed for things to work. If you’d like to run all the possible dependencies run make alldeps or directly the services available in the docker-compose.yml file. Keep in mind, though, that make alldeps does not start up Athens or Oympus, but only their dependencies.

Run unit tests

In order to run unit tests, services they depend on must be running first:

make alldeps

then you can run the unit tests:

make test-unit

Run the docs

To get started with developing the docs we provide a docker image, which runs Hugo to render the docs. Using the docker image, we mount the /docs directory into the container. To get it up and running, from the project root run:

make docs
docker run -it --rm \
        --name hugo-server \
        -p 1313:1313 \
        -v ${PWD}/docs:/src:cached \
        gomods/hugo

Then open http://localhost:1313.

Linting

In our CI/CD pass, we use govet, so feel free to run it locally beforehand:

go vet ./...
Fork me on GitHub