[website] Fix document commit date fetch (#26622)

fix github api commits request

refactor using new URL() object format for readability
This commit is contained in:
Paul Wackerow 2023-02-06 12:02:03 -08:00 committed by GitHub
parent dc5d16a399
commit cd96919edd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -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/';

View File

@ -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)