[
  {
    "path": ".github/workflows/test.yml",
    "content": "name: Node.js CI\n\non:\n  push:\n    branches: [ \"main\" ]\n  pull_request:\n    branches: [ \"main\" ]\n\njobs:\n  test:\n\n    runs-on: ubuntu-latest\n\n    steps:\n    - uses: actions/checkout@v3\n    - name: Setup node\n      uses: actions/setup-node@v3\n      with:\n        cache: 'npm'\n    - run: npm ci\n    - run: GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} SHA=${{github.sha}} npm test\n"
  },
  {
    "path": ".gitignore",
    "content": "# Logs\nlogs\n*.log\nnpm-debug.log*\n\n# Runtime data\npids\n*.pid\n*.seed\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n\n# nyc test coverage\n.nyc_output\n\n# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# node-waf configuration\n.lock-wscript\n\n# Compiled binary addons (http://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directories\nnode_modules\njspm_packages\n\n# Optional npm cache directory\n.npm\n\n# Optional REPL history\n.node_repl_history\n"
  },
  {
    "path": ".travis.yml",
    "content": "dist: trusty\nlanguage: node_js\nnode_js:\n  - \"node\"\n  - \"6\"\ncache:\n  directories:\n    - node_modules\nnotifications:\n  email: false\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2017 Siddharth Kshetrapal\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "<p align=\"center\">\n  <img src=\"https://raw.githubusercontent.com/siddharthkp/github-build/master/art/logo.png\" height=\"100px\"/>\n  <br><br>\n  <b>Github builds/checks for CI</b>\n  <br><br>\n\n</p>\n<p>\n  <img src=\"https://raw.githubusercontent.com/siddharthkp/github-build/master/art/commit.png\" height=\"200px\"/>\n  <br>\n  <img src=\"https://raw.githubusercontent.com/siddharthkp/github-build/master/art/pull_request.png\" height=\"250px\"/>\n</p>\n\n&nbsp;\n\n[![Code Climate](https://lima.codeclimate.com/github/siddharthkp/github-build/badges/gpa.svg)](https://lima.codeclimate.com/github/siddharthkp/github-build)\n[![Known Vulnerabilities](https://snyk.io/test/github/siddharthkp/github-build/badge.svg)](https://snyk.io/test/github/siddharthkp/github-build)\n\n&nbsp;\n\n#### Install\n\n```\nnpm install github-build --save\n```\n\n#### Usage\n\n```js\nconst Build = require('github-build')\n\nconst data = {\n  repo: 'siddharthkp/github-build', // (author/repo)\n  sha: '6954e71d46be1ae9b0529aae6e00b64d7a1023d4', // (commit sha)\n  token: 'secret', // (github oauth token: https://developer.github.com/v3/oauth)\n  label: 'my CI service',\n  description: 'checking some stuff',\n  url: 'http://my-ci-service.com/builds/1', // details url\n}\n\n/* Create a build */\nconst build = new Build(data)\n\n/* When you call start, a pending status get's added on github (returns a promise) */\nbuild.start()\n\n/* Run your tests */\n\n/* If things go well, call pass, it will mark change the status to success ✅ (returns a promise) */\nbuild.pass()\n\n/* Or if the tests fail, mark this build as failed ❌ (returns a promise) */\nbuild.fail()\n\n/* If you could not run the tests because of incorrect config, just error out the build (returns a promise) */\nbuild.error() // use when build errors out (returns a promise)\n\n```\n\n&nbsp;\n\nIf you like it then [you should put a ⭐️ on it](https://www.youtube.com/watch?v=4m1EFMoRFvY)\n\n&nbsp;\n\n#### License\n\nMIT © siddharthkp\n"
  },
  {
    "path": "index.js",
    "content": "const axios = require('axios')\n\nclass Build {\n  constructor(meta) {\n    meta.context = meta.label\n    meta.target_url = meta.url\n    this.meta = meta\n  }\n  start (message, url) {return update(this.meta, message, url, 'pending')}\n  pass  (message, url) {return update(this.meta, message, url, 'success')}\n  fail  (message, url) {return update(this.meta, message, url, 'failure')}\n  error (message, url) {return update(this.meta, message, url, 'error')}\n}\n\nconst update = (build, message, url, status) => new Promise((resolve, reject) => {\n  axios({\n    method: 'POST',\n    url: `https://api.github.com/repos/${build.repo}/statuses/${build.sha}`,\n    responseType: 'json',\n    data: {\n      state: status,\n      target_url: url || build.url,\n      description: message || build.description,\n      context: build.context\n    },\n    headers: {'Authorization': `token ${build.token}`}\n  })\n  .then(({status, data}) => resolve({status, data}))\n  .catch(({response = {status: 500}}) => reject({\n      status: response.status,\n      error: response.data\n    }))\n})\n\nmodule.exports = Build;\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"github-build\",\n  \"version\": \"1.2.4\",\n  \"description\": \"Github builds/checks for CI\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"node test\"\n  },\n  \"keywords\": [\n    \"github\",\n    \"build\",\n    \"checks\",\n    \"ci\"\n  ],\n  \"homepage\": \"https://github.com/siddharthkp/github-build\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/siddharthkp/github-build.git\"\n  },\n  \"author\": \"siddharthkp\",\n  \"license\": \"MIT\",\n  \"dependencies\": {\n    \"axios\": \"1.6.0\"\n  },\n  \"files\": [\n    \"index.js\"\n  ]\n}\n"
  },
  {
    "path": "test.js",
    "content": "const Build = require('./index')\n\nconst data = {\n  repo: 'siddharthkp/github-build',\n  sha: process.env.SHA || process.env.TRAVIS_PULL_REQUEST_SHA || '4391039e9c506a1702ee7971cda4613ca5da2d69',\n  token: process.env.GITHUB_TOKEN,\n  label: 'github-build',\n  description: 'Running some tests'\n}\n\nconst build = new Build(data)\nbuild.start()\nsetTimeout(() => build.pass('Tests passed!', 'https://example.com'), 5000)\n\nprocess.on('unhandledRejection', (reason, p) => {\n  console.log('Unhandled Promise: ')\n  console.log(reason, p)\n  process.exit(1)\n})\n"
  }
]