The recruitment task number 3 for Allegro Summer e-Xperience 2021.
Report Bug
·
Request Feature
Server application that allows:
- listing of repositories (name and number of stargazers)
- returning the sum of stargazers in all repositories for any GitHub user.
To quickly run local GitHubStalker server follow instructions bellow.
- Make sure you have gradle and java version 11 or higher installed.
- Download this repository.
- Make sure you have configured secrets in file. Instructions below.
- Open any terminal in local project directory.
- Build project with
./gradlew build
. - Run project with
./gradlew bootRun
.
- Clone this repository. You can do this manually or from IDE.
- Make sure you have configured secrets in file. Instructions below.
- Run project with IDE for example IntelliJ IDEA
- Wait until your IDE will index all files then run Gradle build task.
- Run project and enjoy.
- Pull the image from Dockerhub.
- Open any terminal.
- Pull the image from Dockerhub with:
$ docker pull szczygiel2000/github-stalker-allegro-intern
- Run container with:
$ docker run -p 9090:8080 szczygiel2000/github-stalker-allegro-intern
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'
- 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)
- 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)
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)
- 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.
Distributed under the MIT License. See LICENSE.txt
for more information.
Mateusz Szczygieł - [email protected] - Mail