initial implementation

carries most of the logic used across our actions

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-01-17 11:53:57 +01:00
parent 3b6c627995
commit 70326fd842
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
31 changed files with 5703 additions and 0 deletions

31
src/github.ts Normal file
View file

@ -0,0 +1,31 @@
import jwt_decode, {JwtPayload} from 'jwt-decode';
import * as github from '@actions/github';
import {Context} from '@actions/github/lib/context';
import {components as OctoOpenApiTypes} from '@octokit/openapi-types';
import * as util from './util';
export type ReposGetResponseData = OctoOpenApiTypes['schemas']['repository'];
export function context(): Context {
return github.context;
}
export async function repo(token: string): Promise<ReposGetResponseData> {
return github
.getOctokit(token)
.rest.repos.get({...github.context.repo})
.then(response => response.data as ReposGetResponseData);
}
interface Jwt extends JwtPayload {
ac?: string;
}
export const parseRuntimeToken = (token: string): Jwt => {
return jwt_decode<Jwt>(token);
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function fromPayload(path: string): any {
return util.select(github.context.payload, path);
}