diff --git a/torchci/components/WorkflowDispatcher.tsx b/torchci/components/WorkflowDispatcher.tsx index 30f721843b..ca49fac924 100644 --- a/torchci/components/WorkflowDispatcher.tsx +++ b/torchci/components/WorkflowDispatcher.tsx @@ -1,4 +1,4 @@ -import { fetcher, fetcherWithToken } from "lib/GeneralUtils"; +import { fetcher } from "lib/GeneralUtils"; import { CommitData, JobData } from "lib/types"; import _ from "lodash"; import { useSession } from "next-auth/react"; @@ -57,11 +57,10 @@ function Workflow({ const url = `/api/github/dispatch/${repoOwner}/${repoName}/${workflow}/${sha}`; // Only want to tag the commit once https://swr.vercel.app/docs/revalidation useSWR( - [isClicked && !alreadyRun ? url : null, accessToken], - fetcherWithToken, + isClicked && !alreadyRun ? [url, accessToken] : null, + ([url, token]) => fetch(url, { headers: { Authorization: token } }), { revalidateOnFocus: false, - revalidateOnMount: false, revalidateOnReconnect: false, refreshWhenOffline: false, refreshWhenHidden: false, diff --git a/torchci/lib/GeneralUtils.ts b/torchci/lib/GeneralUtils.ts index 752853dbb5..cc8fc244af 100644 --- a/torchci/lib/GeneralUtils.ts +++ b/torchci/lib/GeneralUtils.ts @@ -10,8 +10,6 @@ export function includesCaseInsensitive( } export const fetcher = (url: string) => fetch(url).then((res) => res.json()); -export const fetcherWithToken = (url: string, token: string) => - fetch(url, { headers: { Authorization: token } }).then((res) => res.json()); export const getMessage = ( message: string, diff --git a/torchci/pages/api/github/dispatch/[repoOwner]/[repoName]/[workflow]/[sha].ts b/torchci/pages/api/github/dispatch/[repoOwner]/[repoName]/[workflow]/[sha].ts index 331147c371..91351a110f 100644 --- a/torchci/pages/api/github/dispatch/[repoOwner]/[repoName]/[workflow]/[sha].ts +++ b/torchci/pages/api/github/dispatch/[repoOwner]/[repoName]/[workflow]/[sha].ts @@ -8,7 +8,7 @@ export default async function handler( ) { const authorization = req.headers.authorization; if (authorization === undefined) { - return res.status(403).end(); + return void res.status(403).end(); } const owner = req.query["repoOwner"] as string; @@ -21,19 +21,19 @@ export default async function handler( workflow === undefined || sha === undefined ) { - return res.status(400).end(); + return void res.status(400).end(); } // Create an octokit instance using the provided token const octokit = await getOctokitWithUserToken(authorization as string); - // Return right away if the credential is invalid + // return void right away if the credential is invalid const user = await octokit.rest.users.getAuthenticated(); if ( user === undefined || user.data === undefined || user.data.login === undefined ) { - return res.status(403).end(); + return void res.status(403).end(); } const username = user.data.login; @@ -44,7 +44,7 @@ export default async function handler( repo ); if (!hasWritePermissions) { - return res.status(403).end(); + return void res.status(403).end(); } const tag = `ciflow/${workflow}/${sha}`; @@ -54,7 +54,7 @@ export default async function handler( ref: `tags/${tag}`, }); if (matchingRefs !== undefined && matchingRefs.data.length > 0) { - return res.status(200).end(); + return void res.status(200).end(); } // NB: OAuth token could not be used to create a tag atm due to PyTorch org restriction. So we need to use @@ -67,5 +67,5 @@ export default async function handler( ref: `refs/tags/${tag}`, sha: sha, }); - return res.status(result === undefined ? 400 : 200).end(); + return void res.status(result === undefined ? 400 : 200).end(); }