是否可以在应用程序初始化时使用 `context` 执行操作?

Is it possible to perform an action with `context` on the init of the app?

我只是在寻找这样的东西

app.on('init', async context => {
 ...
})

基本上我只需要调用 github API,但我不确定是否有办法在不使用 API 客户端的情况下完成上下文对象。

我最终使用了 probot-scheduler

const createScheduler = require('probot-scheduler')
module.exports = app => {

  createScheduler(app, {
    delay: false
  })
  robot.on('schedule.repository', context => {
    // this is called on startup and can access context
  })
}

我试过 probot-scheduler 但它不存在 - 可能在更新中被删除了?

无论如何,我通过使用实际的 app 对象进行了大量挖掘后设法做到了 - 它是 .auth() 方法 returns 包含 GitHubAPI 接口的承诺: https://probot.github.io/api/latest/classes/application.html#auth

module.exports = app => {
    router.get('/hello-world', async (req, res) => {
        const github = await app.auth();
        const result = await github.repos.listForOrg({'org':'org name});
        console.log(result);
    })
}
如果您想访问私有数据,

.auth() 会使用安装 ID。如果调用为空,客户端将只能检索 public 数据。

不带参数调用.auth()即可获取安装ID,然后listInstallations():

const github = await app.auth();
const result = github.apps.listInstallations();
console.log(result);

您会得到一个包含 ID 的数组,您可以在 .auth().