Skip to content

szczygiel-m/allegro-intern-github-stalker

Repository files navigation

Contributors Forks Stargazers Issues LinkedIn


Github stalker - Allegro Intern

The recruitment task number 3 for Allegro Summer e-Xperience 2021.

Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. How To Run
  3. API Documentation
  4. Future Development
  5. License
  6. Contact

About The Project

Server application that allows:

  • listing of repositories (name and number of stargazers)
  • returning the sum of stargazers in all repositories for any GitHub user.

Built With

How To Run

To quickly run local GitHubStalker server follow instructions bellow.

From Terminal

  1. Make sure you have gradle and java version 11 or higher installed.
  2. Download this repository.
  3. Make sure you have configured secrets in file. Instructions below.
  4. Open any terminal in local project directory.
  5. Build project with ./gradlew build.
  6. Run project with ./gradlew bootRun.

From IDE

  1. Clone this repository. You can do this manually or from IDE.
  2. Make sure you have configured secrets in file. Instructions below.
  3. Run project with IDE for example IntelliJ IDEA
  4. Wait until your IDE will index all files then run Gradle build task.
  5. Run project and enjoy.

With Dockerhub

  1. Pull the image from Dockerhub.
  2. Open any terminal.
  3. Pull the image from Dockerhub with:

$ docker pull szczygiel2000/github-stalker-allegro-intern

  1. Run container with:

$ docker run -p 9090:8080 szczygiel2000/github-stalker-allegro-intern

App secrets in file

For not authorized requests GitHub Api permits only 60 requests per hour. Application to work efficiently needs GitHub OAuth secret key, see the Documentation how to get it. In root folder of project update application.yaml file, and paste bellow code with your own values to this file like this.

application:
  github:
    authToken: '*** HERE GOES YOUR GITHUB OAUTH TOKEN ***'
    urlPrefix: 'https://api.github.com/users/'
spring:
  cache:
    jcache:
      config: 'classpath:ehcache.xml'

Api Documentation

Repos Endpoint:

  • GET, path: /repos/{user}

It allows us listing user repos.

Sample Request:

curl -X GET "http://localhost:8080/api/v1/repos/szczygiel2000" -H "accept: */*"

Sample Response:

{
  "user": "szczygiel2000",
  "user_repos": [
    {
      "name": "Balls-Simulator",
      "stargazers_count": 0
    },
    {
      "name": "Numeric_Matrix_Processor",
      "stargazers_count": 0
    },
    {
      "name": "PCBuilderShopApplication---Backend",
      "stargazers_count": 1
    },
    {
      "name": "Snake-Game",
      "stargazers_count": 0
    }
  ]
}

Http Status Code: 200 (OK)

Pagination

This endpoint also allows us to list user repos by page and size of page.

Sample Request with Pagination:

curl -X GET "http://localhost:8080/api/v1/repos/allegro?page=3&per_page=4" -H "accept: */*"

Sample Response:

{
  "user": "allegro",
  "user_repos": [
    {
      "name": "atm-event-app",
      "stargazers_count": 5
    },
    {
      "name": "atm-event-scanner",
      "stargazers_count": 0
    },
    {
      "name": "axion-release-plugin",
      "stargazers_count": 380
    },
    {
      "name": "bigcache",
      "stargazers_count": 4793
    }
  ]
}

With Http Status Code: 200 (OK)

Stargazers Endpoint

  • GET, path: /stargazers/{user}

Returning the sum of stargazers in all repositories for any GitHub user.

Sample Request:

curl -X GET "http://localhost:8080/api/v1/stargazers/szczygiel2000" -H "accept: */*"

Sample Response:

{
  "user": "szczygiel2000",
  "totalStargazers": 1
}

With Http Status Code: 200 (OK)

Another Sample Request:

curl -X GET "http://localhost:8080/api/v1/stargazers/allegro" -H "accept: */*"

Another Sample Response:

{
  "user": "allegro",
  "totalStargazers": 13104
}

With Http Status Code: 200 (OK)

Errors

Not Found

If we try to stalk non-existing user we will get response like this:

{
  "status": "404",
  "message": "User 'notAllegro' not found.",
  "timestamp": "2021-04-25T13:02:45.6842646"
}

With Http Status Code: 404 (NOT_FOUND)

Bad Request

On GitHub the shortest name is 1 character, while the longest - 39. This Api validates provided username and if it does not match return response just like this:

{
  "status": "400",
  "message": "Username must be between 1 and 39 characters. Your is 45.",
  "timestamp": "2021-04-25T13:10:08.0273211"
}

With Http Status Code: 404 (BAD_REQUEST)

Gateway Timeout

If the server waits for a reply from GitHub for more than 5 seconds it will return:

{
  "status": "504",
  "message": "GitHub wasn't responding for too long.",
  "timestamp": "2021-04-25T13:13:06.3558892"
}

With Http Status Code: 504 (GATEWAY_TIMEOUT)

Future Development

  • Improving the quality of tests by mocking GitHub responses. Now tests are sending requests to GitHub Api and can't accurately test is returned values are correct. Now the tests are indicative only. If I had more time, I would certainly implement it.
  • Sending parallel requests to GitHub Api while calculating total users stargazers to prevent long waiting for sum.
  • Add sorting user repos by stargazers.
  • Add some frontend to enable non-tech users to use the application.

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Mateusz Szczygieł - [email protected] - Mail

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published