我有来自文档的普通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)当我用一个夹具创建一个测试如文档中所建议的并用nock模拟事件webhook调用时,这个方法工作得很好。但是,当我在GitHub上创建一个真正的问题时,就会抛出这个错误。
如何在不引起错误的情况下将代码重构为单独的文件?
发布于 2020-09-22 09:09:42
这是我的错。
这是整个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 = { ... }修复了它!
https://stackoverflow.com/questions/64005977
复制相似问题