Skip to content

Repository files navigation

Project Summary

  • Popularity API for getting the popularity of github repo.
  • Popular GitHub repository means the one with many forks and stars.
  • To use Github Rest Api the Github Personal Access Token is needed.

Project Assumptions

  • App is using PERSONAL_ACCESS_TOKEN available for github users.
  • PERSONAL_ACCESS_TOKEN is valid and working. Be sure it is available in env where the app is running.
  • Project is based on Rest Github Api/ GitHub's official REST API https://docs.github.com/en/rest .
  • Service is only for authenticated users. There is TokenAuthentication and SessionAuthentication.
  • Speed of service depends on speed of Github Api. It is changing during day. It is about 0.5s - 1s.
  • Maximum amount of Github Api requests is 5000/hour for 1 token. Service would not work after the limit is reached.
  • The api is communicating live with Github Api. No caching for common calls.
  • Name of saved github repo should be in Github format to easy identify it: github_user/repo_name e.g. facebook/react

Project Technologies

  • Python 3.7
  • Django 3
  • Django Rest Framework
  • Github Rest Api
  • Django openapi swagger
  • Docker
  • Docker Compose
  • Requests

How to use Service

1. build the service locally

  • use Python 3.7
  • pip install -r requirements.txt
  • python manage.py makemigrations
  • python manage.py migrate
  • export PERSONAL_ACCESS_TOKEN=""
  • python manage.py runserver 8000
  • python manage.py createsuperuser
  • login in /admin
  • check http://127.0.0.1:8000/health_check/ if service is working. If not - probably no valid token was granted.
  • navigate to /doc in browser to use swagger
  • navigate to /api/v1/ in browser to use Django Rest Framework UI
  • create new valid repo by POST in /api/v1/repos/ e.g. name="facebook/react"
  • Get /api/v1/repos/<created_model_id>/popular/ to get popularity score

1. build the service in local docker

  • based on python:3.7 image
  • add valid PERSONAL ACCESS TOKEN to ".env_file" environment file
  • docker-compose up #this would download python:3.7 if there is no image yet
  • docker-compose run web python manage.py createsuperuser
  • login as superuser in /admin
  • navigate to /doc/ to use swagger
  • navigate to /api/v1/ in browser to use Django Rest Framework UI
  • create new valid repo by POST in /api/v1/repos/ e.g. name="facebook/react"
  • Get /api/v1/repos/<created_model_id>/popular/ to get popularity score

Automatic tests

local

  • python manage.py test

docker

  • docker-compose run web python manage.py test

Info about Personal Access Token

Basic auth checks:

Register a new user:
Create authtoken for user
  • python manage.py drf_create_token djoser
  • Generated token 62c20951d9f30234719a6a3e117ece3b4ff57df6 for user djoser {"auth_token": "e80988aed847782fcca766cfdd220ea82fae0649"}
  • #for docker: docker-compose run web python manage.py drf_create_token djoser
Use authtoken for Api usage:

Use swagger to traverse UI:

  • navigate to /doc/
  • login as earlier prepared user
  • use the swagger UI to play with api.

Simple usage of popularity Api:

Be sure the PERSONAL_ACCESS_TOKEN is available as an env variable on running machine

Future Improvements

  • PyGithub Library could be used for Rest Github Api (not used due to project restrictions to use REST Github Api) https://pygithub.readthedocs.io/en/latest/apis.html
  • Communication with Github Api done in faster service. As for now only 0.5s -> 2s speed is reached.
  • Caching/Storing the most common requests to Github Api. As for now the api is live. As for speed of change of
  • Users could send their github tokens. Not only 1 global instance used.
  • Possible another endpoint to save new personal token for users.
  • Users could use api by sending repo links and their personal tokens.
  • Add new paths for 'accounts/* urls to be compatible with Swagger Docs buttons.
  • Use faster db. As for now sqlite is used.
  • Better documentation for swagger
  • As for now App is DEBUG=True mode. It is in development. Remove DEBUG=True to fasten up speed of service.

About

Api to check Popularity rankings in Github

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages