From cd96919edd150bac4f961dbf21170d031c076e57 Mon Sep 17 00:00:00 2001 From: Paul Wackerow <54227730+wackerow@users.noreply.github.com> Date: Mon, 6 Feb 2023 12:02:03 -0800 Subject: [PATCH] [website] Fix document commit date fetch (#26622) fix github api commits request refactor using new URL() object format for readability --- src/constants.ts | 3 +-- src/utils/getLastModifiedDate.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index f1bb20137c..1a5d82de5a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -177,8 +177,7 @@ export const LATEST_GETH_RELEASE_URL = 'https://api.github.com/repos/ethereum/go-ethereum/releases/latest'; export const ALL_GETH_COMMITS_URL = 'https://api.github.com/repos/ethereum/go-ethereum/commits/'; export const RELEASE_COMMIT_BASE_URL = 'https://github.com/ethereum/go-ethereum/tree/'; -export const LAST_COMMIT_BASE_URL = - 'https://api.github.com/repos/ethereum/go-ethereum/commits/website?path='; +export const LAST_COMMIT_BASE_URL = 'https://api.github.com/repos/ethereum/go-ethereum/commits'; // Binaries urls export const BINARIES_BASE_URL = 'https://gethstore.blob.core.windows.net/builds/'; diff --git a/src/utils/getLastModifiedDate.ts b/src/utils/getLastModifiedDate.ts index af0598d37e..de773e8f39 100644 --- a/src/utils/getLastModifiedDate.ts +++ b/src/utils/getLastModifiedDate.ts @@ -5,12 +5,19 @@ export const getLastModifiedDate = async (filePath: string) => { // About personal access tokens https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#about-personal-access-tokens Authorization: 'Token ' + process.env.GITHUB_TOKEN_READ_ONLY }); + const urlWithIndex = new URL(LAST_COMMIT_BASE_URL); + urlWithIndex.searchParams.set('path', `${filePath}/index.md`); + urlWithIndex.searchParams.set('page', '1'); + urlWithIndex.searchParams.set('per_page', '1'); + urlWithIndex.searchParams.set('sha', 'website'); + const urlWithoutIndex = new URL(urlWithIndex); + urlWithoutIndex.searchParams.set('path', `${filePath}.md`); - return fetch(`${LAST_COMMIT_BASE_URL}${filePath}/index.md&page=1&per_page=1`, { headers }) + return fetch(urlWithIndex, { headers }) .then(res => res.json()) .then(commits => commits[0].commit.committer.date) .catch(_ => - fetch(`${LAST_COMMIT_BASE_URL}${filePath}.md&page=1&per_page=1`, { headers }) + fetch(urlWithoutIndex, { headers }) .then(res => res.json()) .then(commits => commits[0].commit.committer.date) .catch(console.error)