Initialised from the "basic-ts => Comment on new issues - written in TypeScript" probot general tuto
Composed of different aspects:
- The reception initializes the routes available to communicate with the bot. An http route for Maracas to send the report to the bot and a webhook endpoint for interracting with the repository.
- The handlers organizes the reactions of the bot to the events listed above.
- The interaction with Maracas notify Maracas about the new pull request.
- The checks management contains ll the functions used to create and update checks.
- The parsing reads the json received from maracas and format it into an array of three fields: a title, a summary and a complete list of the breaking changes.
These scripts use authData classes to store the information needed to authenticate to github and identify the current pull request.
AuthData: an abstract class
This class stores the informations about the pull request and contains methods to authenticate to github or complete the missing informations. Implemented in two different subclasses, depending on how they were initialized.
-
webhookDatas: initialized from a webhook, which contains a lot of information, including an already initialized octokit
-
reportDatas: initialized with little informations, to publish Maracas' report.
- Self-authentication: Instead of connecting with Probot.auth (seen here) we use octokit identification as described here to connect again to the repositry whenever necessary. For general informations on authentication for github apps, click here.
-
Webhooks: Nothing fancy, using the regular expressions from here to receive notifications form github. For details on events names, see here
-
Router: Using express and the default router in probot to receive request form Maracas Api once the job ends (push mode)
This script is called by a handler after a new check is requested: It notifies maracas that a new report is needed, create a new check on the pull request and updates it with the maracas response: if everything is ok, it confirm that maracas is processing the request, else it displays the error message in the check summary.
Tutorials:
Rq: Probot seems to choose its listenning port correctly for heroku
Also, heroku (in local) only works with the secret key read from file with fs in synchronous mode.Since this method doesn't work with a normal deployement on heroku, we use the sercet key in .env instead.
The tests are base on jest, and the http requests are mocked with nock.
# run the tests locally
npm test
All variables used during tests are stored in the globalVars class. This includes:
- URLs
- environment variables
- git variables
The json files used to mock different messages from github and maracas are stored in the fixture folder
The examples of generated reports (in three parts since the reports are displayed as a Title, a summary and a text), are located in the reports folder.
/!\ Even though the summary and the text support markdown, the title is only saved as a markdown file for practicity and doesn't support markdown on github.