From 0e5f8a766ae6d1cf13feeec1ff95956ae675762a Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sat, 28 Oct 2023 02:37:52 +0200 Subject: [PATCH] github: fix jwt-decode import and test Signed-off-by: CrazyMax --- __tests__/github.test.ts | 2 +- src/github.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/github.test.ts b/__tests__/github.test.ts index f992db1..c065cca 100644 --- a/__tests__/github.test.ts +++ b/__tests__/github.test.ts @@ -138,7 +138,7 @@ describe('printActionsRuntimeTokenACs', () => { }); it('malformed', async () => { process.env.ACTIONS_RUNTIME_TOKEN = 'foo'; - await expect(GitHub.printActionsRuntimeTokenACs()).rejects.toThrow(new Error("Cannot parse GitHub Actions Runtime Token: Invalid token specified: Cannot read properties of undefined (reading 'replace')")); + await expect(GitHub.printActionsRuntimeTokenACs()).rejects.toThrow(new Error('Cannot parse GitHub Actions Runtime Token: Invalid token specified: missing part #2')); }); it('refs/heads/master', async () => { const infoSpy = jest.spyOn(core, 'info'); diff --git a/src/github.ts b/src/github.ts index e7b8e1c..d49f0ac 100644 --- a/src/github.ts +++ b/src/github.ts @@ -18,7 +18,7 @@ import {GitHub as Octokit} from '@actions/github/lib/utils'; import * as core from '@actions/core'; import * as github from '@actions/github'; import {Context} from '@actions/github/lib/context'; -import jwt_decode from 'jwt-decode'; +import {jwtDecode, JwtPayload} from 'jwt-decode'; import {GitHubActionsRuntimeToken, GitHubActionsRuntimeTokenAC, GitHubRepo} from './types/github'; @@ -51,7 +51,7 @@ export class GitHub { static get actionsRuntimeToken(): GitHubActionsRuntimeToken | undefined { const token = process.env['ACTIONS_RUNTIME_TOKEN'] || ''; - return token ? jwt_decode(token) : undefined; + return token ? (jwtDecode(token) as GitHubActionsRuntimeToken) : undefined; } public static async printActionsRuntimeTokenACs() {