Commit 86c656fc authored by Farid Neshat's avatar Farid Neshat

Initial commit

parents
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
/node_modules
language: node_js
node_js:
- "0.12"
- "0.10"
- "iojs"
sudo: false
cache:
directories:
- node_modules
notifications:
email: false
# hubot-bamboohr-timeoff
A hubot scripts that adds the ablity to make timeoff requests and their approval
See [`src/bamboohr-timeoff.coffee`](src/bamboohr-timeoff.coffee) for full documentation.
## Installation
In hubot project repo, run:
`npm install hubot-bamboohr-timeoff --save`
Then add **hubot-bamboohr-timeoff** to your `external-scripts.json`:
```json
[
"hubot-bamboohr-timeoff"
]
```
## Sample Interaction
```
user1>> hubot hello
hubot>> hello!
```
## NPM Module
https://www.npmjs.com/package/hubot-bamboohr-timeoff
const fs = require('fs');
const path = require('path');
module.exports = function(robot, scripts) {
const scriptsPath = path.resolve(__dirname, 'src');
if (fs.existsSync(scriptsPath)) {
for (let script of fs.readdirSync(scriptsPath).sort()) {
if (scripts != null && !scripts.includes('*')) {
if (scripts.includes(script)) {
robot.loadFile(scriptsPath, script);
}
} else {
robot.loadFile(scriptsPath, script);
}
}
}
};
This diff is collapsed.
{
"name": "hubot-bamboohr-timeoff",
"description": "A hubot scripts that adds the ablity to make timeoff requests and their approval",
"version": "0.0.0",
"author": "Farid Neshat <FaridN_SOAD@Yahoo.com>",
"license": "MIT",
"keywords": [
"hubot",
"hubot-scripts",
"bamboohr",
"time-off"
],
"repository": {
"type": "git",
"url": "git://github.com/hubot-scripts/hubot-bamboohr-timeoff.git"
},
"bugs": {
"url": "https://github.com/hubot-scripts/hubot-bamboohr-timeoff/issues"
},
"dependencies": {
"coffee-script": "^1.12.7",
"human-interval": "^0.1.6",
"node-bamboohr": "0.0.4",
"sugar": "^2.0.4",
"sugar-date": "^2.0.4"
},
"peerDependencies": {
"hubot": "2.x"
},
"devDependencies": {
"chai": "^4.1.0",
"hubot": "2.x",
"hubot-test-helper": "^1.3.0",
"mocha": "^3.4.2",
"sinon": "^2.4.1",
"sinon-chai": "^2.7.0"
},
"main": "index.coffee",
"scripts": {
"test": "mocha"
}
}
#!/bin/bash
# Make sure everything is development forever
export NODE_ENV=development
# Load environment specific environment variables
if [ -f .env ]; then
source .env
fi
if [ -f .env.${NODE_ENV} ]; then
source .env.${NODE_ENV}
fi
npm install
# Make sure coffee and mocha are on the path
export PATH="node_modules/.bin:$PATH"
\ No newline at end of file
#!/bin/bash
# bootstrap environment
source script/bootstrap
mocha
// Description
// A hubot scripts that adds the ablity to make timeoff requests and their approval
//
// Configuration:
// LIST_OF_ENV_VARS_TO_SET
//
// Commands
// hubot hello - <what the respond trigger does>
// orly - <what the hear trigger does>
//
// Notes:
// <optional notes required for the script>
//
// Author:
// Farid Neshat <FaridN_SOAD@Yahoo.com>
const { Date } = require('sugar-date');
const humanInterval = require('human-interval');
const bamboohr = new (require('node-bamboohr'))({
apikey: process.env.HUBOT_BAMBOOHR_APIKEY,
subdomain: process.env.HUBOT_BAMBOOHR_DOMAIN,
});
const HOUR = 3600000;
const DAY = 24 * 3600000;
const WORKING_HOURS = 8;
const WORKING_DAY_START_HOUR = 8;
const HUMAN_DATE_FORMAT = '{Dow} {Mon} {d}';
module.exports = function(robot) {
robot.respond(/request\s+((\w+?)[\s-]+)?(time-?off|leave|vacation)\s+(from|on)\s+(.+?)\s+for\s+(.+?)\s*(becuase (.+?))?\s*$/i,
res => {
let [,, type, type2,, start, amount, reason] = res.match;
if (type2 === 'vacation') {
type = 'vacation';
}
type = getType(type);
start = Date(Date.create(start, { future: true }));
amount = humanInterval(amount) / DAY;
amount = Math.round(amount);
const end = start.clone().addDays(amount);
if (end.isBefore(end.clone().set({ hour: WORKING_DAY_START_HOUR }, true))) {
end.addDays(-1);
}
if (type.unit === 'hours') {
amount *= WORKING_HOURS;
}
room = res.envelope.user.name;
robot.messageRoom(room, `So you want ${type.shortName} leave from ${
start.format(HUMAN_DATE_FORMAT + ' {yyyy}')} to ${end.format(HUMAN_DATE_FORMAT)} for ${
amount} working ${type.unit}?`);
});
};
function getType() {
return {
shortName: 'vacation',
unit: 'hours',
}
}
// Because hubot-test-helper needs it.
require('coffee-script/register');
const Helper = require('hubot-test-helper');
const sinon = require('sinon');
const chai = require('chai');
chai.use(require('sinon-chai'));
const { expect } = chai;
const sctiptPath = '../src/bamboohr-timeoff.js';
const script = require(sctiptPath);
const helper = new Helper(sctiptPath);
const roomName = '';
const Bamboohr = require('node-bamboohr');
describe('bamboohr-timeoff', function() {
before(function () {
this.timeoffTypes = sinon.stub(Bamboohr.prototype, 'timeOffTypes').yield;
});
after(function () {
this.timeoffTypes.restore();
});
beforeEach(function() {
this.room = helper.createRoom({
name: 'bob',
});
});
afterEach(function() {
this.room.destroy();
});
it('from for', function() {
return this.room.user.say('bob', 'hubot request timeoff from 25 July 2017 for 2 days').then(() => {
expect(this.room.messages[1][1]).to.be.equal('So you want vacation leave from Tue Jul 25' +
' 2017 to Wed Jul 26 for 16 working hours?');
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment