Repository: siddharthkp/github-build Branch: main Commit: 723b1cce3fef Files: 8 Total size: 6.1 KB Directory structure: gitextract_xr25jwcj/ ├── .github/ │ └── workflows/ │ └── test.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── package.json └── test.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/workflows/test.yml ================================================ name: Node.js CI on: push: branches: [ "main" ] pull_request: branches: [ "main" ] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup node uses: actions/setup-node@v3 with: cache: 'npm' - run: npm ci - run: GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} SHA=${{github.sha}} npm test ================================================ FILE: .gitignore ================================================ # Logs logs *.log npm-debug.log* # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # nyc test coverage .nyc_output # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # node-waf configuration .lock-wscript # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules jspm_packages # Optional npm cache directory .npm # Optional REPL history .node_repl_history ================================================ FILE: .travis.yml ================================================ dist: trusty language: node_js node_js: - "node" - "6" cache: directories: - node_modules notifications: email: false ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2017 Siddharth Kshetrapal Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================



Github builds/checks for CI


  [![Code Climate](https://lima.codeclimate.com/github/siddharthkp/github-build/badges/gpa.svg)](https://lima.codeclimate.com/github/siddharthkp/github-build) [![Known Vulnerabilities](https://snyk.io/test/github/siddharthkp/github-build/badge.svg)](https://snyk.io/test/github/siddharthkp/github-build)   #### Install ``` npm install github-build --save ``` #### Usage ```js const Build = require('github-build') const data = { repo: 'siddharthkp/github-build', // (author/repo) sha: '6954e71d46be1ae9b0529aae6e00b64d7a1023d4', // (commit sha) token: 'secret', // (github oauth token: https://developer.github.com/v3/oauth) label: 'my CI service', description: 'checking some stuff', url: 'http://my-ci-service.com/builds/1', // details url } /* Create a build */ const build = new Build(data) /* When you call start, a pending status get's added on github (returns a promise) */ build.start() /* Run your tests */ /* If things go well, call pass, it will mark change the status to success ✅ (returns a promise) */ build.pass() /* Or if the tests fail, mark this build as failed ❌ (returns a promise) */ build.fail() /* If you could not run the tests because of incorrect config, just error out the build (returns a promise) */ build.error() // use when build errors out (returns a promise) ```   If you like it then [you should put a ⭐️ on it](https://www.youtube.com/watch?v=4m1EFMoRFvY)   #### License MIT © siddharthkp ================================================ FILE: index.js ================================================ const axios = require('axios') class Build { constructor(meta) { meta.context = meta.label meta.target_url = meta.url this.meta = meta } start (message, url) {return update(this.meta, message, url, 'pending')} pass (message, url) {return update(this.meta, message, url, 'success')} fail (message, url) {return update(this.meta, message, url, 'failure')} error (message, url) {return update(this.meta, message, url, 'error')} } const update = (build, message, url, status) => new Promise((resolve, reject) => { axios({ method: 'POST', url: `https://api.github.com/repos/${build.repo}/statuses/${build.sha}`, responseType: 'json', data: { state: status, target_url: url || build.url, description: message || build.description, context: build.context }, headers: {'Authorization': `token ${build.token}`} }) .then(({status, data}) => resolve({status, data})) .catch(({response = {status: 500}}) => reject({ status: response.status, error: response.data })) }) module.exports = Build; ================================================ FILE: package.json ================================================ { "name": "github-build", "version": "1.2.4", "description": "Github builds/checks for CI", "main": "index.js", "scripts": { "test": "node test" }, "keywords": [ "github", "build", "checks", "ci" ], "homepage": "https://github.com/siddharthkp/github-build", "repository": { "type": "git", "url": "git+https://github.com/siddharthkp/github-build.git" }, "author": "siddharthkp", "license": "MIT", "dependencies": { "axios": "1.6.0" }, "files": [ "index.js" ] } ================================================ FILE: test.js ================================================ const Build = require('./index') const data = { repo: 'siddharthkp/github-build', sha: process.env.SHA || process.env.TRAVIS_PULL_REQUEST_SHA || '4391039e9c506a1702ee7971cda4613ca5da2d69', token: process.env.GITHUB_TOKEN, label: 'github-build', description: 'Running some tests' } const build = new Build(data) build.start() setTimeout(() => build.pass('Tests passed!', 'https://example.com'), 5000) process.on('unhandledRejection', (reason, p) => { console.log('Unhandled Promise: ') console.log(reason, p) process.exit(1) })