1

I am trying to build a GitHub App and following the https://probot.github.io/docs/ and https://octokit.github.io/rest.js/v17#authentication. It is basically a nodejs app.

I have no experience working with nodejs or typescript and not even the probot framework.

The PRIVATE_KEY_PATH is in the .env file as follows:

PRIVATE_KEY_PATH=my-app.2020-04-03.private-key.pem

The .pem file is in the root directory of the project

The typeof prints string : -------------TypeOf token ---- string

index.js

/**
 * This is the main entrypoint to your Probot app
 * @param {import('probot').Application} app
 */



        const{Octokit} = require("@octokit/rest");
        const{createAppAuth} = require("@octokit/auth-token");

         console.log('PRIVATE_KEY',process.env.PRIVATE_KEY_PATH);
         console.log('-------------TypeOf token ----', typeof process.env.PRIVATE_KEY_PATH)

         const appOctokit = new Octokit({
           authStrategy:createAppAuth,
           auth:{
             id:12345,
             privateKey: process.env.PRIVATE_KEY_PATH,
            //  privateKey: 'token ${process.env.PRIVATE_KEY_PATH}'
            }
         });

I keep getting below error :

10:52:51.166Z ERROR probot: [@octokit/auth-token] Token passed to createTokenAuth is not a string

Not able to find much help on this topic over teh internet. I even tried navigating the code of octokit https://github.com/octokit/auth-token.js/blob/master/src/index.ts and it seems I am doing nothing wrong in my code.

There are not much resources to refer for issues for GitHub Apps or probot framework apart from the documentations. StackOverflow too ha just about 20-30 questions related to GitHub Apps or probot framework.

EDIT 1 : START

Running below code :

/**
 * This is the main entrypoint to your Probot app
 * @param {import('probot').Application} app
 */

 const{Octokit} = require("@octokit/rest");

 const{createAppAuth} = require("@octokit/auth-token");

 console.log('PRIVATE_KEY',process.env.PRIVATE_KEY_PATH);
 console.log('-------------TypeOf token ----', typeof process.env.PRIVATE_KEY_PATH)

produces a below error:

ERROR probot: appFn is not a function
  TypeError: appFn is not a function

EDIT 1 : END

Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47

1 Answers1

1

If you use Probot, you don't need to load your own @octokit/rest or any of the @octokit/auth-* packages, it's all built into Probot

Did you try the example code shown on https://probot.github.io/

module.exports = app => {
  app.on('issues.opened', async context => {
    const params = context.issue({
      body: 'Hello World!'
    })
    await context.github.issues.createComment(params)
  })
}

Probot will automatically read the contents of your .env file, look for the PRIVATE_KEY_PATH environment variable, read out the contents of the file at that location, and setup the JWT/installation authentication for you

Gregor
  • 2,325
  • 17
  • 27
  • Thank you so much for your guidance. I really appreciate that. To be honest, I being a beginner in this GitHub App world personally faced lot of problems while going through the documentation. The documentations are quite detailed but I think they are somewhat not beginner friendly. Speaking of myself, I was not able to connect the dots. Thanks to the automatic code completions of VSCode, I got some hints as to which methods /properties are available for a particular probot object. You also mentioned that @octokit/rest and @octokit/auth-* were needless. – Asif Kamran Malick Apr 06 '20 at 23:37
  • Building upon these ideas and hints, I linked back to the https://octokit.github.io/rest.js/v17 and tried to figure what the probot equivalent of octokit/rest.js would be. private key is also getting recognized by my app. I am now able to successfully create a pull request. Things look somewhat sorted now. Able to connect some dots. – Asif Kamran Malick Apr 06 '20 at 23:37