mirror of
https://code.forgejo.org/docker/actions-toolkit.git
synced 2025-06-24 06:38:23 -04:00
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:
parent
3b6c627995
commit
70326fd842
31 changed files with 5703 additions and 0 deletions
31
src/github.ts
Normal file
31
src/github.ts
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue