From dda93ec49bb654d0dd015b58e89ee52c33894c64 Mon Sep 17 00:00:00 2001 From: Nurlan Moldomurov Date: Thu, 5 Dec 2024 16:32:47 +0300 Subject: [PATCH 1/5] PMM-7 test override --- .../components/source/facts/github/index.ts | 104 ++++++++++++++++++ .../javascripts/templates/source/index.tsx | 47 ++++++++ 2 files changed, 151 insertions(+) create mode 100644 overrides/assets/javascripts/components/source/facts/github/index.ts create mode 100644 overrides/assets/javascripts/templates/source/index.tsx diff --git a/overrides/assets/javascripts/components/source/facts/github/index.ts b/overrides/assets/javascripts/components/source/facts/github/index.ts new file mode 100644 index 0000000000..d76945dcf3 --- /dev/null +++ b/overrides/assets/javascripts/components/source/facts/github/index.ts @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2016-2024 Martin Donath + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +import { Repo, User } from "github-types" +import { + EMPTY, + Observable, + catchError, + defaultIfEmpty, + map, + zip +} from "rxjs" + +import { requestJSON } from "~/browser" + +import { SourceFacts } from "../_" + +/* ---------------------------------------------------------------------------- + * Helper types + * ------------------------------------------------------------------------- */ + +/** + * GitHub release (partial) + */ +interface Release { + tag_name: string /* Tag name */ +} + +/* ---------------------------------------------------------------------------- + * Functions + * ------------------------------------------------------------------------- */ + +/** + * Fetch GitHub repository facts + * + * @param user - GitHub user or organization + * @param repo - GitHub repository + * + * @returns Repository facts observable + */ +export function fetchSourceFactsFromGitHub( + user: string, repo?: string +): Observable { + if (typeof repo !== "undefined") { + const url = `https://api.github.com/repos/${user}/${repo}` + return zip( + + /* Fetch version */ + requestJSON(`${url}/releases/latest`) + .pipe( + catchError(() => EMPTY), // @todo refactor instant loading + map(release => ({ + version: release.tag_name + })), + defaultIfEmpty({}) + ), + + /* Fetch stars and forks */ + requestJSON(url) + .pipe( + catchError(() => EMPTY), // @todo refactor instant loading + map(info => ({ + version: "v3.0.0-BETA", + stars: info.stargazers_count, + forks: info.forks_count + })), + defaultIfEmpty({}) + ) + ) + .pipe( + map(([release, info]) => ({ ...release, ...info })) + ) + + /* User or organization */ + } else { + const url = `https://api.github.com/users/${user}` + return requestJSON(url) + .pipe( + map(info => ({ + repositories: info.public_repos + })), + defaultIfEmpty({}) + ) + } +} \ No newline at end of file diff --git a/overrides/assets/javascripts/templates/source/index.tsx b/overrides/assets/javascripts/templates/source/index.tsx new file mode 100644 index 0000000000..6f08d911cd --- /dev/null +++ b/overrides/assets/javascripts/templates/source/index.tsx @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016-2024 Martin Donath + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +import { SourceFacts } from "~/components" +import { h, round } from "~/utilities" + +/* ---------------------------------------------------------------------------- + * Functions + * ------------------------------------------------------------------------- */ + +/** + * Render repository facts + * + * @param facts - Repository facts + * + * @returns Element + */ +export function renderSourceFacts(facts: SourceFacts): HTMLElement { + return ( +
    + {Object.entries(facts).map(([key, value]) => ( +
  • + {typeof value === "number" ? round(value) : (key == "version" ? "3.0.0-Beta - "+value : value)} +
  • + ))} +
+ ) +} \ No newline at end of file From 8827fbaa13bed988b2670d9744e3811917a8627f Mon Sep 17 00:00:00 2001 From: Nurlan Moldomurov Date: Thu, 5 Dec 2024 16:52:02 +0300 Subject: [PATCH 2/5] PMM-7 test override --- overrides/partials/javascripts/base.html | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 overrides/partials/javascripts/base.html diff --git a/overrides/partials/javascripts/base.html b/overrides/partials/javascripts/base.html new file mode 100644 index 0000000000..a7f011b1f7 --- /dev/null +++ b/overrides/partials/javascripts/base.html @@ -0,0 +1,51 @@ + + + + \ No newline at end of file From 2cf1bb03fb39e9ccdc012966cfd4850607cf8c36 Mon Sep 17 00:00:00 2001 From: Nurlan Moldomurov Date: Thu, 5 Dec 2024 17:10:24 +0300 Subject: [PATCH 3/5] PMM-7 test override --- docs/js/repo-version.js | 14 +++ mkdocs-base.yml | 1 + .../components/source/facts/github/index.ts | 104 ------------------ .../javascripts/templates/source/index.tsx | 47 -------- overrides/partials/javascripts/base.html | 51 --------- 5 files changed, 15 insertions(+), 202 deletions(-) create mode 100644 docs/js/repo-version.js delete mode 100644 overrides/assets/javascripts/components/source/facts/github/index.ts delete mode 100644 overrides/assets/javascripts/templates/source/index.tsx delete mode 100644 overrides/partials/javascripts/base.html diff --git a/docs/js/repo-version.js b/docs/js/repo-version.js new file mode 100644 index 0000000000..f9d0f4d2e8 --- /dev/null +++ b/docs/js/repo-version.js @@ -0,0 +1,14 @@ + +var xhr = new XMLHttpRequest(); +xhr.open('GET', ABS_BASE_URL + '/../versions.json'); +xhr.onload = function () { + var info = JSON.parse(this.responseText); + + __md_set("__source", { + version: "v3.0.0-BETA", + stars: info.stargazers_count, + forks: info.forks_count, + }, sessionStorage) +} + +xhr.send(); \ No newline at end of file diff --git a/mkdocs-base.yml b/mkdocs-base.yml index d29abd690e..521ca6d8fd 100644 --- a/mkdocs-base.yml +++ b/mkdocs-base.yml @@ -67,6 +67,7 @@ extra_javascript: # - js/lightgallery.min.js - js/promptremover.js - js/consent.js + - js/repo-version.js markdown_extensions: attr_list: {} diff --git a/overrides/assets/javascripts/components/source/facts/github/index.ts b/overrides/assets/javascripts/components/source/facts/github/index.ts deleted file mode 100644 index d76945dcf3..0000000000 --- a/overrides/assets/javascripts/components/source/facts/github/index.ts +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2016-2024 Martin Donath - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -import { Repo, User } from "github-types" -import { - EMPTY, - Observable, - catchError, - defaultIfEmpty, - map, - zip -} from "rxjs" - -import { requestJSON } from "~/browser" - -import { SourceFacts } from "../_" - -/* ---------------------------------------------------------------------------- - * Helper types - * ------------------------------------------------------------------------- */ - -/** - * GitHub release (partial) - */ -interface Release { - tag_name: string /* Tag name */ -} - -/* ---------------------------------------------------------------------------- - * Functions - * ------------------------------------------------------------------------- */ - -/** - * Fetch GitHub repository facts - * - * @param user - GitHub user or organization - * @param repo - GitHub repository - * - * @returns Repository facts observable - */ -export function fetchSourceFactsFromGitHub( - user: string, repo?: string -): Observable { - if (typeof repo !== "undefined") { - const url = `https://api.github.com/repos/${user}/${repo}` - return zip( - - /* Fetch version */ - requestJSON(`${url}/releases/latest`) - .pipe( - catchError(() => EMPTY), // @todo refactor instant loading - map(release => ({ - version: release.tag_name - })), - defaultIfEmpty({}) - ), - - /* Fetch stars and forks */ - requestJSON(url) - .pipe( - catchError(() => EMPTY), // @todo refactor instant loading - map(info => ({ - version: "v3.0.0-BETA", - stars: info.stargazers_count, - forks: info.forks_count - })), - defaultIfEmpty({}) - ) - ) - .pipe( - map(([release, info]) => ({ ...release, ...info })) - ) - - /* User or organization */ - } else { - const url = `https://api.github.com/users/${user}` - return requestJSON(url) - .pipe( - map(info => ({ - repositories: info.public_repos - })), - defaultIfEmpty({}) - ) - } -} \ No newline at end of file diff --git a/overrides/assets/javascripts/templates/source/index.tsx b/overrides/assets/javascripts/templates/source/index.tsx deleted file mode 100644 index 6f08d911cd..0000000000 --- a/overrides/assets/javascripts/templates/source/index.tsx +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2016-2024 Martin Donath - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -import { SourceFacts } from "~/components" -import { h, round } from "~/utilities" - -/* ---------------------------------------------------------------------------- - * Functions - * ------------------------------------------------------------------------- */ - -/** - * Render repository facts - * - * @param facts - Repository facts - * - * @returns Element - */ -export function renderSourceFacts(facts: SourceFacts): HTMLElement { - return ( -
    - {Object.entries(facts).map(([key, value]) => ( -
  • - {typeof value === "number" ? round(value) : (key == "version" ? "3.0.0-Beta - "+value : value)} -
  • - ))} -
- ) -} \ No newline at end of file diff --git a/overrides/partials/javascripts/base.html b/overrides/partials/javascripts/base.html deleted file mode 100644 index a7f011b1f7..0000000000 --- a/overrides/partials/javascripts/base.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - \ No newline at end of file From efd7a5862b229c89b097e483cee3a96e00f3cfee Mon Sep 17 00:00:00 2001 From: Nurlan Moldomurov Date: Thu, 5 Dec 2024 17:11:47 +0300 Subject: [PATCH 4/5] PMM-7 test override --- docs/js/repo-version.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/js/repo-version.js b/docs/js/repo-version.js index f9d0f4d2e8..d02e09a257 100644 --- a/docs/js/repo-version.js +++ b/docs/js/repo-version.js @@ -1,6 +1,5 @@ - var xhr = new XMLHttpRequest(); -xhr.open('GET', ABS_BASE_URL + '/../versions.json'); +xhr.open('GET', 'https://api.github.com/repos/percona/pmm-doc'); xhr.onload = function () { var info = JSON.parse(this.responseText); From 30efe451f3aa8d7bc8f19ef222e5942656dbfa2e Mon Sep 17 00:00:00 2001 From: Nurlan Moldomurov Date: Mon, 16 Dec 2024 18:39:07 +0300 Subject: [PATCH 5/5] PMM-7 test override --- docs/js/repo-version.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/js/repo-version.js b/docs/js/repo-version.js index d02e09a257..415ea0368c 100644 --- a/docs/js/repo-version.js +++ b/docs/js/repo-version.js @@ -1,3 +1,6 @@ +__md_set("__source", { + version: "v3.0.0-BETA", +}, sessionStorage) var xhr = new XMLHttpRequest(); xhr.open('GET', 'https://api.github.com/repos/percona/pmm-doc'); xhr.onload = function () {