File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Octokit } from "@octokit/rest" ;
2+ import { createAppAuth } from "@octokit/auth-app"
3+
4+ export const getAccessToken = async ( ) => {
5+
6+ const { GITHUB_APP_ID , GITHUB_APP_PRIVATE_KEY } = process . env
7+
8+ const octoKitInstance = new Octokit ( {
9+ authStrategy : createAppAuth ,
10+ auth : {
11+ appId : GITHUB_APP_ID ,
12+ privateKey : GITHUB_APP_PRIVATE_KEY
13+ }
14+ } ) ;
15+
16+ const { data : installations } = await octoKitInstance . rest . apps . listInstallations ( )
17+
18+ console . log ( "installations -----" , installations ) ;
19+
20+
21+ if ( ! installations . length ) {
22+ throw new Error ( "No Installations found for this github app" )
23+ }
24+
25+ const installationId = installations [ 0 ] . id ;
26+
27+ const installationAccessToken = await octoKitInstance . rest . apps . createInstallationAccessToken ( { installation_id : installationId } )
28+
29+ return installationAccessToken . data . token
30+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " xero-octokit" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " " ,
5+ "main" : " index.js" ,
6+ "type" : " module" ,
7+ "scripts" : {
8+ "test" : " echo \" Error: no test specified\" && exit 1"
9+ },
10+ "author" : " " ,
11+ "license" : " ISC" ,
12+ "dependencies" : {
13+ "@octokit/auth-app" : " ^7.1.1" ,
14+ "@octokit/rest" : " ^21.0.2"
15+ }
16+ }
You can’t perform that action at this time.
0 commit comments