contributors/

directory
v0.0.0-...-9fa2476 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2025 License: Apache-2.0

README

GitHub Client Exercise

Create a project folder in your $GOPATH outside of this repository. A good place would be $GOPATH/src/github.com/yourname/contributors where yourname is your GitHub username.

Part 1: Just Get it Working

Create a program which can call the GitHub API to get a list of contributors for the golang/go repository.

A template file is included to get you started.

Part 2: Refactoring

  • Refactor your GitHub API client to a type called Client with a method Contributors.
  • Move your client code from package main to another package like package github.
  • Create a function in package main that uses the client. func printContributors(repo string, c *github.Client) int
  • Decouple the printContributors function to depend on an interface instead of the concrete type.

Part 3: Testing

  • Add tests for printContributors. Create a mock version of the github client and pass that in. To capture the output you can change the printContributors function to accept an io.Writer where it should print results.
  • Add tests for the github package using net/http/httptest.NewServer.

Just for Fun

  • Add flags to the main package for specifying the repo to pull. Use the flag package.
  • Add a flag to the main package to specify an output file name then encode the results to that file in CSV format. Use the encoding/csv package.
  • Create a web app that accepts a repo name then shows the contributor list for that repo

Directories

Path Synopsis
Call the GitHub API to get a list of repository contributors.
Call the GitHub API to get a list of repository contributors.
Call the GitHub API to get a list of repository contributors.
Call the GitHub API to get a list of repository contributors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL