2018-12-12 15:02:22 +00:00
# Description
This is a minimal REST API intended for use with a Continuous Integration system for managing comments on GitHub.
The problem this solves is posting comments in a PR from multiple builds without spamming the comment section. Instead we post just one comment with a table and continue to update it.
# Example Comment
---
2018-12-12 15:04:46 +00:00
### Jenkins Builds
2018-12-22 11:07:01 +00:00
| :grey_question: | Commit | :hash: | Finished (UTC) | Duration | Platform | Result |
2018-12-13 13:50:03 +00:00
|-|-|-|-|-|-|-|
2018-12-22 11:07:01 +00:00
| :x: | a088572b | [#3 ](https://google.pl ) | 2018-12-21 12:12:55 | ~12 min | `android` | [:page_facing_up: build log ](https://google.plconsoleText ) |
| :x: | a088572b | [#3 ](https://google.pl ) | 2018-12-21 12:13:18 | ~12 min | `android` | [:page_facing_up: build log ](https://google.plconsoleText ) |
| :heavy_check_mark: | a088572b | [#3 ](https://google.pl ) | 2018-12-21 12:13:53 | ~12 min | `ios` | [:package: package ](https://google.pl ) |
| :heavy_check_mark: | a088572b | [#3 ](https://google.pl ) | 2018-12-21 12:13:34 | ~12 min | `ios` | [:package: package ](https://google.pl ) |
| :heavy_check_mark: | a088572b | [#3 ](https://google.pl ) | 2018-12-21 12:14:44 | ~12 min | `ios` | [:package: package ](https://google.pl ) |
2018-12-12 15:02:22 +00:00
---
# API
It exposes just 1 call:
2018-12-22 10:58:38 +00:00
* `POST /builds/:id` - Add a new build result and update the PR comment.
* `POST /builds/:id/refresh` - Re-render the PR comment for given ID.
2018-12-13 13:50:03 +00:00
* `POST /comments` - Show currently managed comments in PRs.
2018-12-12 15:02:22 +00:00
By default it listens on `localhost:8080` .
2018-12-18 10:47:19 +00:00
# Usage
```
$ cat < < EOF
{
2018-12-22 10:58:38 +00:00
"id": 1, "commit": "7367f3d5", "success": true, "platform": "linux", "duration": "~15 min",
2018-12-18 10:47:19 +00:00
"url": "https://ci.status.im/job/status-react/job/prs/job/linux/job/PR-7123/1/",
"pkg_url": "https://status-im-prs.ams3.digitaloceanspaces.com/StatusIm-181212-211210-5157d2-pr.AppImage"
}
EOF >> /tmp/body/json
2018-12-22 14:21:37 +00:00
$ curl -s -XPOST http://localhost:8000/builds/7123 -d@/tmp/body.json -H 'Content-Type: application/json'
2018-12-22 10:58:38 +00:00
{ "status": "ok" }
2018-12-22 14:21:37 +00:00
$ curl -s -XPOST http://localhost:8000/builds/7123/refresh
2018-12-22 10:58:38 +00:00
{ "status": "ok" }
2018-12-18 10:47:19 +00:00
```
You can also check all PRs the application knows about:
```
$ curl -s http://localhost:8000/comments
{
"count": 2,
"comments": [
2018-12-22 10:58:38 +00:00
{ "pr": "7000", "comment_id": 446940840 },
{ "pr": "7084", "comment_id": 446779864 }
2018-12-18 10:47:19 +00:00
]
}
```
2018-12-12 15:02:22 +00:00
# Configuration
There are few environment variables you can set:
2018-12-22 11:02:06 +00:00
* `LISTEN_PORT` - Self explanatory. (Default: `8000` )
* `DB_SAVE_INTERVAL` - How often database is written to disk. (Default: `5000` )
* `DB_PATH` - Path where the [LokiJS ](http://lokijs.org/#/ ) DB file is stored. (Default: `/tmp/builds.db` )
2018-12-22 11:01:02 +00:00
* `GH_TOKEN` - Required for GitHub API access.
* `GH_REPO_OWNER` - Name of owner of repo to manage.
* `GH_REPO_NAME` - Name of GitHub repo to manage.
2018-12-12 15:02:22 +00:00
2018-12-18 10:47:19 +00:00
# Building
2018-12-12 15:02:22 +00:00
2018-12-22 10:57:02 +00:00
* `yarn run start` - For production use.
* `yarn run devel` - For development use.
* `yarn run default` - For building use.
* `yarn run release` - To create and push the docker image use.