Service for managing comments on GitHub
Go to file
Jakub Sokołowski 600d748236
remove usage of babel, replace import with require
Signed-off-by: Jakub Sokołowski <jakub@status.im>
2018-12-27 14:11:07 +01:00
src remove usage of babel, replace import with require 2018-12-27 14:11:07 +01:00
test remove usage of babel, replace import with require 2018-12-27 14:11:07 +01:00
.gitignore ignore yarn.lock 2018-12-13 23:16:17 +01:00
Dockerfile use loglevel module for logging 2018-12-20 22:17:13 +01:00
LICENSE add MIT license 2018-12-22 12:04:50 +01:00
README.md remove unnecessary empty row 2018-12-23 01:17:56 +01:00
gulpfile.js remove usage of babel, replace import with require 2018-12-27 14:11:07 +01:00
package.json remove usage of babel, replace import with require 2018-12-27 14:11:07 +01:00

README.md

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


Jenkins Builds

Commit #️⃣ Finished (UTC) Duration Platform Result
a088572b #3 2018-12-21 12:12:55 ~12 min android 📄 build log
a088572b #3 2018-12-21 12:13:18 ~12 min android 📄 build log
✔️ a088572b #3 2018-12-21 12:13:53 ~12 min ios 📦 package
✔️ a088572b #3 2018-12-21 12:13:34 ~12 min ios 📦 package
✔️ a088572b #3 2018-12-21 12:14:44 ~12 min ios 📦 package

API

It exposes just 1 call:

  • 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.
  • POST /comments - Show currently managed comments in PRs.

By default it listens on localhost:8080.

Usage

$ cat << EOF
{
  "id": 1, "commit": "7367f3d5", "success": true, "platform": "linux", "duration": "~15 min",
  "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

$ curl -s -XPOST http://localhost:8000/builds/7123 -d@/tmp/body.json -H 'Content-Type: application/json'
{ "status": "ok" }

$ curl -s -XPOST http://localhost:8000/builds/7123/refresh
{ "status": "ok" }

You can also check all PRs the application knows about:

$ curl -s http://localhost:8000/comments
{
  "count": 2,
  "comments": [
    { "pr": "7000", "comment_id": 446940840 },
    { "pr": "7084", "comment_id": 446779864 }
  ]
}

Configuration

There are few environment variables you can set:

  • LISTEN_PORT - Self explanatory. (Default: 8000)
  • DB_SAVE_INTERVAL - How often database is written to disk. (Default: 5000)
  • DB_PATH - Path where the LokiJS DB file is stored. (Default: /tmp/builds.db)
  • 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.

Building

  • 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.