Skip to content

Commit 42c66e9

Browse files
authored
[HUD] Fix workflow dispatcher (#5886)
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
1 parent c5ca645 commit 42c66e9

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

torchci/components/WorkflowDispatcher.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fetcher, fetcherWithToken } from "lib/GeneralUtils";
1+
import { fetcher } from "lib/GeneralUtils";
22
import { CommitData, JobData } from "lib/types";
33
import _ from "lodash";
44
import { useSession } from "next-auth/react";
@@ -57,11 +57,10 @@ function Workflow({
5757
const url = `/api/github/dispatch/${repoOwner}/${repoName}/${workflow}/${sha}`;
5858
// Only want to tag the commit once https://swr.vercel.app/docs/revalidation
5959
useSWR(
60-
[isClicked && !alreadyRun ? url : null, accessToken],
61-
fetcherWithToken,
60+
isClicked && !alreadyRun ? [url, accessToken] : null,
61+
([url, token]) => fetch(url, { headers: { Authorization: token } }),
6262
{
6363
revalidateOnFocus: false,
64-
revalidateOnMount: false,
6564
revalidateOnReconnect: false,
6665
refreshWhenOffline: false,
6766
refreshWhenHidden: false,

torchci/lib/GeneralUtils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ export function includesCaseInsensitive(
1010
}
1111

1212
export const fetcher = (url: string) => fetch(url).then((res) => res.json());
13-
export const fetcherWithToken = (url: string, token: string) =>
14-
fetch(url, { headers: { Authorization: token } }).then((res) => res.json());
1513

1614
export const getMessage = (
1715
message: string,

torchci/pages/api/github/dispatch/[repoOwner]/[repoName]/[workflow]/[sha].ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default async function handler(
88
) {
99
const authorization = req.headers.authorization;
1010
if (authorization === undefined) {
11-
return res.status(403).end();
11+
return void res.status(403).end();
1212
}
1313

1414
const owner = req.query["repoOwner"] as string;
@@ -21,19 +21,19 @@ export default async function handler(
2121
workflow === undefined ||
2222
sha === undefined
2323
) {
24-
return res.status(400).end();
24+
return void res.status(400).end();
2525
}
2626

2727
// Create an octokit instance using the provided token
2828
const octokit = await getOctokitWithUserToken(authorization as string);
29-
// Return right away if the credential is invalid
29+
// return void right away if the credential is invalid
3030
const user = await octokit.rest.users.getAuthenticated();
3131
if (
3232
user === undefined ||
3333
user.data === undefined ||
3434
user.data.login === undefined
3535
) {
36-
return res.status(403).end();
36+
return void res.status(403).end();
3737
}
3838

3939
const username = user.data.login;
@@ -44,7 +44,7 @@ export default async function handler(
4444
repo
4545
);
4646
if (!hasWritePermissions) {
47-
return res.status(403).end();
47+
return void res.status(403).end();
4848
}
4949

5050
const tag = `ciflow/${workflow}/${sha}`;
@@ -54,7 +54,7 @@ export default async function handler(
5454
ref: `tags/${tag}`,
5555
});
5656
if (matchingRefs !== undefined && matchingRefs.data.length > 0) {
57-
return res.status(200).end();
57+
return void res.status(200).end();
5858
}
5959

6060
// 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(
6767
ref: `refs/tags/${tag}`,
6868
sha: sha,
6969
});
70-
return res.status(result === undefined ? 400 : 200).end();
70+
return void res.status(result === undefined ? 400 : 200).end();
7171
}

0 commit comments

Comments
 (0)