Skip to content

Commit

Permalink
v0.7.5 - Merge branch 'master' into release-beta
Browse files Browse the repository at this point in the history
Added more comprehensive testing and improved documentation
  • Loading branch information
aaronsky committed Mar 18, 2016
2 parents f20a7ed + 61657ee commit ec62072
Show file tree
Hide file tree
Showing 22 changed files with 883 additions and 130 deletions.
136 changes: 136 additions & 0 deletions coffeelint_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"arrow_spacing": {
"level": "ignore"
},
"braces_spacing": {
"level": "ignore",
"spaces": 0,
"empty_object_spaces": 0
},
"camel_case_classes": {
"level": "error"
},
"coffeescript_error": {
"level": "error"
},
"colon_assignment_spacing": {
"level": "ignore",
"spacing": {
"left": 0,
"right": 0
}
},
"cyclomatic_complexity": {
"level": "ignore",
"value": 10
},
"duplicate_key": {
"level": "error"
},
"empty_constructor_needs_parens": {
"level": "ignore"
},
"ensure_comprehensions": {
"level": "warn"
},
"eol_last": {
"level": "ignore"
},
"indentation": {
"value": 2,
"level": "error"
},
"line_endings": {
"level": "ignore",
"value": "unix"
},
"max_line_length": {
"value": 80,
"level": "error",
"limitComments": true,
"level": "warn"
},
"missing_fat_arrows": {
"level": "ignore",
"is_strict": false
},
"newlines_after_classes": {
"value": 3,
"level": "ignore"
},
"no_backticks": {
"level": "error"
},
"no_debugger": {
"level": "warn",
"console": false
},
"no_empty_functions": {
"level": "ignore"
},
"no_empty_param_list": {
"level": "ignore"
},
"no_implicit_braces": {
"level": "ignore",
"strict": true
},
"no_implicit_parens": {
"level": "ignore",
"strict": true
},
"no_interpolation_in_single_quotes": {
"level": "ignore"
},
"no_nested_string_interpolation": {
"level": "warn"
},
"no_plusplus": {
"level": "ignore"
},
"no_private_function_fat_arrows": {
"level": "warn"
},
"no_stand_alone_at": {
"level": "ignore"
},
"no_tabs": {
"level": "error"
},
"no_this": {
"level": "ignore"
},
"no_throwing_strings": {
"level": "error"
},
"no_trailing_semicolons": {
"level": "error"
},
"no_trailing_whitespace": {
"level": "error",
"allowed_in_comments": false,
"allowed_in_empty_lines": true
},
"no_unnecessary_double_quotes": {
"level": "ignore"
},
"no_unnecessary_fat_arrows": {
"level": "warn"
},
"non_empty_constructor_needs_parens": {
"level": "ignore"
},
"prefer_english_operator": {
"level": "ignore",
"doubleNotLevel": "ignore"
},
"space_operators": {
"level": "ignore"
},
"spacing_after_comma": {
"level": "ignore"
},
"transform_messes_up_line_numbers": {
"level": "warn"
}
}
3 changes: 2 additions & 1 deletion external-scripts.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[
"hubot-help"
"hubot-help",
"hubot-history"
]
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
"url": "https://github.com/aaronsky/ibizan.git"
},
"dependencies": {
"google-spreadsheet": "^1.1.3",
"google-spreadsheet": "^2.0.0",
"hubot": "^2.18.0",
"hubot-help": "^0.1.3",
"hubot-history": "^1.0.0",
"hubot-slack": "^3.4.2",
"moment": "^2.11.2",
"moment-timezone": "^0.5.0",
Expand All @@ -43,7 +44,7 @@
"scripts": {
"start": "./bin/ibizan",
"ibizan": "./bin/ibizan",
"test": "mocha --compilers \"coffee:coffee-script/register\" ./tests/**/* && exit 0",
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --compilers coffee:coffee-script/register --require coffee-coverage/register-istanbul --recursive ./tests/**/*"
"test": "DEBUG=false mocha --compilers \"coffee:coffee-script/register\" ./tests/**/test_* && exit 0",
"coverage": "DEBUG=false ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --compilers coffee:coffee-script/register --require coffee-coverage/register-istanbul --recursive ./tests/**/test_*"
}
}
61 changes: 37 additions & 24 deletions src/helpers/logger.coffee
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@

if debugEnvStr = process.env.DEBUG
if typeof debugEnvStr is 'string'
debugEnvStr = debugEnvStr.toLowerCase()
DEBUG = debugEnvStr is 'true'
else
DEBUG = true
else
DEBUG = true

module.exports = (robot) ->
class Logger
constructor: () ->
@log: (msg) ->
console.log "[Ibizan] (#{new Date()}) LOG: #{msg}"
if DEBUG
console.log "[Ibizan] (#{new Date()}) LOG: #{msg}"
@warn: (msg) ->
console.warn "[Ibizan] (#{new Date()}) WARN: #{msg}"
if DEBUG
console.warn "[Ibizan] (#{new Date()}) WARN: #{msg}"
@error: (msg, error) ->
console.error "[Ibizan] (#{new Date()}) ERROR: #{msg}", error || ''
if DEBUG
console.error "[Ibizan] (#{new Date()}) ERROR: #{msg}", error || ''
@logToChannel: (msg, channel) ->
if robot
robot.send {room: channel}, msg
else
Logger.log msg
if DEBUG
if robot
robot.send {room: channel}, msg
else
Logger.log msg
@errorToSlack: (msg, error) ->
if robot
robot.send {room: 'ibizan-diagnostics'},
"(#{new Date()}) ERROR: #{msg}\n#{error || ''}"
else
Logger.error msg, error
if DEBUG
if robot
robot.send {room: 'ibizan-diagnostics'},
"(#{new Date()}) ERROR: #{msg}\n#{error || ''}"
else
Logger.error msg, error
@reactToMessage: (reaction, user, channel, slack_ts) ->
if robot and
robot.adapter and
client = robot.adapter.client
params =
name: reaction,
channel: channel,
timestamp: slack_ts
client._apiCall 'reactions.add', params, (response) ->
if not response.ok
Logger.logToChannel response.error, user


if DEBUG
if robot and
robot.adapter and
client = robot.adapter.client
params =
name: reaction,
channel: channel,
timestamp: slack_ts
client._apiCall 'reactions.add', params, (response) ->
if not response.ok
Logger.logToChannel response.error, user
Logger
31 changes: 19 additions & 12 deletions src/models/organization.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,33 @@ class Calendar
description: () ->
str = "Organization calendar:\n"
for holiday in @holidays
str += "This year's #{holiday.name} is on #{holiday.date.format('MM/DD/YYYY')}\n"
str += "This year's #{holiday.name} is on
#{holiday.date.format('MM/DD/YYYY')}\n"
return str

# Singleton
class Organization
instance = null

class OrganizationPrivate
constructor: (@name = NAME) ->
if CONFIG.sheet_id
@spreadsheet = new Spreadsheet(CONFIG.sheet_id)
constructor: (id) ->
@name = NAME || 'Bad user'
sheet_id = id || CONFIG.sheet_id
if sheet_id
@spreadsheet = new Spreadsheet(sheet_id)
Logger.log "Welcome to #{@name}!"
@initTime = moment()
@sync()
.done(() -> Logger.log('Options loaded'))
if @spreadsheet.sheet
@sync().done(() -> Logger.log('Options loaded'))
else
Logger.warn 'Sheet not initialized, no spreadsheet ID was provided'
sync: () ->
ready: () ->
if @spreadsheet
return @spreadsheet.initialized
return false
sync: (auth) ->
deferred = Q.defer()
@spreadsheet.authorize(CONFIG.auth)
@spreadsheet.authorize(auth || CONFIG.auth)
.then(@spreadsheet.loadOptions.bind(@spreadsheet))
.then(
(opts) =>
Expand All @@ -59,15 +66,15 @@ class Organization
for user in users
if name is user.slack
return user
Logger.log "user #{name} could not be found"
Logger.log "User #{name} could not be found"
getUserByRealName: (name, users) ->
if not users
users = @users
if users
for user in users
if name is user.name
return user
Logger.log "user #{name} could not be found"
Logger.log "User #{name} could not be found"
getProjectByName: (name, projects) ->
if not projects
projects = @projects
Expand All @@ -91,8 +98,8 @@ class Organization
user.shouldHound = true
i += 1
i
@get: () ->
instance ?= new OrganizationPrivate()
@get: (id) ->
instance ?= new OrganizationPrivate(id)
instance

module.exports = Organization
21 changes: 14 additions & 7 deletions src/models/punch.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Punch
punch.elapsed = elapsed
punch

@parseRaw: (user, row) ->
@parseRaw: (user, row, projects = []) ->
if not user
return
else if not row
Expand Down Expand Up @@ -96,7 +96,7 @@ class Punch
comps = row[headers.blockTime].split ':'
block = parseInt(comps[0]) + (parseFloat(comps[1]) / 60)
datetimes.block = block
projects = []
foundProjects = []
for i in [1..6]
projectStr = row[headers['project'+i]]
if not projectStr
Expand All @@ -105,13 +105,20 @@ class Punch
projectStr is 'sick' or
projectStr is 'unpaid'
break
else if project = Organization.getProjectByName projectStr
projects.push project
continue
else
break
if Organization.ready() and projects.length is 0
project = Organization.getProjectByName projectStr
else if projects.length > 0
project = projects.filter((item, index, arr) ->
return item.name is projectStr
)[0]
if project
foundProjects.push project
continue
else
break
notes = row[headers.notes]
punch = new Punch(mode, datetimes, projects, notes)
punch = new Punch(mode, datetimes, foundProjects, notes)
if elapsed
punch.elapsed = elapsed
punch.assignRow row
Expand Down

0 comments on commit ec62072

Please sign in to comment.