|
534 | 534 | statusContainer.appendChild(keyValuePair); |
535 | 535 | } |
536 | 536 |
|
537 | | - function navigatePath(jsonObj, nameArray) { |
538 | | - let baseParams = new URLSearchParams(window.location.search); |
539 | | - let keysToDelete = []; |
540 | | - baseParams.forEach((value, key) => { |
541 | | - if (key.startsWith('name_')) { |
542 | | - keysToDelete.push(key); // Collect the keys to delete |
543 | | - } |
544 | | - }); |
545 | | - keysToDelete.forEach((key) => baseParams.delete(key)); |
546 | | - let pathNames = []; |
547 | | - let pathLinks = []; |
548 | | - let currentObj = jsonObj; |
549 | | - |
550 | | - // Add the first entry (workflow level) |
551 | | - baseParams.set(`name_0`, nameArray[0]); |
552 | | - pathNames.push(nameArray[0]); |
553 | | - pathLinks.push(`<span class="separator">/</span><a href="${window.location.pathname}?${baseParams.toString()}">${nameArray[0]}</a>`); |
554 | | - // Add the second entry (job level) |
555 | | - if (nameArray.length > 1) { |
556 | | - baseParams.set(`name_1`, nameArray[1]); |
557 | | - pathNames.push(nameArray[1]); |
558 | | - pathLinks.push(`<span class="separator">/</span><a href="${window.location.pathname}?${baseParams.toString()}">${nameArray[1]}</a>`); |
559 | | - } |
560 | | - // Iterate through the nameArray starting at index 0 |
561 | | - for (const [index, name] of nameArray.entries()) { |
562 | | - if (index === 0 || index === 1) continue; |
563 | | - if (currentObj && Array.isArray(currentObj.results)) { |
564 | | - const nextResult = currentObj.results.find(result => result.name === name); |
565 | | - if (nextResult) { |
566 | | - baseParams.set(`name_${index}`, nextResult.name); |
567 | | - pathNames.push(nextResult.name); // Correctly push nextResult name, not currentObj.name |
568 | | - pathLinks.push(`<span class="separator">/</span><a href="${window.location.pathname}?${baseParams.toString()}">${nextResult.name}</a>`); |
569 | | - currentObj = nextResult; // Move to the next object in the hierarchy |
570 | | - } else { |
571 | | - console.error(`Name "${name}" not found in results array.`); |
572 | | - return null; // Name not found in results array |
573 | | - } |
574 | | - } else { |
575 | | - console.error(`Current object is not structured as expected.`); |
576 | | - return null; // Current object is not structured as expected |
577 | | - } |
578 | | - } |
579 | | - const footerLeft = document.querySelector('#footer .left'); |
580 | | - footerLeft.innerHTML = pathLinks.join(''); |
581 | | - |
582 | | - return currentObj; |
583 | | - } |
584 | | - |
585 | 537 | // Define the fixed columns globally, so both functions can use it |
586 | 538 | const columns = ['name', 'status', 'start_time', 'duration', 'info']; |
587 | 539 |
|
|
696 | 648 | populateTableRows(tbody, results, columns, nest_level); |
697 | 649 | } |
698 | 650 |
|
699 | | - async function fetchJson(PR, sha, name) { |
| 651 | + async function fetchJson(suffix, sha, name) { |
700 | 652 | const infoElement = document.getElementById('info-container'); |
701 | 653 | const task = name |
702 | 654 | .toLowerCase() |
|
706 | 658 |
|
707 | 659 | // Construct the URL dynamically based on PR, sha, and task |
708 | 660 | const baseUrl = window.location.origin + window.location.pathname.replace('/json.html', ''); |
709 | | - const path = `${baseUrl}/${encodeURIComponent(PR)}/${encodeURIComponent(sha)}/result_${task}.json`; |
| 661 | + const path = `${baseUrl}/${suffix}/${encodeURIComponent(sha)}/result_${task}.json`; |
710 | 662 |
|
711 | 663 | try { |
712 | 664 | const response = await fetch(path, { cache: "no-cache" }); |
|
716 | 668 | } |
717 | 669 |
|
718 | 670 | //const lastModifiedTime = response.headers.get('Last-Modified'); |
719 | | - const jsonData = await response.json(); |
720 | | - return jsonData; |
| 671 | + return await response.json(); |
721 | 672 | } catch (error) { |
722 | 673 | console.error('Error loading Results:', error); |
723 | 674 | if (infoElement) { |
|
741 | 692 | else if (link.includes('/actions/runs/')) runtimeCache.runLink = link; |
742 | 693 | } |
743 | 694 |
|
744 | | - async function fetch0Json(PR, sha, name) { |
| 695 | + async function fetch0Json(suffix, sha, name) { |
745 | 696 | try { |
746 | | - const resultData = await fetchJson(PR, sha, name); |
| 697 | + const resultData = await fetchJson(suffix, sha, name); |
747 | 698 | runtimeCache.json0 = resultData; |
748 | 699 | if (Array.isArray(resultData.links)) { |
749 | 700 | resultData.links.forEach(storeLink); |
|
753 | 704 | } |
754 | 705 | } |
755 | 706 |
|
756 | | - async function fetch1Json(PR, sha, name) { |
| 707 | + async function fetch1Json(suffix, sha, name) { |
757 | 708 | try { |
758 | | - const resultData = await fetchJson(PR, sha, name); |
759 | | - runtimeCache.json1 = resultData; |
| 709 | + runtimeCache.json1 = await fetchJson(suffix, sha, name); |
760 | 710 | } catch (error) { |
761 | 711 | console.error('Error fetching JSON1:', error); |
762 | 712 | } |
|
859 | 809 | footerLeft.innerHTML = pathLinks.join(''); |
860 | 810 | } |
861 | 811 |
|
862 | | - async function renderResults(PR, sha, nameParams) { |
| 812 | + async function renderResults(PR, REF, sha, nameParams) { |
863 | 813 | const baseUrl = window.location.origin + window.location.pathname.replace('/json.html', ''); |
864 | | - if (PR>0){ |
865 | | - await loadCommitsArray(`${baseUrl}/${encodeURIComponent(PR)}/commits.json`) |
| 814 | + let suffix = ''; |
| 815 | + if (PR) { |
| 816 | + suffix = `PRs/${encodeURIComponent(PR)}`; |
| 817 | + } else if (REF) { |
| 818 | + suffix = `REFs/${encodeURIComponent(REF)}`; |
| 819 | + } |
| 820 | + if (suffix) { |
| 821 | + await loadCommitsArray(`${baseUrl}/${suffix}/commits.json`); |
| 822 | + } else { |
| 823 | + console.error("PR or REF must be defined to load commits."); |
866 | 824 | } |
867 | 825 | const shaToLoad = (sha === 'latest') ? runtimeCache.commits[runtimeCache.commits.length - 1] : sha; |
868 | 826 | if (runtimeCache.json0 === null) { |
869 | | - await fetch0Json(PR, shaToLoad, nameParams[0]); |
| 827 | + await fetch0Json(suffix, shaToLoad, nameParams[0]); |
870 | 828 | } |
871 | 829 | if (nameParams.length > 1 && runtimeCache.json1 === null) { |
872 | | - await fetch1Json(PR, shaToLoad, nameParams[1]); |
| 830 | + await fetch1Json(suffix, shaToLoad, nameParams[1]); |
873 | 831 | } |
874 | 832 | const footerRight = document.querySelector('#footer .right'); |
875 | 833 | function createLinkElement(href, textContent, footer) { |
|
939 | 897 | async function init() { |
940 | 898 | const urlParams = new URLSearchParams(window.location.search); |
941 | 899 | const PR = urlParams.get('PR'); |
| 900 | + const REF = urlParams.get('REF'); |
942 | 901 | const sha = urlParams.get('sha'); |
943 | | - const root_name = urlParams.get('name_0'); |
944 | 902 | const nameParams = []; |
945 | 903 |
|
946 | 904 | // Collect all `name_*` parameters into `nameParams` array |
|
952 | 910 | }); |
953 | 911 |
|
954 | 912 | // Render results using the extracted parameters |
955 | | - await renderResults(PR, sha, nameParams); |
| 913 | + await renderResults(PR, REF, sha, nameParams); |
956 | 914 | } |
957 | 915 |
|
958 | 916 | document.addEventListener('DOMContentLoaded', init); |
| 917 | + // document.querySelectorAll("a").forEach(link => { |
| 918 | + // link.addEventListener("click", function (event) { |
| 919 | + // event.preventDefault(); // Prevent full-page reload |
| 920 | + // history.pushState(null, "", this.href); // Update URL without reload |
| 921 | + // }); |
| 922 | + // }); |
959 | 923 | </script> |
960 | 924 | </body> |
961 | 925 | </html> |
0 commit comments