-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sangeet-joy_xero
committed
Sep 18, 2024
1 parent
7b219fe
commit 975d497
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {Octokit} from "@octokit/rest"; | ||
import {createAppAuth} from "@octokit/auth-app" | ||
|
||
export const getAccessToken = async () => { | ||
|
||
const {GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY} = process.env | ||
|
||
const octoKitInstance = new Octokit({ | ||
authStrategy: createAppAuth, | ||
auth: { | ||
appId: GITHUB_APP_ID, | ||
privateKey: GITHUB_APP_PRIVATE_KEY | ||
} | ||
}); | ||
|
||
const {data: installations} = await octoKitInstance.rest.apps.listInstallations() | ||
|
||
if(!installations.length) { | ||
throw new Error("No Installations found for this github app") | ||
} | ||
|
||
const installationId = installations[0].id; | ||
|
||
const installationAccessToken = await octoKitInstance.rest.apps.createInstallationAccessToken({installation_id: installationId}) | ||
|
||
return installationAccessToken.data.token | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "xero-octokit", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@octokit/auth-app": "^7.1.1", | ||
"@octokit/rest": "^21.0.2" | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Open API PR check | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '**' | ||
|
||
jobs: | ||
pr-health-check: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout codegen repo | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: xero-internal/xeroapi-sdk-codegen | ||
path: xeroapi-sdk-codegen | ||
|
||
# - name: Install octokit dependencies | ||
# run: npm i | ||
# working-directory: xeroapi-sdk-codegen/.github/octokit | ||
|
||
# - name: Get github app access token | ||
# id: get_access_token | ||
# env: | ||
# GITHUB_APP_ID: ${{ secrets.XERO_GITHUB_APP_ID }} | ||
# GITHUB_APP_PRIVATE_KEY: ${{ secrets.XERO_GITHUB_APPLICATION_KEY }} | ||
# uses: actions/github-script@v7 | ||
# with: | ||
# result-encoding: string | ||
# script: | | ||
# const { getAccessToken } = await import('${{ github.workspace }}/xeroapi-sdk-codegen/.github/octokit/index.js') | ||
# const token = await getAccessToken() | ||
# return token | ||
|
||
# - name: Checkout xero-node repo | ||
# uses: actions/checkout@v4 | ||
# with: | ||
# repository: XeroAPI/xero-node | ||
# path: xero-node | ||
# token: ${{steps.get_access_token.outputs.result}} |