嗨,我正在尝试为 hubot 编写插件脚本。我似乎对范围界定有疑问。fork 回调中“msg”的引用是未定义的,我似乎没有在回调中得到任何变量。
内置的 jira-issues.coffee 也有同样的问题!昨天在该脚本中,jiraUrl 在回调中未定义。今天早上它再次工作,现在它再次停止工作(在我重新启动hubot之后)。我什至从未修改过它。
有没有人经历过这样的事情?
githubApi = require("node-github")
module.exports = (robot) ->
github = new githubApi { "version": "3.0.0" }
github.authenticate { "type":"basic", "username":process.env.HUBOT_GITHUB_USER, "password":process.env.HUBOT_GITHUB_P
ASSWORD }
robot.respond /kickstart\s(\S+)/i, (msg) ->
name = msg.match[1]
msg.send name
base_url = process.env.HUBOT_GITHUB_API || 'https://api.github.com'
github.repos.fork {"user":"Raven", "repo":"Raven","org":"codedemos"}, (err,data) ->
if err
msg.send "error :("
else
msg.send "Fork Complete..."
它编译为
// Generated by CoffeeScript 1.6.3
(function() {
var githubApi;
githubApi = require("node-github");
module.exports = function(robot) {
var github;
github = new githubApi({
"version": "3.0.0"
});
github.authenticate({
"type": "basic",
"username": process.env.HUBOT_GITHUB_USER,
"password": process.env.HUBOT_GITHUB_PASSWORD
});
return robot.respond(/kickstart\s(\S+)/i, function(msg) {
var base_url, name;
name = msg.match[1];
msg.send(name);
base_url = process.env.HUBOT_GITHUB_API || 'https://api.github.com';
return github.repos.fork({
"user": "Raven",
"repo": "Raven",
"org": "codedemos"
}, function(err, data) {
var id;
if (err) {
return msg.send("error :(");
} else {
return id = data.id;
}
});
});
};
msg.send("Fork Complete...");
}).call(this);
看起来不错,但运行它会产生:
ReferenceError: msg is not defined
at Object.<anonymous> (/opt/kbot/scripts/kickstart.coffee:48:2, <js>:36:3)
at Object.<anonymous> (/opt/kbot/scripts/kickstart.coffee:33:1, <js>:38:4)
at Module._compile (module.js:456:26)