A simple Golang http service that lists the top Github contributors given a location.
Features included:
- Top contributors by a given location.
- Cached results with a given TTL.
- Number of results customizable (Max 150).
- Sort by the amount of repositories, followers or by the date they joined.
There is a Docker image called smoya/ghtop. In order to run the service, just do:
docker run --publish 8080:8080 smoya/ghtop:latest -gh-token=<github token>Ghtop requires Go 1.9 or later.
go get -u github.com/smoya/ghtopRun the server:
ghtop -gh-token=<github token> -ttl=<ttl in seconds>The GET /top endpoint should be now mounted.
Curl http://localhost:8080/top?location=barcelona in order to see the top dev contributors in Barcelona area.
Replace barcelona with whatever location you want to look at.
curl 'http://localhost:8080/top?location=barcelona'If authentication is required, the application is ready for use Basic HTTP authentication rfc2617. In further versions JWT could be implemented.
In order to prompt the authentication dialog on the /top endpoint, you must specify the user and password when running the service.
| name | type | description | required | default |
|---|---|---|---|---|
| -port | int | Server's listening port | no | 8080 |
| -env | string | Sets the environment. Just for logging. | no | prod |
| -gh-token | string | Github personal access token. Create yours from https://github.com/settings/tokens/new | yes | |
| -ttl | int | The ttl in seconds for the repository cache. | no | 300 |
| -auth-user | string | The username for basic Http Authentication. No Auth if empty | no | |
| -auth-password | string | The password for basic Http Authentication. | no |
Ghtop library tests are split in two:
- Unit tests
- End To End tests (features are located in the e2e pkg)
Run make tests and make e2e respectively, or make check in order to run all of them.
- The code allows us to easy implement a new repository for any other vcs system rather than github.
- The limit has no fixed values but the max is 150 results (avoiding possible performance issues). I considered that adding the possibility to the user to limit the amount of results in each request was better for UX.
- The Github token is set at application level rather than by the user in each request.
This is a design decision since I considered this service as a simple API endpoint for a possible nice frontend application.
However this could be changed handling a given Github token in each
GET /toprequest.
- Repository cache can be improved by checking if the specified limit is lower or equal than the cached one and use that cache.
- We could retrieve more data from Github like user full name, email, organizations, etc.
- Add a multiple repository constructor in order to allow using several repositories (from different vcs) at the same time.
- Add a proper authentication mechanism (JWT for example). This could be done through an in memory database + a simple http middleware.
- Adding more tests.