Home > Blockchain >  How can my Github App make github api requests?
How can my Github App make github api requests?

Time:10-29

I have used github API for fetching data like pull requests or commits on a pull request by using the personal access token. But now I'm using Github app and have installed it on the repo for which I want to fetch all prs and commits on a pr.

I can see endpoints github apps are allowed to make requests here - https://docs.github.com/en/rest/overview/endpoints-available-for-github-apps

Is there a way to do this with Github apps without using personal access token?

CodePudding user response:

The approach that I can think of right now is using octokit/rest.js

const appOctokit = new Octokit({
  authStrategy: createAppAuth,
  auth: {
    appId: 123,
    privateKey: process.env.PRIVATE_KEY,
    installationId: 123,
  },
});

const { token } = await appOctokit.auth({
  type: "installation",
  installationId: 123,
});

And, I have to create an appOctokit instance, request a token, and then use it to make HTTP calls to the Github REST API for every event triggered. I am not sure if this is an efficient approach.

CodePudding user response:

I'm also playing with the Github API with an application. The token is a short lived one for security reason so whatever solution you choose, you'll need to recreate one every ~10min. Maybe you can have some cache if you make a lot of call during the 10min frame. Otherwise, I guess you have the proper way to do it. For other readers, the Github documentation is here.

  • Related