Skip to content

Commit

Permalink
Hacky working version
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Jul 20, 2017
0 parents commit 91b02d9
Show file tree
Hide file tree
Showing 12 changed files with 5,217 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# The ID of your GitHub App
APP_ID=
WEBHOOK_SECRET=development

# Uncomment this to get verbose logging
# LOG_LEVEL=trace # or `info` to show less

# Subdomain to use for localtunnel server. Defaults to your local username.
# SUBDOMAIN=
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
npm-debug.log
*.pem
.env
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sudo: false
language: node_js
node_js:
- "7.7.1"
notifications:
disabled: true
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) [year], {{ author }}

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# {{ name }}

> a GitHub App built with [probot](https://github.com/probot/probot) that {{ description }}
## Setup

```
# Install dependencies
npm install
# Run the bot
npm start
```

See [docs/deploy.md](docs/deploy.md) if you would like to run your own instance of this plugin.
13 changes: 13 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"env": {
"PRIVATE_KEY": {
"description": "the private key you downloaded when creating the GitHub App"
},
"APP_ID": {
"description": "the ID of your GitHub App"
},
"WEBHOOK_SECRET": {
"description": "the secret configured for your GitHub App"
}
}
}
7 changes: 7 additions & 0 deletions docs/deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Deploying

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

This plugin requires these **Permissions & events** for the GitHub App:

> **TODO**: List permissions required for deployment here. See [probot/stale](https://github.com/probot/stale/blob/master/docs/deploy.md) for an example.
46 changes: 46 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const yaml = require('js-yaml');
const minimatch = require('minimatch');

module.exports = robot => {
robot.on('pull_request.opened', autolabel);
robot.on('pull_request.synchronize', autolabel);

async function autolabel(context) {
const content = await context.github.repos.getContent(context.repo({
path: '.github/autolabeler.yml'
}));
const config = yaml.load(Buffer.from(content.data.content, 'base64').toString());

const files = await context.github.pullRequests.getFiles(context.issue());
const changedFiles = files.data.map(file => file.filename);

const labels = new Set();

// eslint-disable-next-line guard-for-in
for (const label in config) {
robot.log('looking for changes', label, config[label]);

const matches = [].concat(config[label]).find(glob => {
robot.log('comparing', glob, changedFiles);
return changedFiles.find(file => {
robot.log('matching', file, glob, minimatch(file, glob));
return minimatch(file, glob);
});
});

if (matches) {
robot.log('adding label', label);
labels.add(label);
}
}

const labelsToAdd = Array.from(labels);

robot.log('Adding labels', labelsToAdd);
if (labelsToAdd.length > 0) {
return context.github.issues.addLabels(context.issue({
labels: labelsToAdd
}));
}
}
};
Loading

0 comments on commit 91b02d9

Please sign in to comment.