问题描述
我有docs中的香草probot事件函数,它对新问题进行了评论:
const probotApp = app => {
app.on("issues.opened",async context => {
const params = context.issue({ body: "Hello World!" });
return context.github.issues.createComment(params);
});
}
这很好。
index.js
const { createComment } = require("./src/event/probot.event");
const probotApp = app => {
app.on("issues.opened",createComment);
}
probot.event.js
module.exports.createComment = async context => {
const params = context.issue({ body: "Hello World!" });
return context.github.issues.createComment(params);
};
但是我收到此错误:
ERROR (event): handler is not a function
TypeError: handler is not a function
at C:\Users\User\probot\node_modules\@octokit\webhooks\dist-node\index.js:103:14
at processticksAndRejections (internal/process/task_queues.js:97:5)
at async Promise.all (index 0)
当我使用夹具创建测试as recommended in the docs并使用nock模拟事件webhook调用时,此方法可以正常工作。但是当我在GitHub上创建一个真正的问题时,就会抛出此错误。
解决方法
这是我的错误。
这是整个probot.event.js
文件:
module.exports.createComment = async context => {
const params = context.issue({ body: "Hello World!" });
return context.github.issues.createComment(params);
};
module.exports = app => {
// some other event definitions
}
通过定义module.exports = app
,我重写了先前的module.export。因此,createComment
函数从未导出。
移除module.exports = app = { ... }
可以解决问题!