Skip to content

Infraspeak/pie-api

Repository files navigation

pie-api

PIE Intro

This is a service that belongs to a bigger project (PIE). PIE's objective is to return all issues from repositories present on a composer.json or a package.json file. The idea came in Hactoberfest 2020, when the team wanted to contribute to the packages we are using, but there was no easy way to list them all. PIE project is composed by 5 projects:

Resume

This service receives a composer.json or a package.json via the API and injects it into the respective Redis queue. It will listen on another Redis queue for issues and send them to Pusher to be displayed by the frontend.

Project Setup

The following commands assume you have .direnv installed and authorized. Check how to do it here

docker-compose build
composer install
cp .env.example .env
php artisan key:generate

Add your Pusher key and secret to variables PUSHER_APP_* in your .env file.

Project Run

docker-compose up or with -d flag to run in detached mode and on another terminal php artisan redis:subscribe:issues

How it works

An endpoint is exposed in POST /API/files expecting a composer.json or a package.json file and a unique identifier (UUID). Depending on the received file, the endpoint will inject the file content in one of two Redis queues, COMPOSER_FILE for composer.json and NPM_FILE for package.json ex:

{
   "headers": {
      // uuid identifier
   },
   "payload": {
      // composer.json or package.json file content
   }
}

Both queues are being listened to by other services that will process them. The UUID will also be propagated, as it identifies the Pusher WebSocket that should receive the parsed files later on.

A command, php artisan redis:subscribe:issues will be listening to the ISSUES Redis queue that should receive messages in the following format:

{
   "headers":{
      // uuid identifier
   },
   "payload":{
      "repo":{
         "name":"vendor/package",
         "url":"repo url"
      },
      "issues":[
         {
            "url":"",
            "title":"",
            "description":"",
            "author":"",
            "status":"open/closed",
            "tags":[
               "hacktoberfest"
            ],
            "id":"",
            "date_opened":""
         }
      ]
   }
}

A command, php artisan redis:subscribe:errors will be listening to the APP_ERRORS Redis queue that should receive messages with errors in the following format:

{
   "headers":{
      // uuid identifier
   },
   "payload":{
      "errors": [
         {
            "code":"",
            "description":""
         }
      ]
   }
}