I'm simply looking for something like this

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

Basically I just need to make to calls to the github API, but I'm not sure there is a way to do it without using the API client inside the Context object.

2 Answers

I ended up using 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 }) }

I tried probot-scheduler but it didn't exist - perhaps removed in an update?

In any case, I managed to do it after lots of digging by using the actual app object - it's .auth() method returns a promise containing the GitHubAPI interface:

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() takes the ID of the installation if you wish to access private data. If called empty, the client will can only retrieve public data.

You can get the installation ID by calling .auth() without paramaters, and then listInstallations():

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

You get an array including IDs that you can in .auth().

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy