├── .env.example ├── .github ├── autolabeler.yml └── stale.yml ├── .gitignore ├── .lintstagedrc ├── .travis.yml ├── LICENSE ├── README.md ├── app.json ├── docs └── deploy.md ├── index.js ├── package.json └── test ├── fixtures └── pull_request.opened.json └── index.test.js /.env.example: -------------------------------------------------------------------------------- 1 | # The ID of your GitHub App 2 | APP_ID= 3 | WEBHOOK_SECRET=development 4 | 5 | # Uncomment this to get verbose logging 6 | # LOG_LEVEL=trace # or `info` to show less 7 | 8 | # Go to https://smee.io/new set this to the URL that you are redirected to. 9 | # WEBHOOK_PROXY_URL= 10 | -------------------------------------------------------------------------------- /.github/autolabeler.yml: -------------------------------------------------------------------------------- 1 | tests: ["test"] 2 | docs: ["*.md", "docs/", "LICENSE"] 3 | config: [".github", ".travis*"] 4 | 5 | # Pull request has files in it that it shouldn't! 6 | broken: ["*.pem", "*-lock.json", "node_modules", ".env"] 7 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for https://github.com/probot/stale 2 | _extends: .github 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | *.pem 4 | .env 5 | package-lock.json 6 | -------------------------------------------------------------------------------- /.lintstagedrc: -------------------------------------------------------------------------------- 1 | { 2 | "*.js": "standard --fix" 3 | } 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - 10 5 | notifications: 6 | disabled: true 7 | before_install: 8 | - npm install -g npm@6 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) [year], {{ author }} 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 | # Probot Auto Labeler 2 | 3 | [![Greenkeeper badge](https://badges.greenkeeper.io/probot/autolabeler.svg)](https://greenkeeper.io/) 4 | 5 | > A GitHub App built with [probot](https://github.com/probot/probot) that adds labels to Pull Requests based on matched file patterns. 6 | 7 | ## Using 8 | 9 | Configure by creating a `.github/autolabeler.yml` file with a [YAML file](https://en.wikipedia.org/wiki/YAML) in the format of `label: file/path`. Then add the [Probot Auto Labeler Bot](https://github.com/apps/probot-autolabeler) to your repository. 10 | 11 | For example, 12 | 13 | ```yaml 14 | frontend: ["*.js", "*.css", "*.html"] 15 | backend: ["/app", "*.rb"] 16 | legal: ["LICENSE*", "NOTICES*"] 17 | config: .github 18 | ``` 19 | 20 | Then if a pull request is opened that has `scripts/widget.js` modified, then the frontend label will be added. 21 | 22 | ##### Issues with Bot 23 | 24 | If you are having issues with [the GitHub app not working](https://github.com/apps/probot-autolabeler), please [open an issue](https://github.com/probot/autolabeler/issues). 25 | 26 | 27 | ## Setup 28 | 29 | ``` 30 | # Install dependencies 31 | npm install 32 | 33 | # Run the bot 34 | npm start 35 | ``` 36 | 37 | See [docs/deploy.md](docs/deploy.md) if you would like to run your own instance of this plugin. 38 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "PRIVATE_KEY": { 4 | "description": "the private key you downloaded when creating the GitHub App" 5 | }, 6 | "APP_ID": { 7 | "description": "the ID of your GitHub App" 8 | }, 9 | "WEBHOOK_SECRET": { 10 | "description": "the secret configured for your GitHub App" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /docs/deploy.md: -------------------------------------------------------------------------------- 1 | # Deploying 2 | 3 | If you would like to run your own instance of this plugin, see the [docs for deploying plugins](https://github.com/probot/probot/blob/master/docs/deployment.md). 4 | 5 | This plugin 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 yaml = require('js-yaml') 2 | const ignore = require('ignore') 3 | 4 | module.exports = ({ app }) => { 5 | app.on('pull_request.opened', autolabel) 6 | app.on('pull_request.synchronize', autolabel) 7 | app.on('pull_request.reopened', autolabel) 8 | 9 | async function autolabel (context) { 10 | const content = await context.octokit.repos.getContent( 11 | context.repo({ 12 | path: '.github/autolabeler.yml' 13 | }) 14 | ) 15 | const config = yaml.safeLoad( 16 | Buffer.from(content.data.content, 'base64').toString() 17 | ) 18 | 19 | const files = await context.octokit.pulls.listFiles(context.pullRequest()) 20 | const changedFiles = files.data.map((file) => file.filename) 21 | 22 | const labels = new Set() 23 | 24 | // eslint-disable-next-line guard-for-in 25 | for (const label in config) { 26 | app.log('looking for changes', label, config[label]) 27 | const matcher = ignore().add(config[label]) 28 | 29 | if (changedFiles.find((file) => matcher.ignores(file))) { 30 | labels.add(label) 31 | } 32 | } 33 | 34 | const labelsToAdd = Array.from(labels) 35 | 36 | app.log('Adding labels', labelsToAdd) 37 | if (labelsToAdd.length > 0) { 38 | return context.octokit.issues.addLabels( 39 | context.issue({ 40 | labels: labelsToAdd 41 | }) 42 | ) 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "probot-labeler", 3 | "version": "1.0.0", 4 | "description": "A GitHub App built with probot that adds labels to Pull Requests based on matched file patterns.", 5 | "author": "Brandon Keepers", 6 | "license": "ISC", 7 | "repository": "https://github.com/probot/labeler.git", 8 | "scripts": { 9 | "start": "probot run ./index.js", 10 | "test": "jest && standard" 11 | }, 12 | "dependencies": { 13 | "ignore": "^3.3.3", 14 | "js-yaml": "^3.9.0", 15 | "probot": "^10.0.0" 16 | }, 17 | "devDependencies": { 18 | "husky": "^4.3.0", 19 | "jest": "^26.6.0", 20 | "lint-staged": "^10.5.1", 21 | "nock": "^13.0.0", 22 | "smee-client": "^1.0.1", 23 | "standard": "^16.0.0" 24 | }, 25 | "standard": { 26 | "env": [ 27 | "jest" 28 | ] 29 | }, 30 | "husky": { 31 | "hooks": { 32 | "pre-commit": "lint-staged" 33 | } 34 | }, 35 | "jest": { 36 | "verbose": true, 37 | "testURL": "http://localhost/" 38 | }, 39 | "engines": { 40 | "node": ">= 10.9.0", 41 | "npm": ">= 6.0.0" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/fixtures/pull_request.opened.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pull_request", 3 | "payload": { 4 | "action": "opened", 5 | "number": 98, 6 | "pull_request": { 7 | "url": "https://api.github.com/repos/robotland/test/pulls/98", 8 | "id": 131638216, 9 | "html_url": "https://github.com/robotland/test/pull/98", 10 | "diff_url": "https://github.com/robotland/test/pull/98.diff", 11 | "patch_url": "https://github.com/robotland/test/pull/98.patch", 12 | "issue_url": "https://api.github.com/repos/robotland/test/issues/98", 13 | "number": 98, 14 | "state": "open", 15 | "locked": false, 16 | "title": "Create autolabeler.yml", 17 | "user": { 18 | "login": "bkeepers", 19 | "id": 173, 20 | "avatar_url": "https://avatars0.githubusercontent.com/u/173?v=4", 21 | "gravatar_id": "", 22 | "url": "https://api.github.com/users/bkeepers", 23 | "html_url": "https://github.com/bkeepers", 24 | "followers_url": "https://api.github.com/users/bkeepers/followers", 25 | "following_url": "https://api.github.com/users/bkeepers/following{/other_user}", 26 | "gists_url": "https://api.github.com/users/bkeepers/gists{/gist_id}", 27 | "starred_url": "https://api.github.com/users/bkeepers/starred{/owner}{/repo}", 28 | "subscriptions_url": "https://api.github.com/users/bkeepers/subscriptions", 29 | "organizations_url": "https://api.github.com/users/bkeepers/orgs", 30 | "repos_url": "https://api.github.com/users/bkeepers/repos", 31 | "events_url": "https://api.github.com/users/bkeepers/events{/privacy}", 32 | "received_events_url": "https://api.github.com/users/bkeepers/received_events", 33 | "type": "User", 34 | "site_admin": true 35 | }, 36 | "body": "", 37 | "created_at": "2017-07-20T20:02:29Z", 38 | "updated_at": "2017-07-20T20:02:29Z", 39 | "closed_at": null, 40 | "merged_at": null, 41 | "merge_commit_sha": null, 42 | "assignee": null, 43 | "assignees": [], 44 | "requested_reviewers": [], 45 | "milestone": null, 46 | "commits_url": "https://api.github.com/repos/robotland/test/pulls/98/commits", 47 | "review_comments_url": "https://api.github.com/repos/robotland/test/pulls/98/comments", 48 | "review_comment_url": "https://api.github.com/repos/robotland/test/pulls/comments{/number}", 49 | "comments_url": "https://api.github.com/repos/robotland/test/issues/98/comments", 50 | "statuses_url": "https://api.github.com/repos/robotland/test/statuses/14b63ee8704a1bd22dc3c0208870f499391f4e9f", 51 | "head": { 52 | "label": "robotland:autolabeler", 53 | "ref": "autolabeler", 54 | "sha": "14b63ee8704a1bd22dc3c0208870f499391f4e9f", 55 | "user": { 56 | "login": "robotland", 57 | "id": 11724939, 58 | "avatar_url": "https://avatars2.githubusercontent.com/u/11724939?v=4", 59 | "gravatar_id": "", 60 | "url": "https://api.github.com/users/robotland", 61 | "html_url": "https://github.com/robotland", 62 | "followers_url": "https://api.github.com/users/robotland/followers", 63 | "following_url": "https://api.github.com/users/robotland/following{/other_user}", 64 | "gists_url": "https://api.github.com/users/robotland/gists{/gist_id}", 65 | "starred_url": "https://api.github.com/users/robotland/starred{/owner}{/repo}", 66 | "subscriptions_url": "https://api.github.com/users/robotland/subscriptions", 67 | "organizations_url": "https://api.github.com/users/robotland/orgs", 68 | "repos_url": "https://api.github.com/users/robotland/repos", 69 | "events_url": "https://api.github.com/users/robotland/events{/privacy}", 70 | "received_events_url": "https://api.github.com/users/robotland/received_events", 71 | "type": "Organization", 72 | "site_admin": false 73 | }, 74 | "repo": { 75 | "id": 68474533, 76 | "name": "test", 77 | "full_name": "robotland/test", 78 | "owner": { 79 | "login": "robotland", 80 | "id": 11724939, 81 | "avatar_url": "https://avatars2.githubusercontent.com/u/11724939?v=4", 82 | "gravatar_id": "", 83 | "url": "https://api.github.com/users/robotland", 84 | "html_url": "https://github.com/robotland", 85 | "followers_url": "https://api.github.com/users/robotland/followers", 86 | "following_url": "https://api.github.com/users/robotland/following{/other_user}", 87 | "gists_url": "https://api.github.com/users/robotland/gists{/gist_id}", 88 | "starred_url": "https://api.github.com/users/robotland/starred{/owner}{/repo}", 89 | "subscriptions_url": "https://api.github.com/users/robotland/subscriptions", 90 | "organizations_url": "https://api.github.com/users/robotland/orgs", 91 | "repos_url": "https://api.github.com/users/robotland/repos", 92 | "events_url": "https://api.github.com/users/robotland/events{/privacy}", 93 | "received_events_url": "https://api.github.com/users/robotland/received_events", 94 | "type": "Organization", 95 | "site_admin": false 96 | }, 97 | "private": true, 98 | "html_url": "https://github.com/robotland/test", 99 | "description": "a playground for gentle robots", 100 | "fork": false, 101 | "url": "https://api.github.com/repos/robotland/test", 102 | "forks_url": "https://api.github.com/repos/robotland/test/forks", 103 | "keys_url": "https://api.github.com/repos/robotland/test/keys{/key_id}", 104 | "collaborators_url": "https://api.github.com/repos/robotland/test/collaborators{/collaborator}", 105 | "teams_url": "https://api.github.com/repos/robotland/test/teams", 106 | "hooks_url": "https://api.github.com/repos/robotland/test/hooks", 107 | "issue_events_url": "https://api.github.com/repos/robotland/test/issues/events{/number}", 108 | "events_url": "https://api.github.com/repos/robotland/test/events", 109 | "assignees_url": "https://api.github.com/repos/robotland/test/assignees{/user}", 110 | "branches_url": "https://api.github.com/repos/robotland/test/branches{/branch}", 111 | "tags_url": "https://api.github.com/repos/robotland/test/tags", 112 | "blobs_url": "https://api.github.com/repos/robotland/test/git/blobs{/sha}", 113 | "git_tags_url": "https://api.github.com/repos/robotland/test/git/tags{/sha}", 114 | "git_refs_url": "https://api.github.com/repos/robotland/test/git/refs{/sha}", 115 | "trees_url": "https://api.github.com/repos/robotland/test/git/trees{/sha}", 116 | "statuses_url": "https://api.github.com/repos/robotland/test/statuses/{sha}", 117 | "languages_url": "https://api.github.com/repos/robotland/test/languages", 118 | "stargazers_url": "https://api.github.com/repos/robotland/test/stargazers", 119 | "contributors_url": "https://api.github.com/repos/robotland/test/contributors", 120 | "subscribers_url": "https://api.github.com/repos/robotland/test/subscribers", 121 | "subscription_url": "https://api.github.com/repos/robotland/test/subscription", 122 | "commits_url": "https://api.github.com/repos/robotland/test/commits{/sha}", 123 | "git_commits_url": "https://api.github.com/repos/robotland/test/git/commits{/sha}", 124 | "comments_url": "https://api.github.com/repos/robotland/test/comments{/number}", 125 | "issue_comment_url": "https://api.github.com/repos/robotland/test/issues/comments{/number}", 126 | "contents_url": "https://api.github.com/repos/robotland/test/contents/{+path}", 127 | "compare_url": "https://api.github.com/repos/robotland/test/compare/{base}...{head}", 128 | "merges_url": "https://api.github.com/repos/robotland/test/merges", 129 | "archive_url": "https://api.github.com/repos/robotland/test/{archive_format}{/ref}", 130 | "downloads_url": "https://api.github.com/repos/robotland/test/downloads", 131 | "issues_url": "https://api.github.com/repos/robotland/test/issues{/number}", 132 | "pulls_url": "https://api.github.com/repos/robotland/test/pulls{/number}", 133 | "milestones_url": "https://api.github.com/repos/robotland/test/milestones{/number}", 134 | "notifications_url": "https://api.github.com/repos/robotland/test/notifications{?since,all,participating}", 135 | "labels_url": "https://api.github.com/repos/robotland/test/labels{/name}", 136 | "releases_url": "https://api.github.com/repos/robotland/test/releases{/id}", 137 | "deployments_url": "https://api.github.com/repos/robotland/test/deployments", 138 | "created_at": "2016-09-17T19:44:06Z", 139 | "updated_at": "2017-07-19T22:20:16Z", 140 | "pushed_at": "2017-07-20T20:02:24Z", 141 | "git_url": "git://github.com/robotland/test.git", 142 | "ssh_url": "git@github.com:robotland/test.git", 143 | "clone_url": "https://github.com/robotland/test.git", 144 | "svn_url": "https://github.com/robotland/test", 145 | "homepage": "https://probot.github.io/", 146 | "size": 36, 147 | "stargazers_count": 0, 148 | "watchers_count": 0, 149 | "language": "JavaScript", 150 | "has_issues": true, 151 | "has_projects": false, 152 | "has_downloads": true, 153 | "has_wiki": true, 154 | "has_pages": false, 155 | "forks_count": 0, 156 | "mirror_url": null, 157 | "open_issues_count": 23, 158 | "forks": 0, 159 | "open_issues": 23, 160 | "watchers": 0, 161 | "default_branch": "master" 162 | } 163 | }, 164 | "base": { 165 | "label": "robotland:master", 166 | "ref": "master", 167 | "sha": "92b70a68f1bd8c19c6e66e7673aa7d152b6961ea", 168 | "user": { 169 | "login": "robotland", 170 | "id": 11724939, 171 | "avatar_url": "https://avatars2.githubusercontent.com/u/11724939?v=4", 172 | "gravatar_id": "", 173 | "url": "https://api.github.com/users/robotland", 174 | "html_url": "https://github.com/robotland", 175 | "followers_url": "https://api.github.com/users/robotland/followers", 176 | "following_url": "https://api.github.com/users/robotland/following{/other_user}", 177 | "gists_url": "https://api.github.com/users/robotland/gists{/gist_id}", 178 | "starred_url": "https://api.github.com/users/robotland/starred{/owner}{/repo}", 179 | "subscriptions_url": "https://api.github.com/users/robotland/subscriptions", 180 | "organizations_url": "https://api.github.com/users/robotland/orgs", 181 | "repos_url": "https://api.github.com/users/robotland/repos", 182 | "events_url": "https://api.github.com/users/robotland/events{/privacy}", 183 | "received_events_url": "https://api.github.com/users/robotland/received_events", 184 | "type": "Organization", 185 | "site_admin": false 186 | }, 187 | "repo": { 188 | "id": 68474533, 189 | "name": "test", 190 | "full_name": "robotland/test", 191 | "owner": { 192 | "login": "robotland", 193 | "id": 11724939, 194 | "avatar_url": "https://avatars2.githubusercontent.com/u/11724939?v=4", 195 | "gravatar_id": "", 196 | "url": "https://api.github.com/users/robotland", 197 | "html_url": "https://github.com/robotland", 198 | "followers_url": "https://api.github.com/users/robotland/followers", 199 | "following_url": "https://api.github.com/users/robotland/following{/other_user}", 200 | "gists_url": "https://api.github.com/users/robotland/gists{/gist_id}", 201 | "starred_url": "https://api.github.com/users/robotland/starred{/owner}{/repo}", 202 | "subscriptions_url": "https://api.github.com/users/robotland/subscriptions", 203 | "organizations_url": "https://api.github.com/users/robotland/orgs", 204 | "repos_url": "https://api.github.com/users/robotland/repos", 205 | "events_url": "https://api.github.com/users/robotland/events{/privacy}", 206 | "received_events_url": "https://api.github.com/users/robotland/received_events", 207 | "type": "Organization", 208 | "site_admin": false 209 | }, 210 | "private": true, 211 | "html_url": "https://github.com/robotland/test", 212 | "description": "a playground for gentle robots", 213 | "fork": false, 214 | "url": "https://api.github.com/repos/robotland/test", 215 | "forks_url": "https://api.github.com/repos/robotland/test/forks", 216 | "keys_url": "https://api.github.com/repos/robotland/test/keys{/key_id}", 217 | "collaborators_url": "https://api.github.com/repos/robotland/test/collaborators{/collaborator}", 218 | "teams_url": "https://api.github.com/repos/robotland/test/teams", 219 | "hooks_url": "https://api.github.com/repos/robotland/test/hooks", 220 | "issue_events_url": "https://api.github.com/repos/robotland/test/issues/events{/number}", 221 | "events_url": "https://api.github.com/repos/robotland/test/events", 222 | "assignees_url": "https://api.github.com/repos/robotland/test/assignees{/user}", 223 | "branches_url": "https://api.github.com/repos/robotland/test/branches{/branch}", 224 | "tags_url": "https://api.github.com/repos/robotland/test/tags", 225 | "blobs_url": "https://api.github.com/repos/robotland/test/git/blobs{/sha}", 226 | "git_tags_url": "https://api.github.com/repos/robotland/test/git/tags{/sha}", 227 | "git_refs_url": "https://api.github.com/repos/robotland/test/git/refs{/sha}", 228 | "trees_url": "https://api.github.com/repos/robotland/test/git/trees{/sha}", 229 | "statuses_url": "https://api.github.com/repos/robotland/test/statuses/{sha}", 230 | "languages_url": "https://api.github.com/repos/robotland/test/languages", 231 | "stargazers_url": "https://api.github.com/repos/robotland/test/stargazers", 232 | "contributors_url": "https://api.github.com/repos/robotland/test/contributors", 233 | "subscribers_url": "https://api.github.com/repos/robotland/test/subscribers", 234 | "subscription_url": "https://api.github.com/repos/robotland/test/subscription", 235 | "commits_url": "https://api.github.com/repos/robotland/test/commits{/sha}", 236 | "git_commits_url": "https://api.github.com/repos/robotland/test/git/commits{/sha}", 237 | "comments_url": "https://api.github.com/repos/robotland/test/comments{/number}", 238 | "issue_comment_url": "https://api.github.com/repos/robotland/test/issues/comments{/number}", 239 | "contents_url": "https://api.github.com/repos/robotland/test/contents/{+path}", 240 | "compare_url": "https://api.github.com/repos/robotland/test/compare/{base}...{head}", 241 | "merges_url": "https://api.github.com/repos/robotland/test/merges", 242 | "archive_url": "https://api.github.com/repos/robotland/test/{archive_format}{/ref}", 243 | "downloads_url": "https://api.github.com/repos/robotland/test/downloads", 244 | "issues_url": "https://api.github.com/repos/robotland/test/issues{/number}", 245 | "pulls_url": "https://api.github.com/repos/robotland/test/pulls{/number}", 246 | "milestones_url": "https://api.github.com/repos/robotland/test/milestones{/number}", 247 | "notifications_url": "https://api.github.com/repos/robotland/test/notifications{?since,all,participating}", 248 | "labels_url": "https://api.github.com/repos/robotland/test/labels{/name}", 249 | "releases_url": "https://api.github.com/repos/robotland/test/releases{/id}", 250 | "deployments_url": "https://api.github.com/repos/robotland/test/deployments", 251 | "created_at": "2016-09-17T19:44:06Z", 252 | "updated_at": "2017-07-19T22:20:16Z", 253 | "pushed_at": "2017-07-20T20:02:24Z", 254 | "git_url": "git://github.com/robotland/test.git", 255 | "ssh_url": "git@github.com:robotland/test.git", 256 | "clone_url": "https://github.com/robotland/test.git", 257 | "svn_url": "https://github.com/robotland/test", 258 | "homepage": "https://probot.github.io/", 259 | "size": 36, 260 | "stargazers_count": 0, 261 | "watchers_count": 0, 262 | "language": "JavaScript", 263 | "has_issues": true, 264 | "has_projects": false, 265 | "has_downloads": true, 266 | "has_wiki": true, 267 | "has_pages": false, 268 | "forks_count": 0, 269 | "mirror_url": null, 270 | "open_issues_count": 23, 271 | "forks": 0, 272 | "open_issues": 23, 273 | "watchers": 0, 274 | "default_branch": "master" 275 | } 276 | }, 277 | "_links": { 278 | "self": { 279 | "href": "https://api.github.com/repos/robotland/test/pulls/98" 280 | }, 281 | "html": { 282 | "href": "https://github.com/robotland/test/pull/98" 283 | }, 284 | "issue": { 285 | "href": "https://api.github.com/repos/robotland/test/issues/98" 286 | }, 287 | "comments": { 288 | "href": "https://api.github.com/repos/robotland/test/issues/98/comments" 289 | }, 290 | "review_comments": { 291 | "href": "https://api.github.com/repos/robotland/test/pulls/98/comments" 292 | }, 293 | "review_comment": { 294 | "href": "https://api.github.com/repos/robotland/test/pulls/comments{/number}" 295 | }, 296 | "commits": { 297 | "href": "https://api.github.com/repos/robotland/test/pulls/98/commits" 298 | }, 299 | "statuses": { 300 | "href": "https://api.github.com/repos/robotland/test/statuses/14b63ee8704a1bd22dc3c0208870f499391f4e9f" 301 | } 302 | }, 303 | "merged": false, 304 | "mergeable": null, 305 | "rebaseable": null, 306 | "mergeable_state": "unknown", 307 | "merged_by": null, 308 | "comments": 0, 309 | "review_comments": 0, 310 | "maintainer_can_modify": false, 311 | "commits": 1, 312 | "additions": 3, 313 | "deletions": 0, 314 | "changed_files": 1 315 | }, 316 | "repository": { 317 | "id": 68474533, 318 | "name": "test", 319 | "full_name": "robotland/test", 320 | "owner": { 321 | "login": "robotland", 322 | "id": 11724939, 323 | "avatar_url": "https://avatars2.githubusercontent.com/u/11724939?v=4", 324 | "gravatar_id": "", 325 | "url": "https://api.github.com/users/robotland", 326 | "html_url": "https://github.com/robotland", 327 | "followers_url": "https://api.github.com/users/robotland/followers", 328 | "following_url": "https://api.github.com/users/robotland/following{/other_user}", 329 | "gists_url": "https://api.github.com/users/robotland/gists{/gist_id}", 330 | "starred_url": "https://api.github.com/users/robotland/starred{/owner}{/repo}", 331 | "subscriptions_url": "https://api.github.com/users/robotland/subscriptions", 332 | "organizations_url": "https://api.github.com/users/robotland/orgs", 333 | "repos_url": "https://api.github.com/users/robotland/repos", 334 | "events_url": "https://api.github.com/users/robotland/events{/privacy}", 335 | "received_events_url": "https://api.github.com/users/robotland/received_events", 336 | "type": "Organization", 337 | "site_admin": false 338 | }, 339 | "private": true, 340 | "html_url": "https://github.com/robotland/test", 341 | "description": "a playground for gentle robots", 342 | "fork": false, 343 | "url": "https://api.github.com/repos/robotland/test", 344 | "forks_url": "https://api.github.com/repos/robotland/test/forks", 345 | "keys_url": "https://api.github.com/repos/robotland/test/keys{/key_id}", 346 | "collaborators_url": "https://api.github.com/repos/robotland/test/collaborators{/collaborator}", 347 | "teams_url": "https://api.github.com/repos/robotland/test/teams", 348 | "hooks_url": "https://api.github.com/repos/robotland/test/hooks", 349 | "issue_events_url": "https://api.github.com/repos/robotland/test/issues/events{/number}", 350 | "events_url": "https://api.github.com/repos/robotland/test/events", 351 | "assignees_url": "https://api.github.com/repos/robotland/test/assignees{/user}", 352 | "branches_url": "https://api.github.com/repos/robotland/test/branches{/branch}", 353 | "tags_url": "https://api.github.com/repos/robotland/test/tags", 354 | "blobs_url": "https://api.github.com/repos/robotland/test/git/blobs{/sha}", 355 | "git_tags_url": "https://api.github.com/repos/robotland/test/git/tags{/sha}", 356 | "git_refs_url": "https://api.github.com/repos/robotland/test/git/refs{/sha}", 357 | "trees_url": "https://api.github.com/repos/robotland/test/git/trees{/sha}", 358 | "statuses_url": "https://api.github.com/repos/robotland/test/statuses/{sha}", 359 | "languages_url": "https://api.github.com/repos/robotland/test/languages", 360 | "stargazers_url": "https://api.github.com/repos/robotland/test/stargazers", 361 | "contributors_url": "https://api.github.com/repos/robotland/test/contributors", 362 | "subscribers_url": "https://api.github.com/repos/robotland/test/subscribers", 363 | "subscription_url": "https://api.github.com/repos/robotland/test/subscription", 364 | "commits_url": "https://api.github.com/repos/robotland/test/commits{/sha}", 365 | "git_commits_url": "https://api.github.com/repos/robotland/test/git/commits{/sha}", 366 | "comments_url": "https://api.github.com/repos/robotland/test/comments{/number}", 367 | "issue_comment_url": "https://api.github.com/repos/robotland/test/issues/comments{/number}", 368 | "contents_url": "https://api.github.com/repos/robotland/test/contents/{+path}", 369 | "compare_url": "https://api.github.com/repos/robotland/test/compare/{base}...{head}", 370 | "merges_url": "https://api.github.com/repos/robotland/test/merges", 371 | "archive_url": "https://api.github.com/repos/robotland/test/{archive_format}{/ref}", 372 | "downloads_url": "https://api.github.com/repos/robotland/test/downloads", 373 | "issues_url": "https://api.github.com/repos/robotland/test/issues{/number}", 374 | "pulls_url": "https://api.github.com/repos/robotland/test/pulls{/number}", 375 | "milestones_url": "https://api.github.com/repos/robotland/test/milestones{/number}", 376 | "notifications_url": "https://api.github.com/repos/robotland/test/notifications{?since,all,participating}", 377 | "labels_url": "https://api.github.com/repos/robotland/test/labels{/name}", 378 | "releases_url": "https://api.github.com/repos/robotland/test/releases{/id}", 379 | "deployments_url": "https://api.github.com/repos/robotland/test/deployments", 380 | "created_at": "2016-09-17T19:44:06Z", 381 | "updated_at": "2017-07-19T22:20:16Z", 382 | "pushed_at": "2017-07-20T20:02:24Z", 383 | "git_url": "git://github.com/robotland/test.git", 384 | "ssh_url": "git@github.com:robotland/test.git", 385 | "clone_url": "https://github.com/robotland/test.git", 386 | "svn_url": "https://github.com/robotland/test", 387 | "homepage": "https://probot.github.io/", 388 | "size": 36, 389 | "stargazers_count": 0, 390 | "watchers_count": 0, 391 | "language": "JavaScript", 392 | "has_issues": true, 393 | "has_projects": false, 394 | "has_downloads": true, 395 | "has_wiki": true, 396 | "has_pages": false, 397 | "forks_count": 0, 398 | "mirror_url": null, 399 | "open_issues_count": 23, 400 | "forks": 0, 401 | "open_issues": 23, 402 | "watchers": 0, 403 | "default_branch": "master" 404 | }, 405 | "organization": { 406 | "login": "robotland", 407 | "id": 11724939, 408 | "url": "https://api.github.com/orgs/robotland", 409 | "repos_url": "https://api.github.com/orgs/robotland/repos", 410 | "events_url": "https://api.github.com/orgs/robotland/events", 411 | "hooks_url": "https://api.github.com/orgs/robotland/hooks", 412 | "issues_url": "https://api.github.com/orgs/robotland/issues", 413 | "members_url": "https://api.github.com/orgs/robotland/members{/member}", 414 | "public_members_url": "https://api.github.com/orgs/robotland/public_members{/member}", 415 | "avatar_url": "https://avatars2.githubusercontent.com/u/11724939?v=4", 416 | "description": null 417 | }, 418 | "sender": { 419 | "login": "bkeepers", 420 | "id": 173, 421 | "avatar_url": "https://avatars0.githubusercontent.com/u/173?v=4", 422 | "gravatar_id": "", 423 | "url": "https://api.github.com/users/bkeepers", 424 | "html_url": "https://github.com/bkeepers", 425 | "followers_url": "https://api.github.com/users/bkeepers/followers", 426 | "following_url": "https://api.github.com/users/bkeepers/following{/other_user}", 427 | "gists_url": "https://api.github.com/users/bkeepers/gists{/gist_id}", 428 | "starred_url": "https://api.github.com/users/bkeepers/starred{/owner}{/repo}", 429 | "subscriptions_url": "https://api.github.com/users/bkeepers/subscriptions", 430 | "organizations_url": "https://api.github.com/users/bkeepers/orgs", 431 | "repos_url": "https://api.github.com/users/bkeepers/repos", 432 | "events_url": "https://api.github.com/users/bkeepers/events{/privacy}", 433 | "received_events_url": "https://api.github.com/users/bkeepers/received_events", 434 | "type": "User", 435 | "site_admin": true 436 | }, 437 | "installation": { 438 | "id": 13055 439 | } 440 | } 441 | } 442 | -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | const { Probot, ProbotOctokit } = require('probot') 2 | const nock = require('nock') 3 | const plugin = require('..') 4 | 5 | const config = ` 6 | test: test* 7 | config: .github 8 | frontend: ["*.js"] 9 | ` 10 | 11 | describe('autolabeler', () => { 12 | let probot 13 | 14 | beforeEach(() => { 15 | nock.disableNetConnect() 16 | probot = new Probot({ 17 | id: 1, 18 | githubToken: 'test', 19 | // Disable throttling & retrying requests for easier testing 20 | Octokit: ProbotOctokit.defaults({ 21 | retry: { enabled: false }, 22 | throttle: { enabled: false } 23 | }) 24 | }) 25 | probot.load(plugin) 26 | }) 27 | 28 | afterEach(() => { 29 | nock.cleanAll() 30 | nock.enableNetConnect() 31 | }) 32 | 33 | describe('pull_request.opened event', () => { 34 | const event = require('./fixtures/pull_request.opened') 35 | 36 | test('adds label', async () => { 37 | // Test that we correctly return a test token 38 | nock('https://api.github.com') 39 | .get('/repos/robotland/test/contents/.github%2Fautolabeler.yml') 40 | .reply(200, { 41 | content: Buffer.from(config, 'utf-8').toString('base64') 42 | }) 43 | .get('/repos/robotland/test/pulls/98/files') 44 | .reply(200, [ 45 | { filename: 'test.txt' }, 46 | { filename: '.github/autolabeler.yml' } 47 | ]) 48 | .post('/repos/robotland/test/issues/98/labels', (body) => { 49 | expect(body).toEqual(['test', 'config']) 50 | return true 51 | }) 52 | .reply(200) 53 | 54 | await probot.receive(event) 55 | }) 56 | }) 57 | }) 58 | --------------------------------------------------------------------------------