Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
push:
branches: ["main"]
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Check formatting
run: deno fmt --check *.ts

- name: Lint
run: deno lint

cli-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Test CLI
run: |
deno run --allow-net ./cli.ts \
${{ secrets.APP_ID }} \
${{ secrets.APP_PRIVATE_KEY_BASE64 }} \
${{ secrets.APP_INSTALLATION_ID }} \
| gh auth login --with-token

gh auth status
gh api 'installation/repositories' -q '.repositories[].name' | grep 'scala-template'
6 changes: 3 additions & 3 deletions cli.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env deno run --allow-net=api.github.com

import { appJwt } from "./jwt.ts";
import { listInstallations, createInstallationToken } from "./request.ts";
import { createInstallationToken, listInstallations } from "./request.ts";

const [appId, privateKey, installationId, ...repositories] = Deno.args;
if (Deno.args.length < 2) {
console.log(
"Usage: github-app-auth <app-id> <private-key-base64-encoded> [installation-id [repositories ...]]"
"Usage: github-app-auth <app-id> <private-key-base64-encoded> [installation-id [repositories ...]]",
);
Deno.exit(1);
}
Expand All @@ -20,7 +20,7 @@ if (!installationId) {
const response = await createInstallationToken(
jwt,
installationId,
...repositories
...repositories,
);
console.log(response.token);
}
2 changes: 1 addition & 1 deletion jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export function appJwt(appId: string, privateKey: string): Promise<string> {
iat: getNumericDate(0), // issued at time (now)
exp: getNumericDate(5 * 60), // expiration time (in 5 minutes)
},
atob(privateKey)
atob(privateKey),
);
}
1 change: 1 addition & 0 deletions request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ async function githubApiUrl() {
export async function appRequest(
jwt: string,
endpoint: string,
// deno-lint-ignore no-explicit-any
params?: Record<string, any>,
) {
const apiUrl = await githubApiUrl();
Expand Down