Skip to content

Commit 5770906

Browse files
Merge pull request #970 from github/warn-hubot-scripts
Print warning for loading deprecated hubot-scripts.json
2 parents 741110e + a715457 commit 5770906

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

bin/hubot

+34-1
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,42 @@ else
104104
scriptsPath = Path.resolve "node_modules", "hubot-scripts", "src", "scripts"
105105
robot.loadHubotScripts scriptsPath, scripts
106106
catch err
107-
console.error "Error parsing JSON data from hubot-scripts.json: #{err}"
107+
robot.logger.error "Error parsing JSON data from hubot-scripts.json: #{err}"
108108
process.exit(1)
109109

110+
hubotScriptsWarning = "Loading scripts from hubot-scripts.json is deprecated and " +
111+
"will be removed in 3.0 (https://github.com/github/hubot-scripts/issues/1113) " +
112+
"in favor of packages for each script.\n\n"
113+
114+
if scripts.length is 0
115+
hubotScriptsWarning += "Your hubot-scripts.json is empty, so you just need to remove it."
116+
else
117+
hubotScriptsReplacements = Path.resolve "node_modules", "hubot-scripts", "replacements.json"
118+
119+
if Fs.existsSync(hubotScriptsReplacements)
120+
hubotScriptsWarning += "The following scripts have known replacements. Follow the link for installation instructions, then remove it from hubot-scripts.json:\n"
121+
122+
replacementsData = Fs.readFileSync(hubotScriptsReplacements)
123+
replacements = JSON.parse(replacementsData)
124+
scriptsWithoutReplacements = []
125+
for script in scripts
126+
replacement = replacements[script]
127+
if replacement
128+
hubotScriptsWarning += "* #{script}: #{replacement}\n"
129+
else
130+
scriptsWithoutReplacements.push(script)
131+
hubotScriptsWarning += "\n"
132+
133+
if scriptsWithoutReplacements.length > 0
134+
hubotScriptsWarning += "The following scripts don't have (known) replacements. You can try searching https://www.npmjs.com/ or http://github.com/search or your favorite search engine. You can copy the script into your local scripts directory, or consider creating a new package to maintain yourself. If you find a replacement or create a package yourself, please post on https://github.com/github/hubot-scripts/issues/1641:\n"
135+
hubotScriptsWarning += "* #{script}\n" for script in scriptsWithoutReplacements
136+
137+
hubotScriptsWarning += "\nYou an also try updating hubot-scripts to get the latest list of replacements: npm install --save hubot-scripts@latest"
138+
else
139+
hubotScriptsWarning += "To get a list of recommended replacements, update your hubot-scripts: npm install --save hubot-scripts@latest"
140+
141+
robot.logger.warning hubotScriptsWarning
142+
110143
externalScripts = Path.resolve ".", "external-scripts.json"
111144
if Fs.existsSync(externalScripts)
112145
Fs.readFile externalScripts, (err, data) ->

0 commit comments

Comments
 (0)