Skip to content

Instantly share code, notes, and snippets.

@stahnma
Created June 9, 2022 16:24
Show Gist options
  • Save stahnma/3c292c68325577ccef5c4a9ae28dc335 to your computer and use it in GitHub Desktop.
Save stahnma/3c292c68325577ccef5c4a9ae28dc335 to your computer and use it in GitHub Desktop.
# Description:
# None
#
# Dependencies:
# None
#
# Configuration:
# HUBOT_BRAIN_DIR
#
# Commands:
# None
#
# Author:
# dustyburwell, stahnma
#
# Note:
# Grabbed from https://raw.githubusercontent.com/github/hubot-scripts/master/src/scripts/file-brain.coffee before modification
# Note: this file _must_ be loaded last in order to have the brain working with everything else. Hence, why it starts with the letter z.
#
# Category: workflow
fs = require 'fs'
path = require 'path'
module.exports = (robot) ->
brainPath = process.env.HUBOT_BRAIN_DIR
unless fs.existsSync brainPath
brainPath = process.cwd()
brainPath = path.join brainPath, 'hubot-brain.json'
try
data = fs.readFileSync brainPath, 'utf-8'
if data
robot.brain.mergeData JSON.parse(data)
catch error
console.log('Unable to read file', error) unless error.code is 'ENOENT'
robot.brain.on 'save', (data) ->
fs.writeFileSync brainPath, JSON.stringify(data), 'utf-8'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment