Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial hubot Cloudant scripts #2

Merged
merged 6 commits into from
Aug 11, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"env": {
"es6": true,
"node": true,
"mocha": true
},
"extends": "strongloop",
"rules": {
"dot-notation": [2, {"allowPattern": "^[a-z]+(_[a-z]+)+$"}],
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"max-len": 0,
"semi": [
"error",
"always"
],
"comma-dangle": ["error", "never"],
"brace-style": ["error", "stroustrup"]
}
}
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
.hubot_history
npm-debug.log
config
coverage
gh-pages
external-scripts.json
.npmrc
.DS_Store
databases/nlc
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- '4.2'
install:
- 'npm install'
script:
- 'npm run lint'
- 'npm run coverage'
notifications:
slack: ${SLACK_TOKEN}
132 changes: 132 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Contribution Guidelines

Want to contribute to this repository? Please read below first:

- [Issues and Bugs](#issues-and-bugs)
- [Feature Requests](#feature-requests)
- [Doc Fixes](#doc-fixes)
- [Guidelines](#submission-guidelines)
- [Coding Standards](#coding-standards)
- [Signing the CLA](#signing-the-cla)

## Issues and Bugs
If you find a bug in the source code or a mistake in the documentation, you can help us by
submitting an issue to this repo. Even better you can submit a Pull Request
with a fix.

**Please see the Submission Guidelines below**.

## Feature Requests
You can request a new feature by submitting an issue to this repo. Proposed features (with suitable design documentation and reasoning) can be crafted and submitted to this repo as a Pull Request.

**Please see the Submission Guidelines below**.

## Doc Fixes
If you want to help improve the docs, it's a good idea to let others know what you're working on to
minimize duplication of effort. Comment on an issue to let others know what you're working on, or create a new issue if your work
doesn't fit within the scope of any of the existing doc fix projects.

**Please see the Submission Guidelines below**.

## Submission Guidelines

### Submitting an Issue
Before you submit your issue search the repository. Maybe your question was already answered.

If your issue appears to be a bug, and hasn't been reported, open a new issue.
Help us to maximize the effort we can spend fixing issues and adding new
features, by not reporting duplicate issues.

### Submitting a Pull Request
Before you submit your pull request consider the following guidelines:

* Search this repo for an open or closed Pull Request
that relates to your submission. You don't want to duplicate effort.
* Please sign our [Contributor License Agreement (CLA)](#signing-the-cla) before sending pull
requests. We cannot accept code without this.
* Make your changes in a new git branch:

```shell
git checkout -b my-fix-branch master
```
* Create your patch, **including appropriate test cases**.
* Follow our [Coding Standards](#coding-standards).
* Test your branch via `npm test`
* Commit your changes using a descriptive commit message.

```shell
git commit -a
```
Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.
* Push your branch to GitHub:

```shell
git push origin my-fix-branch
```

* In GitHub, send a pull request to the master branch.
* If we suggest changes then:
* Make the required updates.
* Re-run `npm test` to ensure tests are still passing.
* Commit your changes to your branch (e.g. `my-fix-branch`).
* Push the changes to your GitHub repository (this will update your Pull Request).

If the PR gets too outdated we may ask you to rebase and force push to update the PR:

```
git rebase master -i
git push origin my-fix-branch -f
```

*WARNING. Squashing or reverting commits and forced push thereafter may remove GitHub comments
on code that were previously made by you and others in your commits.*

That's it! Thank you for your contribution!

#### After your pull request is merged

After your pull request is merged, you can safely delete your branch and pull the changes
from the main (upstream) repository:

* Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows:

```shell
git push origin --delete my-fix-branch
```

* Check out the master branch:

```shell
git checkout master -f
```

* Delete the local branch:

```shell
git branch -D my-fix-branch
```

* Update your master with the latest upstream version:

```shell
git pull --ff upstream master
```

## Coding Standards
To ensure consistency throughout the source code, keep these rules in mind as you are working:

### Linting

We enforce some style rules for code in this repository using [eslint](http://eslint.org/). You can install a linting addon to a lot of editors and IDEs that will follow our linting rules.

We use [Strongloop's](https://github.com/strongloop/eslint-config-strongloop) eslint configuration module, which is installed via `npm`. If you are using a linting addon and are seeing weird error messages, they can likely be fixed by running `npm i`.

If you decide to not install a linter addon, or cannot, you can run `npm run lint` to get a report of any style issues. Any issues not fixed will be caught during CI, and _will_ prevent merging.

## Signing the CLA

Please sign our Contributor License Agreement (CLA) before sending pull requests. For any code
changes to be accepted, the CLA must be signed.

* [For individuals](./cla-individual.pdf).
* [For corporations](./cla-corporate.pdf).
13 changes: 13 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2016 IBM

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,89 @@
[![Build Status](https://travis-ci.org/ibm-cloud-solutions/hubot-ibmcloud-cloudant.svg?branch=master)](https://travis-ci.org/ibm-cloud-solutions/hubot-ibmcloud-cloudant)
[![Coverage Status](https://coveralls.io/repos/github/ibm-cloud-solutions/hubot-ibmcloud-cloudant/badge.svg?branch=cleanup)](https://coveralls.io/github/ibm-cloud-solutions/hubot-ibmcloud-cloudant?branch=master)
[![Dependency Status](https://dependencyci.com/github/ibm-cloud-solutions/hubot-ibmcloud-cloudant/badge)](https://dependencyci.com/github/ibm-cloud-solutions/hubot-ibmcloud-cloudant)
[![npm](https://img.shields.io/npm/v/hubot-ibmcloud-cloudant.svg?maxAge=2592000)](https://www.npmjs.com/package/hubot-ibmcloud-cloudant)

# hubot-ibmcloud-cloudant

A hubot script for management of your the IBM Bluemix Cloudant instance.

## Getting Started
* [Usage](#usage)
* [Commands](#commands)
* [Hubot Adapter Setup](#hubot-adapter-setup)
* [Development](#development)
* [License](#license)
* [Contribute](#contribute)

## Usage

Steps for adding this to your existing hubot:

1. `cd` into your hubot directory
2. Install the cloudant management functionality with `npm install hubot-ibmcloud-cloudant --save`
3. Add `hubot-ibmcloud-cloudant` to your `external-scripts.json`
4. Add the necessary environment variables:
```
export HUBOT_CLOUDANT_ENDPOINT=<Bluemix Cloudant Endpoint
(https://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-bluemix.cloudant.com:443)>
export HUBOT_CLOUDANT_KEY=<Bluemix Cloudant User ID>
export HUBOT_CLOUDANT_PASSWORD=<Password for the Bluemix Cloudant user>
```

5. Start up your bot & off to the races!

## Commands <a id="commands"></a>
- `hubot cloudant help` - Show available commands for cloudant management.
- `hubot cloudant list databases` - List databases.
- `hubot cloudant info database [database]` - Show details for a database.
- `hubot cloudant create database [database]` - Create a database.
- `hubot cloudant set permissions [database] [user/apikey]` - Set permissions for a user/apikey for a database.
- `hubot cloudant list views [database]` - List all views for a database.
- `hubot cloudant run view [database] [view]` - Run the view for a database.

## Hubot Adapter Setup

Hubot supports a variety of adapters to connect to popular chat clients. For more feature rich experiences you can setup the following adapters:
- [Slack setup](https://github.com/ibm-cloud-solutions/hubot-ibmcloud-cloudant/blob/master/docs/adapters/slack.md)
- [Facebook Messenger setup](https://github.com/ibm-cloud-solutions/hubot-ibmcloud-cloudant/blob/master/docs/adapters/facebook.md)

## Development

Please refer to the [CONTRIBUTING.md](https://github.com/ibm-cloud-solutions/hubot-ibmcloud-cloudant/blob/master/CONTRIBUTING.md) before starting any work. Steps for running this script for development purposes:

### Configuration Setup

1. Create `config` folder in root of this project.
2. Create `env` in the `config` folder, with the following contents:
```
export HUBOT_CLOUDANT_ENDPOINT=<Bluemix Cloudant Endpoint
(https://xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-bluemix.cloudant.com:443)>
export HUBOT_CLOUDANT_KEY=<Bluemix Cloudant User ID>
export HUBOT_CLOUDANT_PASSWORD=<Password for the Bluemix Cloudant user>
```
3. In order to view content in chat clients you will need to add `hubot-ibmcloud-formatter` to your `external-scripts.json` file. Additionally, if you want to use `hubot-help` to make sure your command documentation is correct. Create `external-scripts.json` in the root of this project
```
[
"hubot-help",
"hubot-ibmcloud-formatter"
]
```
4. Lastly, run `npm install` to obtain all the dependent node modules.

### Running Hubot with Adapters

Hubot supports a variety of adapters to connect to popular chat clients.

If you just want to use:
- Terminal: run `npm run start`
- [Slack: link to setup instructions](https://github.com/ibm-cloud-solutions/hubot-ibmcloud-cloudant/blob/master/docs/adapters/slack.md)
- [Facebook Messenger: link to setup instructions](https://github.com/ibm-cloud-solutions/hubot-ibmcloud-cloudant/blob/master/docs/adapters/facebook.md)


## License

See [LICENSE.txt](https://github.com/ibm-cloud-solutions/hubot-ibmcloud-cloudant/blob/master/LICENSE.txt) for license information.

## Contribute

Please check out our [Contribution Guidelines](https://github.com/ibm-cloud-solutions/hubot-ibmcloud-cloudant/blob/master/CONTRIBUTING.md) for detailed information on how you can lend a hand.
Binary file added cla-corporate.pdf
Binary file not shown.
Binary file added cla-individual.pdf
Binary file not shown.
31 changes: 31 additions & 0 deletions docs/adapters/facebook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Using Facebook Messenger with your bot

If you want to use Facebook Messenger to communicate with your bot, get started with the following steps:

## Facebook setup

Follow the instructions from the link below to setup Facebook to obtain the `FB_PAGE_ID`, `FB_APP_ID`, `FB_APP_SECRET`, `FB_WEBHOOK_BASE`, and `FB_PAGE_TOKEN`.

- [Facebook setup instructions](http://cloudbots.ng.bluemix.net/docs/adapters/facebook.html)

## Configure the bot with Facebook Credentials
There are two available options for configuration depending on whether you choose the simple provisioning flow to run your bot on Bluemix or run your bot locally with the development configuration.

### Provisioning Configuration

In order to provision your bot on Bluemix to use Facebook Messenger you will need to supply the `FB_PAGE_ID`, `FB_APP_ID`, `FB_APP_SECRET`, `FB_WEBHOOK_BASE`, and `FB_PAGE_TOKEN` information obtained from the __Facebook setup__ section into the configuration wizard. See the __Provisioning on Bluemix__ section of the [README.md](../../README.md) for more information.

### Development Configuration

Take the Facebook values obtained in the previous section and append to the end of `config/env`:
```
export FB_PAGE_ID=xx
export FB_APP_ID=xx
export FB_APP_SECRET=xx
export FB_WEBHOOK_BASE=xx
export FB_PAGE_TOKEN=xx
```

#### Run with Facebook Adapter

To start Hubot using the Facebook adapter use: `npm run facebook`
26 changes: 26 additions & 0 deletions docs/adapters/slack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Using Slack with your bot

If you want to use Slack to communicate with your bot, get started with the following steps:

## Slack setup

Follow the instructions from the link below obtain a Slack token.

- [Slack setup instructions](http://cloudbots.ng.bluemix.net/docs/adapters/slack.html)

## Configure the bot with Slack token
There are two available options for configuration depending on whether you choose the simple provisioning flow to run your bot on Bluemix or run your bot locally with the development configuration.

### Provisioning Configuration

In order to provision your bot on Bluemix to use Slack you will need to supply the Slack token obtained from the __Slack setup__ section into the configuration wizard. See the __Provisioning on Bluemix__ section of the [README.md](../../README.md) for more information.

### Development Configuration

Take the Slack token that was obtained in the previous section and append the following environment information to the end of `config/env` file:
```
export HUBOT_SLACK_TOKEN=<TOKEN>
```

#### Run with Slack Adapter
To start Hubot using the Slack adapter use: `npm run slack`
Binary file added docs/images/Bluemix_Solutions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed Materials - Property of IBM
* (C) Copyright IBM Corp. 2016. All Rights Reserved.
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*/
'use strict';

const fs = require('fs');
const path = require('path');

function readScripts(robot) {
const scriptsPath = path.resolve(__dirname, 'src', 'scripts');
fs.access(scriptsPath, fs.R_OK, (err) => {
if (!err) {
fs.readdir(scriptsPath, (err, files) => {
if (!err) {
// For each file, call loadFile, bound to robot, and using `scriptsPath` as the default first arg
files.forEach(robot.loadFile.bind(robot, scriptsPath));
}
});
}
});
}


module.exports = (robot, scripts) => {
robot.logger.info('Executing primary boot subroutine...');
readScripts(robot);
};
Loading