This commit is contained in:
Samuel Attard 2022-05-05 15:28:56 -07:00
Коммит d5045df1f2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7296A7AB7521D713
8 изменённых файлов: 3981 добавлений и 0 удалений

47
.circleci/config.yml Normal file
Просмотреть файл

@ -0,0 +1,47 @@
step-restore-cache: &step-restore-cache
restore_cache:
keys:
- v1-dependencies-{{ arch }}-{{ checksum "yarn.lock" }}
- v1-dependencies-{{ arch }}
steps-test: &steps-test
steps:
- run: git config --global core.autocrlf input
- checkout
- *step-restore-cache
- run: yarn --frozen-lockfile
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ arch }}-{{ checksum "yarn.lock" }}
- run: yarn test
version: 2.1
jobs:
test:
docker:
- image: circleci/node:14.17
<<: *steps-test
release:
docker:
- image: circleci/node:14.17
steps:
- checkout
- *step-restore-cache
- run: yarn
- run: npx semantic-release@17.4.5
workflows:
version: 2
test_and_release:
# Run the test jobs first, then the release only when all the test jobs are successful
jobs:
- test
- release:
requires:
- test
filters:
branches:
only:
- main

2
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,2 @@
dist
node_modules

7
.prettierrc.json Normal file
Просмотреть файл

@ -0,0 +1,7 @@
{
"trailingComma": "all",
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"parser": "typescript"
}

10
.releaserc.json Normal file
Просмотреть файл

@ -0,0 +1,10 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@continuous-auth/semantic-release-npm",
"@semantic-release/github"
],
"branches": [ "main" ]
}

23
package.json Normal file
Просмотреть файл

@ -0,0 +1,23 @@
{
"name": "@electron/github-app-auth",
"version": "0.0.0-development",
"description": "Gets an auth token for a repo via a GitHub app installation",
"main": "dist/index.js",
"author": "Samuel Attard <sam@electronjs.org>",
"license": "MIT",
"scripts": {
"prepublishOnly": "tsc"
},
"devDependencies": {
"@continuous-auth/semantic-release-npm": "^2.0.0",
"@types/node": "^17.0.31",
"typescript": "^4.6.4"
},
"dependencies": {
"@octokit/auth-app": "^3.6.1",
"@octokit/rest": "^18.12.0"
},
"files": [
"dist"
]
}

42
src/index.ts Normal file
Просмотреть файл

@ -0,0 +1,42 @@
import { createAppAuth } from '@octokit/auth-app';
import { Octokit } from '@octokit/rest';
export interface RepoInfo {
owner: string;
name: string;
}
export interface AppCredentials {
appId: string;
privateKey: string;
}
export function appCredentialsFromString(str: string): AppCredentials {
return JSON.parse(Buffer.from(str, 'base64').toString('utf-8')) as any as AppCredentials;
}
export async function getTokenForRepo(repo: RepoInfo, appCreds: AppCredentials) {
const auth = createAppAuth({
appId: appCreds.appId,
privateKey: appCreds.privateKey,
});
const appAuth = await auth({
type: 'app',
});
const octokit = new Octokit({
auth: appAuth.token,
});
const installations = await octokit.apps.listInstallations();
if (installations.data.length !== 1) return null;
if (installations.data[0].account?.login !== repo.owner) return null;
const installationAuth = await auth({
type: 'installation',
installationId: installations.data[0].id,
});
return installationAuth.token;
}

21
tsconfig.json Normal file
Просмотреть файл

@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"lib": [
"es2017"
],
"sourceMap": true,
"strict": true,
"outDir": "dist",
"types": [
"node"
],
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"declaration": true
},
"include": [
"src"
]
}

3829
yarn.lock Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу