Skip to content

Commit

Permalink
[HUD] Fix workflow dispatcher (#5886)
Browse files Browse the repository at this point in the history
Dunno when this broke, it was before the next update, but fix workflow
dispatcher on HUD

`return void stuff` because after the next update, I was getting `API
handler should not return a value`. Next wanted it to return undefined,
and void somethng is the same as evaluate something and then return
undefined. Ref: vercel/next.js#48951
  • Loading branch information
clee2000 authored Nov 9, 2024
1 parent c5ca645 commit 42c66e9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
7 changes: 3 additions & 4 deletions torchci/components/WorkflowDispatcher.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions torchci/lib/GeneralUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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}`;
Expand All @@ -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
Expand All @@ -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();
}

0 comments on commit 42c66e9

Please sign in to comment.