代码之家  ›  专栏  ›  技术社区  ›  TKrugg

是否可以在应用程序的init上使用“context”执行操作?

  •  0
  • TKrugg  · 技术社区  · 7 年前

    我只是在找这样的东西

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

    基本上我只需要对githubapi进行调用,但是我不确定有没有一种方法不在Context对象中使用API客户机就可以做到这一点。

    2 回复  |  直到 7 年前
        1
  •  0
  •   TKrugg    7 年前

    我最后使用了probot调度程序

    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
      })
    }
        2
  •  0
  •   limco    7 年前

    我尝试了probot调度程序,但它不存在-可能在更新中删除?

    app 对象-它是 .auth() 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。如果调用为空,客户端将只能检索公共数据。

    .auth() listInstallations() :

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

    你会得到一个数组,其中包含你可以输入的ID .auth()

    推荐文章