From 01c625275409047b969ce02e0014ff8f6d50f6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Quiroz?= Date: Tue, 13 Dec 2022 14:19:57 -0300 Subject: [PATCH] feat: add getLastModifiedDate --- src/utils/getLastModifiedDate.ts | 11 +++++++++++ src/utils/index.ts | 1 + 2 files changed, 12 insertions(+) create mode 100644 src/utils/getLastModifiedDate.ts diff --git a/src/utils/getLastModifiedDate.ts b/src/utils/getLastModifiedDate.ts new file mode 100644 index 0000000000..5b63043bc1 --- /dev/null +++ b/src/utils/getLastModifiedDate.ts @@ -0,0 +1,11 @@ +import { LAST_COMMIT_BASE_URL } from '../constants'; + +export const getLastModifiedDate = async (filePath: string) => + fetch(`${LAST_COMMIT_BASE_URL}${filePath}/index.md&page=1&per_page=1`) + .then(res => res.json()) + .then(commits => commits[0].commit.committer.date) + .catch(_ => + fetch(`${LAST_COMMIT_BASE_URL}${filePath}.md&page=1&per_page=1`) + .then(res => res.json()) + .then(commits => commits[0].commit.committer.date) + ); diff --git a/src/utils/index.ts b/src/utils/index.ts index f950ec7d46..1616b13b8d 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -4,6 +4,7 @@ export { fetchLatestReleaseVersionAndName } from './fetchLatestReleaseVersionAnd export { fetchXMLData } from './fetchXMLData'; export { getChecksum } from './getChecksum'; export { getKebabCaseFromName } from './getKebabCaseFromName'; +export { getLastModifiedDate } from './getLastModifiedDate'; export { getLatestBinaryURL } from './getLatestBinaryURL'; export { getOS } from './getOS'; export { getParsedDate } from './getParsedDate';