Created
August 11, 2020 19:37
-
-
Save smarr/317e83149bb564e54dc2b662a312ae03 to your computer and use it in GitHub Desktop.
Revisions
-
smarr revised this gist
Aug 11, 2020 . No changes.There are no files selected for viewing
-
smarr created this gist
Aug 11, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ import { Octokit } from '@octokit/rest'; import { createAppAuth } from '@octokit/auth-app'; import { readFileSync } from 'fs'; // authorize on app level const app = new Octokit({ authStrategy: createAppAuth, auth: { type: "app", id: 12345, privateKey: readFileSync('app-private-key.pem') } }); async function start() { // get the installation id const install = await app.apps.getRepoInstallation({ owner: 'owner', repo: 'repo' }); // authorize on repo level const appInstall = new Octokit({ authStrategy: createAppAuth, auth: { type: "install", id: 12345, privateKey: readFileSync('app-private-key.pem') installationId: install.data.id } }); // create a comment on a commit, it normally will show on on related PRs let result = await appInstall.repos.createCommitComment({ // or perhaps comment on an issue/PR // let result = await appInstall.issues.createComment({ // issue_number: 42, owner: 'owner', repo: 'repo', commit_sha: 'sha', body:`### Test This is test with markdown. Let's see whether it works.`}); console.log('got result: '); console.log(result); } start().then(() => console.log('done')).catch(e => { console.error(e) });