├── .env.example ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── docs └── deploy.md ├── index.js ├── lib └── analysis.js ├── package.json └── test ├── analysis.test.js ├── fixtures ├── check_run.rerequested.json └── check_suite.requested.json └── index.test.js /.env.example: -------------------------------------------------------------------------------- 1 | # The ID of your GitHub App 2 | APP_ID= 3 | WEBHOOK_SECRET=development 4 | 5 | # Use `trace` to get verbose logging or `info` to show less 6 | LOG_LEVEL=debug 7 | 8 | # Go to https://smee.io/new set this to the URL that you are redirected to. 9 | # WEBHOOK_PROXY_URL= 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | *.pem 4 | .env 5 | package-lock.json 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - "8.3" 5 | notifications: 6 | disabled: true 7 | script: 8 | - $(npm bin)/jest 9 | after_script: 10 | - $(npm bin)/jest --coverage --coverageReporters=text-lcov | coveralls 11 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at stevewinton@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | [fork]: /fork 4 | [pr]: /compare 5 | [style]: https://standardjs.com/ 6 | [code-of-conduct]: CODE_OF_CONDUCT.md 7 | 8 | Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. 9 | 10 | Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms. 11 | 12 | ## Submitting a pull request 13 | 14 | 1. [Fork][fork] and clone the repository 15 | 1. Configure and install the dependencies: `npm install` 16 | 1. Make sure the tests pass on your machine: `npm test`, note: these tests also apply the linter, so no need to lint seperately 17 | 1. Create a new branch: `git checkout -b my-branch-name` 18 | 1. Make your change, add tests, and make sure the tests still pass 19 | 1. Push to your fork and [submit a pull request][pr] 20 | 1. Pat your self on the back and wait for your pull request to be reviewed and merged. 21 | 22 | Here are a few things you can do that will increase the likelihood of your pull request being accepted: 23 | 24 | - Follow the [style guide][style] which is using standard. Any linting errors should be shown when running `npm test` 25 | - Write and update tests. 26 | - Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests. 27 | - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). 28 | 29 | Work in Progress pull request are also welcome to get feedback early on, or if there is something blocked you. 30 | 31 | ## Resources 32 | 33 | - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) 34 | - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) 35 | - [GitHub Help](https://help.github.com) 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2018, Steve Winton (https://github.com/apps/linter-alex) 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # linter-alex 2 | 3 | [![build status](https://travis-ci.org/swinton/linter-alex.svg?branch=master)](https://travis-ci.org/swinton/linter-alex) [![coverage status](https://coveralls.io/repos/github/swinton/linter-alex/badge.svg?branch=master)](https://coveralls.io/github/swinton/linter-alex?branch=master) [![Greenkeeper badge](https://badges.greenkeeper.io/swinton/linter-alex.svg)](https://greenkeeper.io/) 4 | 5 | > a GitHub App built with [probot](https://github.com/probot/probot) combining [Alex](http://alexjs.com/) with GitHub's [(beta) Checks API](https://developer.github.com/changes/2018-05-07-new-checks-api-public-beta/) to ensure **sensitive, considerate writing before you merge your Pull Requests**. 6 | 7 | ### Looking for an example? 8 | 9 | [**Here you go**](https://github.com/swinton/example/runs/449335)! :eyes: 10 | 11 | ## Installation 12 | 13 | Want to try it out? :sparkles: :cool: :sparkles: You can install the app directly from [**this page**](https://github.com/apps/linter-alex). 14 | 15 | See [docs/deploy.md](docs/deploy.md) if you would like to run your own instance of this app. 16 | 17 | ## Limitations 18 | 19 | Currently, [trees](https://git-scm.com/book/en/v1/Git-Internals-Git-Objects#Tree-Objects) are fetched recursively for analysis via [this API](https://developer.github.com/v3/git/trees/#get-a-tree-recursively), which has a hard limit of 100,000 _entries_, where each entry is either a _blob_ object or a further _sub-tree_ object. If your repo has more entries than this, only the first 100,000 entries will be reachable by linter-alex. 20 | 21 | ## Feedback? 22 | 23 | Please [**open an issue**](https://github.com/swinton/linter-alex/issues/new) :bow: 24 | -------------------------------------------------------------------------------- /docs/deploy.md: -------------------------------------------------------------------------------- 1 | # Deploying 2 | 3 | If you would like to run your own instance of this app, see the [docs for deployment](https://probot.github.io/docs/deployment/). 4 | 5 | This app requires these **Permissions & events** for the GitHub App: 6 | 7 | > **TODO**: List permissions required for deployment here. See [probot/stale](https://github.com/probot/stale/blob/master/docs/deploy.md) for an example. 8 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const mediaType = 'application/vnd.github.antiope-preview+json' 2 | const headers = {headers: {accept: mediaType}} 3 | const analyzeTree = require('./lib/analysis') 4 | 5 | module.exports = (robot) => { 6 | robot.on('check_run', async context => { 7 | const {action, check_run} = context.payload 8 | const {owner, repo} = context.repo() 9 | const {head_sha: sha} = check_run 10 | 11 | return handler({context, action, owner, repo, sha}) 12 | }) 13 | 14 | robot.on('check_suite', async context => { 15 | const {action, check_suite} = context.payload 16 | const {owner, repo} = context.repo() 17 | const {head_sha: sha} = check_suite 18 | 19 | return handler({context, action, owner, repo, sha}) 20 | }) 21 | } 22 | 23 | const handler = async ({context, action, owner, repo, sha}) => { 24 | context.log.trace(`action is "${action}".`) 25 | context.log.trace(`repo is "${owner}/${repo}".`) 26 | context.log.trace(`sha is "${sha}".`) 27 | 28 | if (['requested', 'rerequested'].includes(action)) { 29 | context.log.trace('creating in_progress check run...') 30 | 31 | let url = `https://api.github.com/repos/${owner}/${repo}/check-runs` 32 | let result = await context.github.request(Object.assign({ 33 | method: 'POST', 34 | url: url, 35 | name: 'feedback', 36 | head_sha: sha, 37 | status: 'in_progress', 38 | started_at: (new Date()).toISOString() 39 | }, headers)) 40 | 41 | const {data: {id: check_run_id, url: check_run_url}} = result 42 | context.log.trace('result is %j.', result) 43 | context.log.trace(`check_run_id is ${check_run_id}.`) 44 | context.log.trace(`check_run_url is ${check_run_url}.`) 45 | 46 | // Process all .md files in this repo 47 | const annotations = (await analyzeTree(context, owner, repo, sha)) 48 | .filter(annotation => annotation.length > 0) 49 | .reduce((accumulator, currentValue) => accumulator.concat(currentValue), []) 50 | const count = annotations.length 51 | context.log.trace('annotations (%d) are %j', count, annotations) 52 | 53 | // Provide feedback 54 | // https://developer.github.com/v3/checks/runs/#update-a-check-run 55 | // PATCH /repos/:owner/:repo/check-runs/:check_run_id 56 | 57 | // Send annotations in batches of (up to) 50 58 | while (annotations.length > 0) { 59 | let batch = annotations.splice(0, 50) 60 | context.log.info(`sending batch of ${batch.length}`) 61 | result = await context.github.request(Object.assign({ 62 | method: 'PATCH', 63 | url: check_run_url, 64 | output: { 65 | title: 'analysis', 66 | summary: `Alex found ${count} issue${count === 1 ? '' : 's'}`, 67 | annotations: batch 68 | } 69 | }, headers)) 70 | context.log.trace('result is %j', result) 71 | } 72 | 73 | // Complete the check run 74 | result = await context.github.request(Object.assign({ 75 | method: 'PATCH', 76 | url: check_run_url, 77 | status: 'completed', 78 | conclusion: count > 0 ? 'neutral' : 'success', 79 | completed_at: (new Date()).toISOString() 80 | }, headers)) 81 | context.log.trace('result is %j', result) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /lib/analysis.js: -------------------------------------------------------------------------------- 1 | const alex = require('alex') 2 | 3 | async function processBlob(context, owner, repo, tree_sha, filename, file_sha) { 4 | const {data: {content: encoded}} = await context.github.gitdata.getBlob({owner, repo, sha: file_sha}) 5 | const decoded = Buffer.from(encoded, 'base64').toString() 6 | context.log(`Blob (${file_sha}) for https://github.com/${owner}/${repo}/blob/${tree_sha}/${filename} is: %j`, decoded) 7 | 8 | const analysis = alex.markdown(decoded).messages.map(message => { 9 | const {message: description, ruleId: title, location} = message 10 | return { 11 | path: filename, // The path to the file being annotated. 12 | start_line: location.start.line, // The start line of the annotation. 13 | end_line: location.end.line, // The end line of the annotation. 14 | annotation_level: 'notice', // The level of the annotation. Can be one of notice, warning, or failure. 15 | message: description, // A short description of the feedback for these lines of code. The maximum size is 64 KB. 16 | title: title // The title that represents the annotation. The maximum size is 255 characters. 17 | } 18 | }) 19 | 20 | return analysis 21 | } 22 | 23 | async function analyzeTree(context, owner, repo, tree_sha) { 24 | // Get tree, recursively 25 | const {data: {tree}} = await context.github.gitdata.getTree({owner, repo, sha: tree_sha, recursive: 1}) 26 | context.log('Tree: %j', tree) 27 | 28 | // Filter tree, only blobs ending in '.md' 29 | const blobs = tree.filter(path => { 30 | const {path: filename, type} = path 31 | return type === 'blob' && filename.endsWith('.md') 32 | }); 33 | context.log('Filtered tree: %j', blobs) 34 | 35 | // Process each blob 36 | return Promise.all(blobs.map(blob => { 37 | const {path: filename, sha: file_sha} = blob 38 | return processBlob(context, owner, repo, tree_sha, filename, file_sha) 39 | })) 40 | } 41 | 42 | module.exports = analyzeTree 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "linter-alex", 3 | "version": "1.0.0", 4 | "description": "", 5 | "author": "Steve Winton (https://github.com/apps/linter-alex)", 6 | "license": "ISC", 7 | "repository": "https://github.com/swinton/linter-alex.git", 8 | "scripts": { 9 | "dev": "nodemon --exec \"npm start\"", 10 | "start": "probot run ./index.js", 11 | "lint": "standard --fix", 12 | "test": "jest --coverage", 13 | "test:watch": "jest --watch --notify --notifyMode=change --coverage", 14 | "simulate-suite": "LOG_LEVEL=TRACE node_modules/.bin/probot simulate check_suite ./test/fixtures/check_suite.requested.json ./index.js", 15 | "simulate-run": "LOG_LEVEL=TRACE node_modules/.bin/probot simulate check_run ./test/fixtures/check_run.rerequested.json ./index.js" 16 | }, 17 | "dependencies": { 18 | "alex": "^6.0.0", 19 | "probot": "^7.1.0" 20 | }, 21 | "devDependencies": { 22 | "@octokit/rest": "15.11.1", 23 | "coveralls": "^3.0.2", 24 | "jest": "^23.0.0", 25 | "nodemon": "^1.17.4", 26 | "smee-client": "^1.0.1", 27 | "standard": "^12.0.1" 28 | }, 29 | "engines": { 30 | "node": ">= 8.3.0" 31 | }, 32 | "standard": { 33 | "env": [ 34 | "jest" 35 | ] 36 | }, 37 | "jest": { 38 | "testEnvironment": "node", 39 | "collectCoverageFrom": [ 40 | "index.js", 41 | "lib/*.js" 42 | ], 43 | "coverageThreshold": { 44 | "global": { 45 | "branches": 80, 46 | "functions": 80, 47 | "lines": 80, 48 | "statements": 80 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/analysis.test.js: -------------------------------------------------------------------------------- 1 | // jest.mock('alex') 2 | // const alex = require('alex') 3 | const analyzeTree = require('../lib/analysis') 4 | 5 | describe('analyzeTree', () => { 6 | let context 7 | 8 | beforeEach(() => { 9 | context = { 10 | github: { 11 | gitdata: { 12 | getTree: jest.fn().mockResolvedValue({ 13 | data: { 14 | sha: "9875bf915c118e6369a610770288cf7f0a415124", 15 | url: "https://api.github.com/repos/wintron/example/git/trees/9875bf915c118e6369a610770288cf7f0a415124", 16 | tree: [ 17 | { 18 | path: "README.md", 19 | mode: "100644", 20 | type: "blob", 21 | sha: "43fbdc5368d7729a3cf70743cecc50e790ca51d0", 22 | size: 47, 23 | url: "https://api.github.com/repos/wintron/example/git/blobs/43fbdc5368d7729a3cf70743cecc50e790ca51d0" 24 | }, 25 | { 26 | path: "CONTRIBUTING.md", 27 | mode: "100644", 28 | type: "blob", 29 | sha: "54fbdc5368d7729a3cf70743cecc50e790ca51d0", 30 | size: 47, 31 | url: "https://api.github.com/repos/wintron/example/git/blobs/43fbdc5368d7729a3cf70743cecc50e790ca51d0" 32 | } 33 | ], 34 | truncated: false 35 | } 36 | }), 37 | getBlob: jest.fn() 38 | } 39 | }, 40 | log: jest.fn().mockImplementation(mesg => mesg) 41 | // log: console.log 42 | } 43 | 44 | // alex.mockImplementation({ 45 | // markdown: jest.fn().mockReturnValue({ 46 | // messages: [] 47 | // }) 48 | // }) 49 | }) 50 | 51 | afterEach(() => { 52 | // alex.mockClear() 53 | }) 54 | 55 | it("returns an empty array for each file", async () => { 56 | context.github.gitdata.getBlob.mockResolvedValueOnce({ 57 | data: { 58 | sha: "43fbdc5368d7729a3cf70743cecc50e790ca51d0", 59 | node_id: "MDQ6QmxvYjY5NjAxNjMxOjQzZmJkYzUzNjhkNzcyOWEzY2Y3MDc0M2NlY2M1MGU3OTBjYTUxZDA=", 60 | size: 47, 61 | url: "https://api.github.com/repos/wintron/example/git/blobs/43fbdc5368d7729a3cf70743cecc50e790ca51d0", 62 | content: "aGVsbG8gd29ybGQ=", 63 | encoding: "base64" 64 | } 65 | }) 66 | context.github.gitdata.getBlob.mockResolvedValueOnce({ 67 | data: { 68 | sha: "54fbdc5368d7729a3cf70743cecc50e790ca51d0", 69 | node_id: "NEQ6QmxvYjY5NjAxNjMxOjQzZmJkYzUzNjhkNzcyOWEzY2Y3MDc0M2NlY2M1MGU3OTBjYTUxZDA=", 70 | size: 47, 71 | url: "https://api.github.com/repos/wintron/example/git/blobs/54fbdc5368d7729a3cf70743cecc50e790ca51d0", 72 | content: "aGVsbG8gd29ybGQ=", 73 | encoding: "base64" 74 | } 75 | }) 76 | 77 | const analysis = await analyzeTree(context, "wintron", "example", "9875bf915c118e6369a610770288cf7f0a415124") 78 | 79 | expect(context.github.gitdata.getTree).toHaveBeenCalledTimes(1) 80 | expect(context.github.gitdata.getTree).toHaveBeenCalledWith({ 81 | owner: "wintron", 82 | repo: "example", 83 | sha: "9875bf915c118e6369a610770288cf7f0a415124", 84 | recursive: 1 85 | }) 86 | expect(context.github.gitdata.getBlob).toHaveBeenCalledTimes(2) 87 | expect(context.github.gitdata.getBlob).toHaveBeenNthCalledWith(1, { 88 | owner: "wintron", repo: "example", sha: "43fbdc5368d7729a3cf70743cecc50e790ca51d0" 89 | }) 90 | expect(context.github.gitdata.getBlob).toHaveBeenNthCalledWith(2, { 91 | owner: "wintron", repo: "example", sha: "54fbdc5368d7729a3cf70743cecc50e790ca51d0" 92 | }) 93 | expect(analysis).toEqual([[], []]) 94 | }) 95 | 96 | it("returns an array of messages for each file", async () => { 97 | context.github.gitdata.getBlob.mockResolvedValueOnce({ 98 | data: { 99 | sha: "43fbdc5368d7729a3cf70743cecc50e790ca51d0", 100 | node_id: "MDQ6QmxvYjY5NjAxNjMxOjQzZmJkYzUzNjhkNzcyOWEzY2Y3MDc0M2NlY2M1MGU3OTBjYTUxZDA=", 101 | size: 57, 102 | url: "https://api.github.com/repos/wintron/example/git/blobs/43fbdc5368d7729a3cf70743cecc50e790ca51d0", 103 | content: "dGhlIHNlcnZlcnMgd2VyZSBkZXBsb3llZCBpbiBhIG1hc3Rlci9zbGF2ZSBjb25maWd1cmF0aW9u", 104 | encoding: "base64" 105 | } 106 | }) 107 | context.github.gitdata.getBlob.mockResolvedValueOnce({ 108 | data: { 109 | sha: "54fbdc5368d7729a3cf70743cecc50e790ca51d0", 110 | node_id: "NEQ6QmxvYjY5NjAxNjMxOjQzZmJkYzUzNjhkNzcyOWEzY2Y3MDc0M2NlY2M1MGU3OTBjYTUxZDA=", 111 | size: 31, 112 | url: "https://api.github.com/repos/wintron/example/git/blobs/54fbdc5368d7729a3cf70743cecc50e790ca51d0", 113 | content: "c29ycnkgZm9yIGJlaW5nIHN1Y2ggYSBqYWNrYXNz", 114 | encoding: "base64" 115 | } 116 | }) 117 | 118 | const analysis = await analyzeTree(context, "wintron", "example", "9875bf915c118e6369a610770288cf7f0a415124") 119 | 120 | expect(context.github.gitdata.getTree).toHaveBeenCalledTimes(1) 121 | expect(context.github.gitdata.getTree).toHaveBeenCalledWith({ 122 | owner: "wintron", 123 | repo: "example", 124 | sha: "9875bf915c118e6369a610770288cf7f0a415124", 125 | recursive: 1 126 | }) 127 | expect(context.github.gitdata.getBlob).toHaveBeenCalledTimes(2) 128 | expect(context.github.gitdata.getBlob).toHaveBeenNthCalledWith(1, { 129 | owner: "wintron", repo: "example", sha: "43fbdc5368d7729a3cf70743cecc50e790ca51d0" 130 | }) 131 | expect(context.github.gitdata.getBlob).toHaveBeenNthCalledWith(2, { 132 | owner: "wintron", repo: "example", sha: "54fbdc5368d7729a3cf70743cecc50e790ca51d0" 133 | }) 134 | expect(analysis).toEqual([ 135 | [{ 136 | end_line: 1, 137 | path: "README.md", 138 | message: "`master` / `slave` may be insensitive, use `primary` / `replica` instead", 139 | start_line: 1, 140 | title: "master-slave", 141 | annotation_level: "notice" 142 | }, { 143 | end_line: 1, 144 | path: "README.md", 145 | message: "Don’t use “slave”, it’s profane", 146 | start_line: 1, 147 | title: "slave", 148 | annotation_level: "notice" 149 | }], 150 | [{ 151 | end_line: 1, 152 | path: "CONTRIBUTING.md", 153 | message: "Don’t use “jackass”, it’s profane", 154 | start_line: 1, 155 | title: "jackass", 156 | annotation_level: "notice" 157 | }] 158 | ]) 159 | }) 160 | }) 161 | -------------------------------------------------------------------------------- /test/fixtures/check_run.rerequested.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "rerequested", 3 | "check_run": { 4 | "id": 1528004, 5 | "head_sha": "8e86089c36bbc8018af737312e756b8c2777ef50", 6 | "external_id": "", 7 | "url": "https://api.github.com/repos/wintron/example/check-runs/1528004", 8 | "html_url": "https://github.com/wintron/example/runs/1528004", 9 | "status": "completed", 10 | "conclusion": "success", 11 | "started_at": "2018-05-23T22:34:25Z", 12 | "completed_at": "2018-05-23T22:34:27Z", 13 | "output": { 14 | "title": null, 15 | "summary": null, 16 | "text": null, 17 | "annotations_count": 0, 18 | "annotations_url": "https://api.github.com/repos/wintron/example/check-runs/1528004/annotations" 19 | }, 20 | "name": "feedback", 21 | "check_suite": { 22 | "id": 1089302, 23 | "head_branch": "example", 24 | "head_sha": "8e86089c36bbc8018af737312e756b8c2777ef50", 25 | "status": "completed", 26 | "conclusion": "success", 27 | "url": "https://api.github.com/repos/wintron/example/check-suites/1089302", 28 | "before": "0000000000000000000000000000000000000000", 29 | "after": "8e86089c36bbc8018af737312e756b8c2777ef50", 30 | "pull_requests": [ 31 | { 32 | "url": "https://api.github.com/repos/wintron/example/pulls/5", 33 | "id": 190123676, 34 | "number": 5, 35 | "head": { 36 | "ref": "example", 37 | "sha": "8e86089c36bbc8018af737312e756b8c2777ef50", 38 | "repo": { 39 | "id": 69601631, 40 | "url": "https://api.github.com/repos/wintron/example", 41 | "name": "example" 42 | } 43 | }, 44 | "base": { 45 | "ref": "master", 46 | "sha": "b4b57afa9532dab453ddea850c0006d346dad800", 47 | "repo": { 48 | "id": 69601631, 49 | "url": "https://api.github.com/repos/wintron/example", 50 | "name": "example" 51 | } 52 | } 53 | } 54 | ], 55 | "app": { 56 | "id": 12603, 57 | "owner": { 58 | "login": "swinton", 59 | "id": 27806, 60 | "avatar_url": "https://avatars2.githubusercontent.com/u/27806?v=4", 61 | "gravatar_id": "", 62 | "url": "https://api.github.com/users/swinton", 63 | "html_url": "https://github.com/swinton", 64 | "followers_url": "https://api.github.com/users/swinton/followers", 65 | "following_url": "https://api.github.com/users/swinton/following{/other_user}", 66 | "gists_url": "https://api.github.com/users/swinton/gists{/gist_id}", 67 | "starred_url": "https://api.github.com/users/swinton/starred{/owner}{/repo}", 68 | "subscriptions_url": "https://api.github.com/users/swinton/subscriptions", 69 | "organizations_url": "https://api.github.com/users/swinton/orgs", 70 | "repos_url": "https://api.github.com/users/swinton/repos", 71 | "events_url": "https://api.github.com/users/swinton/events{/privacy}", 72 | "received_events_url": "https://api.github.com/users/swinton/received_events", 73 | "type": "User", 74 | "site_admin": true 75 | }, 76 | "name": "linter-alex-development", 77 | "description": "Ensure sensitive, considerate writing before you merge your Pull Requests.", 78 | "external_url": "https://github.com/swinton/linter-alex#development", 79 | "html_url": "https://github.com/apps/linter-alex-development", 80 | "created_at": 1527114543, 81 | "updated_at": 1527114573 82 | }, 83 | "created_at": "2018-05-23T22:32:31Z", 84 | "updated_at": "2018-05-23T22:34:28Z" 85 | }, 86 | "app": { 87 | "id": 12603, 88 | "owner": { 89 | "login": "swinton", 90 | "id": 27806, 91 | "avatar_url": "https://avatars2.githubusercontent.com/u/27806?v=4", 92 | "gravatar_id": "", 93 | "url": "https://api.github.com/users/swinton", 94 | "html_url": "https://github.com/swinton", 95 | "followers_url": "https://api.github.com/users/swinton/followers", 96 | "following_url": "https://api.github.com/users/swinton/following{/other_user}", 97 | "gists_url": "https://api.github.com/users/swinton/gists{/gist_id}", 98 | "starred_url": "https://api.github.com/users/swinton/starred{/owner}{/repo}", 99 | "subscriptions_url": "https://api.github.com/users/swinton/subscriptions", 100 | "organizations_url": "https://api.github.com/users/swinton/orgs", 101 | "repos_url": "https://api.github.com/users/swinton/repos", 102 | "events_url": "https://api.github.com/users/swinton/events{/privacy}", 103 | "received_events_url": "https://api.github.com/users/swinton/received_events", 104 | "type": "User", 105 | "site_admin": true 106 | }, 107 | "name": "linter-alex-development", 108 | "description": "Ensure sensitive, considerate writing before you merge your Pull Requests.", 109 | "external_url": "https://github.com/swinton/linter-alex#development", 110 | "html_url": "https://github.com/apps/linter-alex-development", 111 | "created_at": 1527114543, 112 | "updated_at": 1527114573 113 | }, 114 | "pull_requests": [ 115 | { 116 | "url": "https://api.github.com/repos/wintron/example/pulls/5", 117 | "id": 190123676, 118 | "number": 5, 119 | "head": { 120 | "ref": "example", 121 | "sha": "8e86089c36bbc8018af737312e756b8c2777ef50", 122 | "repo": { 123 | "id": 69601631, 124 | "url": "https://api.github.com/repos/wintron/example", 125 | "name": "example" 126 | } 127 | }, 128 | "base": { 129 | "ref": "master", 130 | "sha": "b4b57afa9532dab453ddea850c0006d346dad800", 131 | "repo": { 132 | "id": 69601631, 133 | "url": "https://api.github.com/repos/wintron/example", 134 | "name": "example" 135 | } 136 | } 137 | } 138 | ] 139 | }, 140 | "repository": { 141 | "id": 69601631, 142 | "name": "example", 143 | "full_name": "wintron/example", 144 | "owner": { 145 | "login": "wintron", 146 | "id": 18087678, 147 | "avatar_url": "https://avatars0.githubusercontent.com/u/18087678?v=4", 148 | "gravatar_id": "", 149 | "url": "https://api.github.com/users/wintron", 150 | "html_url": "https://github.com/wintron", 151 | "followers_url": "https://api.github.com/users/wintron/followers", 152 | "following_url": "https://api.github.com/users/wintron/following{/other_user}", 153 | "gists_url": "https://api.github.com/users/wintron/gists{/gist_id}", 154 | "starred_url": "https://api.github.com/users/wintron/starred{/owner}{/repo}", 155 | "subscriptions_url": "https://api.github.com/users/wintron/subscriptions", 156 | "organizations_url": "https://api.github.com/users/wintron/orgs", 157 | "repos_url": "https://api.github.com/users/wintron/repos", 158 | "events_url": "https://api.github.com/users/wintron/events{/privacy}", 159 | "received_events_url": "https://api.github.com/users/wintron/received_events", 160 | "type": "Organization", 161 | "site_admin": false 162 | }, 163 | "private": true, 164 | "html_url": "https://github.com/wintron/example", 165 | "description": "Example", 166 | "fork": false, 167 | "url": "https://api.github.com/repos/wintron/example", 168 | "forks_url": "https://api.github.com/repos/wintron/example/forks", 169 | "keys_url": "https://api.github.com/repos/wintron/example/keys{/key_id}", 170 | "collaborators_url": "https://api.github.com/repos/wintron/example/collaborators{/collaborator}", 171 | "teams_url": "https://api.github.com/repos/wintron/example/teams", 172 | "hooks_url": "https://api.github.com/repos/wintron/example/hooks", 173 | "issue_events_url": "https://api.github.com/repos/wintron/example/issues/events{/number}", 174 | "events_url": "https://api.github.com/repos/wintron/example/events", 175 | "assignees_url": "https://api.github.com/repos/wintron/example/assignees{/user}", 176 | "branches_url": "https://api.github.com/repos/wintron/example/branches{/branch}", 177 | "tags_url": "https://api.github.com/repos/wintron/example/tags", 178 | "blobs_url": "https://api.github.com/repos/wintron/example/git/blobs{/sha}", 179 | "git_tags_url": "https://api.github.com/repos/wintron/example/git/tags{/sha}", 180 | "git_refs_url": "https://api.github.com/repos/wintron/example/git/refs{/sha}", 181 | "trees_url": "https://api.github.com/repos/wintron/example/git/trees{/sha}", 182 | "statuses_url": "https://api.github.com/repos/wintron/example/statuses/{sha}", 183 | "languages_url": "https://api.github.com/repos/wintron/example/languages", 184 | "stargazers_url": "https://api.github.com/repos/wintron/example/stargazers", 185 | "contributors_url": "https://api.github.com/repos/wintron/example/contributors", 186 | "subscribers_url": "https://api.github.com/repos/wintron/example/subscribers", 187 | "subscription_url": "https://api.github.com/repos/wintron/example/subscription", 188 | "commits_url": "https://api.github.com/repos/wintron/example/commits{/sha}", 189 | "git_commits_url": "https://api.github.com/repos/wintron/example/git/commits{/sha}", 190 | "comments_url": "https://api.github.com/repos/wintron/example/comments{/number}", 191 | "issue_comment_url": "https://api.github.com/repos/wintron/example/issues/comments{/number}", 192 | "contents_url": "https://api.github.com/repos/wintron/example/contents/{+path}", 193 | "compare_url": "https://api.github.com/repos/wintron/example/compare/{base}...{head}", 194 | "merges_url": "https://api.github.com/repos/wintron/example/merges", 195 | "archive_url": "https://api.github.com/repos/wintron/example/{archive_format}{/ref}", 196 | "downloads_url": "https://api.github.com/repos/wintron/example/downloads", 197 | "issues_url": "https://api.github.com/repos/wintron/example/issues{/number}", 198 | "pulls_url": "https://api.github.com/repos/wintron/example/pulls{/number}", 199 | "milestones_url": "https://api.github.com/repos/wintron/example/milestones{/number}", 200 | "notifications_url": "https://api.github.com/repos/wintron/example/notifications{?since,all,participating}", 201 | "labels_url": "https://api.github.com/repos/wintron/example/labels{/name}", 202 | "releases_url": "https://api.github.com/repos/wintron/example/releases{/id}", 203 | "deployments_url": "https://api.github.com/repos/wintron/example/deployments", 204 | "created_at": "2016-09-29T19:41:57Z", 205 | "updated_at": "2016-09-29T19:43:45Z", 206 | "pushed_at": "2018-05-23T22:33:30Z", 207 | "git_url": "git://github.com/wintron/example.git", 208 | "ssh_url": "git@github.com:wintron/example.git", 209 | "clone_url": "https://github.com/wintron/example.git", 210 | "svn_url": "https://github.com/wintron/example", 211 | "homepage": null, 212 | "size": 1, 213 | "stargazers_count": 0, 214 | "watchers_count": 0, 215 | "language": null, 216 | "has_issues": true, 217 | "has_projects": true, 218 | "has_downloads": true, 219 | "has_wiki": true, 220 | "has_pages": false, 221 | "forks_count": 0, 222 | "mirror_url": null, 223 | "archived": false, 224 | "open_issues_count": 4, 225 | "license": null, 226 | "forks": 0, 227 | "open_issues": 4, 228 | "watchers": 0, 229 | "default_branch": "master" 230 | }, 231 | "organization": { 232 | "login": "wintron", 233 | "id": 18087678, 234 | "url": "https://api.github.com/orgs/wintron", 235 | "repos_url": "https://api.github.com/orgs/wintron/repos", 236 | "events_url": "https://api.github.com/orgs/wintron/events", 237 | "hooks_url": "https://api.github.com/orgs/wintron/hooks", 238 | "issues_url": "https://api.github.com/orgs/wintron/issues", 239 | "members_url": "https://api.github.com/orgs/wintron/members{/member}", 240 | "public_members_url": "https://api.github.com/orgs/wintron/public_members{/member}", 241 | "avatar_url": "https://avatars0.githubusercontent.com/u/18087678?v=4", 242 | "description": null 243 | }, 244 | "sender": { 245 | "login": "swinton", 246 | "id": 27806, 247 | "avatar_url": "https://avatars2.githubusercontent.com/u/27806?v=4", 248 | "gravatar_id": "", 249 | "url": "https://api.github.com/users/swinton", 250 | "html_url": "https://github.com/swinton", 251 | "followers_url": "https://api.github.com/users/swinton/followers", 252 | "following_url": "https://api.github.com/users/swinton/following{/other_user}", 253 | "gists_url": "https://api.github.com/users/swinton/gists{/gist_id}", 254 | "starred_url": "https://api.github.com/users/swinton/starred{/owner}{/repo}", 255 | "subscriptions_url": "https://api.github.com/users/swinton/subscriptions", 256 | "organizations_url": "https://api.github.com/users/swinton/orgs", 257 | "repos_url": "https://api.github.com/users/swinton/repos", 258 | "events_url": "https://api.github.com/users/swinton/events{/privacy}", 259 | "received_events_url": "https://api.github.com/users/swinton/received_events", 260 | "type": "User", 261 | "site_admin": true 262 | }, 263 | "installation": { 264 | "id": 189366 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /test/fixtures/check_suite.requested.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": "requested", 3 | "check_suite": { 4 | "id": 1088593, 5 | "head_branch": "example", 6 | "head_sha": "9875bf915c118e6369a610770288cf7f0a415124", 7 | "status": "queued", 8 | "conclusion": null, 9 | "url": "https://api.github.com/repos/wintron/example/check-suites/1088593", 10 | "before": "2d9f412e781f67a3610bb56d360706b9c983f33d", 11 | "after": "9875bf915c118e6369a610770288cf7f0a415124", 12 | "pull_requests": [ 13 | { 14 | "url": "https://api.github.com/repos/wintron/example/pulls/4", 15 | "id": 190118105, 16 | "number": 4, 17 | "head": { 18 | "ref": "example", 19 | "sha": "9875bf915c118e6369a610770288cf7f0a415124", 20 | "repo": { 21 | "id": 69601631, 22 | "url": "https://api.github.com/repos/wintron/example", 23 | "name": "example" 24 | } 25 | }, 26 | "base": { 27 | "ref": "master", 28 | "sha": "b4b57afa9532dab453ddea850c0006d346dad800", 29 | "repo": { 30 | "id": 69601631, 31 | "url": "https://api.github.com/repos/wintron/example", 32 | "name": "example" 33 | } 34 | } 35 | } 36 | ], 37 | "app": { 38 | "id": 11319, 39 | "owner": { 40 | "login": "swinton", 41 | "id": 27806, 42 | "avatar_url": "https://avatars2.githubusercontent.com/u/27806?v=4", 43 | "gravatar_id": "", 44 | "url": "https://api.github.com/users/swinton", 45 | "html_url": "https://github.com/swinton", 46 | "followers_url": "https://api.github.com/users/swinton/followers", 47 | "following_url": "https://api.github.com/users/swinton/following{/other_user}", 48 | "gists_url": "https://api.github.com/users/swinton/gists{/gist_id}", 49 | "starred_url": "https://api.github.com/users/swinton/starred{/owner}{/repo}", 50 | "subscriptions_url": "https://api.github.com/users/swinton/subscriptions", 51 | "organizations_url": "https://api.github.com/users/swinton/orgs", 52 | "repos_url": "https://api.github.com/users/swinton/repos", 53 | "events_url": "https://api.github.com/users/swinton/events{/privacy}", 54 | "received_events_url": "https://api.github.com/users/swinton/received_events", 55 | "type": "User", 56 | "site_admin": true 57 | }, 58 | "name": "linter-alex", 59 | "description": "Ensure sensitive, considerate writing before you merge your Pull Requests.", 60 | "external_url": "https://github.com/swinton/linter-alex", 61 | "html_url": "https://github.com/apps/linter-alex", 62 | "created_at": 1524256403, 63 | "updated_at": 1526078858 64 | }, 65 | "created_at": "2018-05-23T22:21:27Z", 66 | "updated_at": "2018-05-23T22:21:27Z", 67 | "unique_check_runs_count": 0, 68 | "check_runs_url": "https://api.github.com/repos/wintron/example/check-suites/1088593/check-runs", 69 | "head_commit": { 70 | "id": "9875bf915c118e6369a610770288cf7f0a415124", 71 | "tree_id": "651dc4444c0ed3e7dcf5b1c7d7a2ad66110dd77c", 72 | "message": "Update the nice blockquote", 73 | "timestamp": "2018-05-23T17:21:25-05:00", 74 | "author": { 75 | "name": "Steve Winton", 76 | "email": "swinton@users.noreply.github.com" 77 | }, 78 | "committer": { 79 | "name": "GitHub", 80 | "email": "noreply@github.com" 81 | } 82 | } 83 | }, 84 | "repository": { 85 | "id": 69601631, 86 | "name": "example", 87 | "full_name": "wintron/example", 88 | "owner": { 89 | "login": "wintron", 90 | "id": 18087678, 91 | "avatar_url": "https://avatars0.githubusercontent.com/u/18087678?v=4", 92 | "gravatar_id": "", 93 | "url": "https://api.github.com/users/wintron", 94 | "html_url": "https://github.com/wintron", 95 | "followers_url": "https://api.github.com/users/wintron/followers", 96 | "following_url": "https://api.github.com/users/wintron/following{/other_user}", 97 | "gists_url": "https://api.github.com/users/wintron/gists{/gist_id}", 98 | "starred_url": "https://api.github.com/users/wintron/starred{/owner}{/repo}", 99 | "subscriptions_url": "https://api.github.com/users/wintron/subscriptions", 100 | "organizations_url": "https://api.github.com/users/wintron/orgs", 101 | "repos_url": "https://api.github.com/users/wintron/repos", 102 | "events_url": "https://api.github.com/users/wintron/events{/privacy}", 103 | "received_events_url": "https://api.github.com/users/wintron/received_events", 104 | "type": "Organization", 105 | "site_admin": false 106 | }, 107 | "private": true, 108 | "html_url": "https://github.com/wintron/example", 109 | "description": "Example", 110 | "fork": false, 111 | "url": "https://api.github.com/repos/wintron/example", 112 | "forks_url": "https://api.github.com/repos/wintron/example/forks", 113 | "keys_url": "https://api.github.com/repos/wintron/example/keys{/key_id}", 114 | "collaborators_url": "https://api.github.com/repos/wintron/example/collaborators{/collaborator}", 115 | "teams_url": "https://api.github.com/repos/wintron/example/teams", 116 | "hooks_url": "https://api.github.com/repos/wintron/example/hooks", 117 | "issue_events_url": "https://api.github.com/repos/wintron/example/issues/events{/number}", 118 | "events_url": "https://api.github.com/repos/wintron/example/events", 119 | "assignees_url": "https://api.github.com/repos/wintron/example/assignees{/user}", 120 | "branches_url": "https://api.github.com/repos/wintron/example/branches{/branch}", 121 | "tags_url": "https://api.github.com/repos/wintron/example/tags", 122 | "blobs_url": "https://api.github.com/repos/wintron/example/git/blobs{/sha}", 123 | "git_tags_url": "https://api.github.com/repos/wintron/example/git/tags{/sha}", 124 | "git_refs_url": "https://api.github.com/repos/wintron/example/git/refs{/sha}", 125 | "trees_url": "https://api.github.com/repos/wintron/example/git/trees{/sha}", 126 | "statuses_url": "https://api.github.com/repos/wintron/example/statuses/{sha}", 127 | "languages_url": "https://api.github.com/repos/wintron/example/languages", 128 | "stargazers_url": "https://api.github.com/repos/wintron/example/stargazers", 129 | "contributors_url": "https://api.github.com/repos/wintron/example/contributors", 130 | "subscribers_url": "https://api.github.com/repos/wintron/example/subscribers", 131 | "subscription_url": "https://api.github.com/repos/wintron/example/subscription", 132 | "commits_url": "https://api.github.com/repos/wintron/example/commits{/sha}", 133 | "git_commits_url": "https://api.github.com/repos/wintron/example/git/commits{/sha}", 134 | "comments_url": "https://api.github.com/repos/wintron/example/comments{/number}", 135 | "issue_comment_url": "https://api.github.com/repos/wintron/example/issues/comments{/number}", 136 | "contents_url": "https://api.github.com/repos/wintron/example/contents/{+path}", 137 | "compare_url": "https://api.github.com/repos/wintron/example/compare/{base}...{head}", 138 | "merges_url": "https://api.github.com/repos/wintron/example/merges", 139 | "archive_url": "https://api.github.com/repos/wintron/example/{archive_format}{/ref}", 140 | "downloads_url": "https://api.github.com/repos/wintron/example/downloads", 141 | "issues_url": "https://api.github.com/repos/wintron/example/issues{/number}", 142 | "pulls_url": "https://api.github.com/repos/wintron/example/pulls{/number}", 143 | "milestones_url": "https://api.github.com/repos/wintron/example/milestones{/number}", 144 | "notifications_url": "https://api.github.com/repos/wintron/example/notifications{?since,all,participating}", 145 | "labels_url": "https://api.github.com/repos/wintron/example/labels{/name}", 146 | "releases_url": "https://api.github.com/repos/wintron/example/releases{/id}", 147 | "deployments_url": "https://api.github.com/repos/wintron/example/deployments", 148 | "created_at": "2016-09-29T19:41:57Z", 149 | "updated_at": "2016-09-29T19:43:45Z", 150 | "pushed_at": "2018-05-23T22:21:27Z", 151 | "git_url": "git://github.com/wintron/example.git", 152 | "ssh_url": "git@github.com:wintron/example.git", 153 | "clone_url": "https://github.com/wintron/example.git", 154 | "svn_url": "https://github.com/wintron/example", 155 | "homepage": null, 156 | "size": 1, 157 | "stargazers_count": 0, 158 | "watchers_count": 0, 159 | "language": null, 160 | "has_issues": true, 161 | "has_projects": true, 162 | "has_downloads": true, 163 | "has_wiki": true, 164 | "has_pages": false, 165 | "forks_count": 0, 166 | "mirror_url": null, 167 | "archived": false, 168 | "open_issues_count": 4, 169 | "license": null, 170 | "forks": 0, 171 | "open_issues": 4, 172 | "watchers": 0, 173 | "default_branch": "master" 174 | }, 175 | "organization": { 176 | "login": "wintron", 177 | "id": 18087678, 178 | "url": "https://api.github.com/orgs/wintron", 179 | "repos_url": "https://api.github.com/orgs/wintron/repos", 180 | "events_url": "https://api.github.com/orgs/wintron/events", 181 | "hooks_url": "https://api.github.com/orgs/wintron/hooks", 182 | "issues_url": "https://api.github.com/orgs/wintron/issues", 183 | "members_url": "https://api.github.com/orgs/wintron/members{/member}", 184 | "public_members_url": "https://api.github.com/orgs/wintron/public_members{/member}", 185 | "avatar_url": "https://avatars0.githubusercontent.com/u/18087678?v=4", 186 | "description": null 187 | }, 188 | "sender": { 189 | "login": "swinton", 190 | "id": 27806, 191 | "avatar_url": "https://avatars2.githubusercontent.com/u/27806?v=4", 192 | "gravatar_id": "", 193 | "url": "https://api.github.com/users/swinton", 194 | "html_url": "https://github.com/swinton", 195 | "followers_url": "https://api.github.com/users/swinton/followers", 196 | "following_url": "https://api.github.com/users/swinton/following{/other_user}", 197 | "gists_url": "https://api.github.com/users/swinton/gists{/gist_id}", 198 | "starred_url": "https://api.github.com/users/swinton/starred{/owner}{/repo}", 199 | "subscriptions_url": "https://api.github.com/users/swinton/subscriptions", 200 | "organizations_url": "https://api.github.com/users/swinton/orgs", 201 | "repos_url": "https://api.github.com/users/swinton/repos", 202 | "events_url": "https://api.github.com/users/swinton/events{/privacy}", 203 | "received_events_url": "https://api.github.com/users/swinton/received_events", 204 | "type": "User", 205 | "site_admin": true 206 | }, 207 | "installation": { 208 | "id": 189366 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | const { Application } = require('probot') 2 | const myProbotApp = require('..') 3 | const checkSuitePayload = require('./fixtures/check_suite.requested') 4 | const checkRunPayload = require('./fixtures/check_run.rerequested') 5 | const myDate = new Date(Date.UTC(2018, 0, 1)) 6 | const RealDate = Date 7 | 8 | // Mock out the analysis implementation for these tests 9 | // https://jestjs.io/docs/en/mock-functions#mock-implementations 10 | jest.mock('../lib/analysis.js') 11 | const analyzeTree = require('../lib/analysis') 12 | 13 | describe('index', () => { 14 | let app 15 | let event 16 | let github 17 | 18 | beforeEach(() => { 19 | global.Date = jest.fn( 20 | (...props) => 21 | props.length 22 | ? new RealDate(...props) 23 | : new RealDate(myDate) 24 | ) 25 | Object.assign(Date, RealDate) 26 | 27 | // Define event 28 | event = {name: 'check_suite', payload: checkSuitePayload} 29 | 30 | // Create app instance 31 | app = new Application() 32 | 33 | // Initialize app with probot application 34 | app.load(myProbotApp) 35 | 36 | // Mock out the GitHub API 37 | github = {} 38 | github.request = jest 39 | .fn() 40 | .mockResolvedValue({data: {id: 42, url: "https://api.github.com/repos/wintron/example/check-runs/42"}}) 41 | 42 | // Pass mocked out GitHub API into our app instance 43 | app.auth = () => Promise.resolve(github) 44 | }) 45 | 46 | afterEach(() => { 47 | global.Date = RealDate 48 | analyzeTree.mockClear() 49 | }) 50 | 51 | it('handles no annotations', async () => { 52 | analyzeTree.mockResolvedValue([]) 53 | 54 | await app.receive(event) 55 | 56 | expect(github.request).toHaveBeenCalledTimes(2) 57 | expect(github.request).toHaveBeenNthCalledWith(1, { 58 | headers: { 59 | 'accept': 'application/vnd.github.antiope-preview+json' 60 | }, 61 | method: 'POST', 62 | url: 'https://api.github.com/repos/wintron/example/check-runs', 63 | name: 'feedback', 64 | head_sha: '9875bf915c118e6369a610770288cf7f0a415124', 65 | status: 'in_progress', 66 | started_at: '2018-01-01T00:00:00.000Z' 67 | }) 68 | expect(github.request).toHaveBeenNthCalledWith(2, { 69 | headers: { 70 | 'accept': 'application/vnd.github.antiope-preview+json' 71 | }, 72 | method: 'PATCH', 73 | url: 'https://api.github.com/repos/wintron/example/check-runs/42', 74 | status: 'completed', 75 | conclusion: 'success', 76 | completed_at: '2018-01-01T00:00:00.000Z' 77 | }) 78 | 79 | expect(analyzeTree).toHaveBeenCalledTimes(1) 80 | expect(analyzeTree.mock.calls[0][0]).toBeDefined() 81 | expect(analyzeTree.mock.calls[0][1]).toBe('wintron') 82 | expect(analyzeTree.mock.calls[0][2]).toBe('example') 83 | expect(analyzeTree.mock.calls[0][3]).toBe('9875bf915c118e6369a610770288cf7f0a415124') 84 | }) 85 | 86 | it('handles a single annotation', async () => { 87 | analyzeTree.mockResolvedValue([ 88 | [{ 89 | filename: 'FILENAME.md', 90 | blob_href: 'https://github.com/wintron/example/blob/ref/FILENAME.md', 91 | start_line: 1, 92 | end_line: 1, 93 | warning_level: 'notice', 94 | message: 'message', 95 | title: 'title' 96 | }] 97 | ]) 98 | 99 | await app.receive(event) 100 | 101 | expect(github.request).toHaveBeenCalledTimes(3) 102 | expect(github.request).toHaveBeenNthCalledWith(1, { 103 | headers: { 104 | 'accept': 'application/vnd.github.antiope-preview+json' 105 | }, 106 | method: 'POST', 107 | url: 'https://api.github.com/repos/wintron/example/check-runs', 108 | name: 'feedback', 109 | head_sha: '9875bf915c118e6369a610770288cf7f0a415124', 110 | status: 'in_progress', 111 | started_at: '2018-01-01T00:00:00.000Z' 112 | }) 113 | expect(github.request).toHaveBeenNthCalledWith(2, { 114 | headers: { 115 | 'accept': 'application/vnd.github.antiope-preview+json' 116 | }, 117 | method: 'PATCH', 118 | url: 'https://api.github.com/repos/wintron/example/check-runs/42', 119 | output: { 120 | summary: 'Alex found 1 issue', 121 | title: 'analysis', 122 | annotations: [{ 123 | blob_href: 'https://github.com/wintron/example/blob/ref/FILENAME.md', 124 | start_line: 1, 125 | end_line: 1, 126 | filename: 'FILENAME.md', 127 | message: 'message', 128 | title: 'title', 129 | warning_level: 'notice', 130 | }] 131 | } 132 | }) 133 | expect(github.request).toHaveBeenNthCalledWith(3, { 134 | headers: { 135 | 'accept': 'application/vnd.github.antiope-preview+json' 136 | }, 137 | method: 'PATCH', 138 | url: 'https://api.github.com/repos/wintron/example/check-runs/42', 139 | status: 'completed', 140 | conclusion: 'neutral', 141 | completed_at: '2018-01-01T00:00:00.000Z' 142 | }) 143 | 144 | expect(analyzeTree).toHaveBeenCalledTimes(1) 145 | }) 146 | 147 | it('handles multiple annotations from the same file', async () => { 148 | analyzeTree.mockResolvedValue([ 149 | [{ 150 | filename: 'FILENAME.md', 151 | blob_href: 'https://github.com/wintron/example/blob/ref/FILENAME.md', 152 | start_line: 1, 153 | end_line: 1, 154 | warning_level: 'notice', 155 | message: 'message', 156 | title: 'title' 157 | }, { 158 | filename: 'FILENAME.md', 159 | blob_href: 'https://github.com/wintron/example/blob/ref/FILENAME.md', 160 | start_line: 2, 161 | end_line: 2, 162 | warning_level: 'notice', 163 | message: 'message', 164 | title: 'title' 165 | }] 166 | ]) 167 | 168 | await app.receive(event) 169 | 170 | expect(github.request).toHaveBeenCalledTimes(3) 171 | expect(github.request).toHaveBeenNthCalledWith(1, { 172 | headers: { 173 | 'accept': 'application/vnd.github.antiope-preview+json' 174 | }, 175 | method: 'POST', 176 | url: 'https://api.github.com/repos/wintron/example/check-runs', 177 | name: 'feedback', 178 | head_sha: '9875bf915c118e6369a610770288cf7f0a415124', 179 | status: 'in_progress', 180 | started_at: '2018-01-01T00:00:00.000Z' 181 | }) 182 | expect(github.request).toHaveBeenNthCalledWith(2, { 183 | headers: { 184 | 'accept': 'application/vnd.github.antiope-preview+json' 185 | }, 186 | method: 'PATCH', 187 | url: 'https://api.github.com/repos/wintron/example/check-runs/42', 188 | output: { 189 | summary: 'Alex found 2 issues', 190 | title: 'analysis', 191 | annotations: [{ 192 | blob_href: 'https://github.com/wintron/example/blob/ref/FILENAME.md', 193 | start_line: 1, 194 | end_line: 1, 195 | filename: 'FILENAME.md', 196 | message: 'message', 197 | title: 'title', 198 | warning_level: 'notice', 199 | }, { 200 | blob_href: 'https://github.com/wintron/example/blob/ref/FILENAME.md', 201 | start_line: 2, 202 | end_line: 2, 203 | filename: 'FILENAME.md', 204 | message: 'message', 205 | title: 'title', 206 | warning_level: 'notice', 207 | }] 208 | } 209 | }) 210 | expect(github.request).toHaveBeenNthCalledWith(3, { 211 | headers: { 212 | 'accept': 'application/vnd.github.antiope-preview+json' 213 | }, 214 | method: 'PATCH', 215 | url: 'https://api.github.com/repos/wintron/example/check-runs/42', 216 | status: 'completed', 217 | conclusion: 'neutral', 218 | completed_at: '2018-01-01T00:00:00.000Z' 219 | }) 220 | 221 | expect(analyzeTree).toHaveBeenCalledTimes(1) 222 | }) 223 | 224 | it('handles multiple annotations across different file', async () => { 225 | analyzeTree.mockResolvedValue([ 226 | [{ 227 | filename: 'FIRST.md', 228 | blob_href: 'https://github.com/wintron/example/blob/ref/FIRST.md', 229 | start_line: 1, 230 | end_line: 1, 231 | warning_level: 'notice', 232 | message: 'message', 233 | title: 'title' 234 | }], 235 | [{ 236 | filename: 'SECOND.md', 237 | blob_href: 'https://github.com/wintron/example/blob/ref/SECOND.md', 238 | start_line: 1, 239 | end_line: 1, 240 | warning_level: 'notice', 241 | message: 'message', 242 | title: 'title' 243 | }] 244 | ]) 245 | 246 | await app.receive(event) 247 | 248 | expect(github.request).toHaveBeenCalledTimes(3) 249 | expect(github.request).toHaveBeenNthCalledWith(1, { 250 | headers: { 251 | 'accept': 'application/vnd.github.antiope-preview+json' 252 | }, 253 | method: 'POST', 254 | url: 'https://api.github.com/repos/wintron/example/check-runs', 255 | name: 'feedback', 256 | head_sha: '9875bf915c118e6369a610770288cf7f0a415124', 257 | status: 'in_progress', 258 | started_at: '2018-01-01T00:00:00.000Z' 259 | }) 260 | expect(github.request).toHaveBeenNthCalledWith(2, { 261 | headers: { 262 | 'accept': 'application/vnd.github.antiope-preview+json' 263 | }, 264 | method: 'PATCH', 265 | url: 'https://api.github.com/repos/wintron/example/check-runs/42', 266 | output: { 267 | summary: 'Alex found 2 issues', 268 | title: 'analysis', 269 | annotations: [{ 270 | blob_href: 'https://github.com/wintron/example/blob/ref/FIRST.md', 271 | start_line: 1, 272 | end_line: 1, 273 | filename: 'FIRST.md', 274 | message: 'message', 275 | title: 'title', 276 | warning_level: 'notice', 277 | }, { 278 | blob_href: 'https://github.com/wintron/example/blob/ref/SECOND.md', 279 | start_line: 1, 280 | end_line: 1, 281 | filename: 'SECOND.md', 282 | message: 'message', 283 | title: 'title', 284 | warning_level: 'notice', 285 | }] 286 | } 287 | }) 288 | expect(github.request).toHaveBeenNthCalledWith(3, { 289 | headers: { 290 | 'accept': 'application/vnd.github.antiope-preview+json' 291 | }, 292 | method: 'PATCH', 293 | url: 'https://api.github.com/repos/wintron/example/check-runs/42', 294 | status: 'completed', 295 | conclusion: 'neutral', 296 | completed_at: '2018-01-01T00:00:00.000Z' 297 | }) 298 | 299 | expect(analyzeTree).toHaveBeenCalledTimes(1) 300 | }) 301 | 302 | it('handles a check_run event', async () => { 303 | // Override event 304 | event = {name: 'check_run', payload: checkRunPayload} 305 | 306 | analyzeTree.mockResolvedValue([]) 307 | 308 | await app.receive(event) 309 | 310 | expect(github.request).toHaveBeenCalledTimes(2) 311 | expect(github.request).toHaveBeenNthCalledWith(1, { 312 | headers: { 313 | 'accept': 'application/vnd.github.antiope-preview+json' 314 | }, 315 | method: 'POST', 316 | url: 'https://api.github.com/repos/wintron/example/check-runs', 317 | name: 'feedback', 318 | head_sha: '8e86089c36bbc8018af737312e756b8c2777ef50', 319 | status: 'in_progress', 320 | started_at: '2018-01-01T00:00:00.000Z' 321 | }) 322 | expect(github.request).toHaveBeenNthCalledWith(2, { 323 | headers: { 324 | 'accept': 'application/vnd.github.antiope-preview+json' 325 | }, 326 | method: 'PATCH', 327 | url: 'https://api.github.com/repos/wintron/example/check-runs/42', 328 | status: 'completed', 329 | conclusion: 'success', 330 | completed_at: '2018-01-01T00:00:00.000Z' 331 | }) 332 | 333 | expect(analyzeTree).toHaveBeenCalledTimes(1) 334 | }) 335 | 336 | it('handles more than 50 annotations', async () => { 337 | const annotations = Array(100).fill({ 338 | filename: 'FILENAME.md', 339 | blob_href: 'https://github.com/wintron/example/blob/ref/FILENAME.md', 340 | start_line: 1, 341 | end_line: 1, 342 | warning_level: 'notice', 343 | message: 'message', 344 | title: 'title' 345 | }) 346 | 347 | analyzeTree.mockResolvedValue([annotations]) 348 | 349 | await app.receive(event) 350 | 351 | expect(annotations.length).toBe(100) 352 | expect(github.request).toHaveBeenCalledTimes(4) 353 | expect(github.request).toHaveBeenNthCalledWith(1, { 354 | headers: { 355 | 'accept': 'application/vnd.github.antiope-preview+json' 356 | }, 357 | method: 'POST', 358 | url: 'https://api.github.com/repos/wintron/example/check-runs', 359 | name: 'feedback', 360 | head_sha: '9875bf915c118e6369a610770288cf7f0a415124', 361 | status: 'in_progress', 362 | started_at: '2018-01-01T00:00:00.000Z' 363 | }) 364 | expect(github.request).toHaveBeenNthCalledWith(2, { 365 | headers: { 366 | 'accept': 'application/vnd.github.antiope-preview+json' 367 | }, 368 | method: 'PATCH', 369 | url: 'https://api.github.com/repos/wintron/example/check-runs/42', 370 | output: { 371 | summary: 'Alex found 100 issues', 372 | title: 'analysis', 373 | annotations: annotations.slice(0, 50) 374 | } 375 | }) 376 | expect(github.request).toHaveBeenNthCalledWith(3, { 377 | headers: { 378 | 'accept': 'application/vnd.github.antiope-preview+json' 379 | }, 380 | method: 'PATCH', 381 | url: 'https://api.github.com/repos/wintron/example/check-runs/42', 382 | output: { 383 | summary: 'Alex found 100 issues', 384 | title: 'analysis', 385 | annotations: annotations.slice(50, 100) 386 | } 387 | }) 388 | expect(github.request).toHaveBeenNthCalledWith(4, { 389 | headers: { 390 | 'accept': 'application/vnd.github.antiope-preview+json' 391 | }, 392 | method: 'PATCH', 393 | url: 'https://api.github.com/repos/wintron/example/check-runs/42', 394 | status: 'completed', 395 | conclusion: 'neutral', 396 | completed_at: '2018-01-01T00:00:00.000Z' 397 | }) 398 | 399 | expect(analyzeTree).toHaveBeenCalledTimes(1) 400 | }) 401 | 402 | it('ignores other check_suite actions', async () => { 403 | // Override event action 404 | event.payload.action = 'completed' 405 | 406 | await app.receive(event) 407 | 408 | expect(github.request).toHaveBeenCalledTimes(0) 409 | expect(analyzeTree).toHaveBeenCalledTimes(0) 410 | }) 411 | }) 412 | 413 | 414 | --------------------------------------------------------------------------------