From 00712cc5f87e105430bce19834c6ad96f3372ffa Mon Sep 17 00:00:00 2001 From: David Sanders Date: Sat, 26 Aug 2023 18:49:17 -0700 Subject: [PATCH 1/2] fix: check for token before revoking --- lib/post.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/post.js b/lib/post.js index 2e0319f..b2b9115 100644 --- a/lib/post.js +++ b/lib/post.js @@ -10,11 +10,13 @@ import { request } from "@octokit/request"; export async function post(core, request) { const token = core.getState("token"); - await request("DELETE /installation/token", { - headers: { - authorization: `token ${token}`, - }, - }); - - core.info("Token revoked"); + if (token) { + await request("DELETE /installation/token", { + headers: { + authorization: `token ${token}`, + }, + }); + + core.info("Token revoked"); + } } From 8ff79ca1386e8686510f52674a1578acecd24a34 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Mon, 28 Aug 2023 14:23:02 -0700 Subject: [PATCH 2/2] refactor: exit early Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com> --- lib/post.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/post.js b/lib/post.js index b2b9115..a0efe15 100644 --- a/lib/post.js +++ b/lib/post.js @@ -10,13 +10,13 @@ import { request } from "@octokit/request"; export async function post(core, request) { const token = core.getState("token"); - if (token) { - await request("DELETE /installation/token", { - headers: { - authorization: `token ${token}`, - }, - }); + if (!token) return; - core.info("Token revoked"); - } + await request("DELETE /installation/token", { + headers: { + authorization: `token ${token}`, + }, + }); + + core.info("Token revoked"); }