diff --git a/public/callback/main.js b/public/callback/main.js index 395b862..c556fb7 100644 --- a/public/callback/main.js +++ b/public/callback/main.js @@ -1,4 +1,3 @@ -import { registerPipeline } from '../modules/storage.js' const showDebugInformation = false; @@ -11,53 +10,30 @@ window.onload = async function () { technicalInformationTextArea.value += key + ": " + value + "\n"; }); } + const token = localStorage.getItem("git-api-token"); + const instanceType = parameters.get("type"); + localStorage.setItem("instance-type", instanceType); + if(instanceType=="github"){ + const owner = parameters.get("owner"); + const repo = parameters.get("repo"); + const artifactId = parameters.get("artifactId"); + console.log(owner, repo, artifactId); + localStorage.setItem("owner", owner); + localStorage.setItem("repo", repo); + localStorage.setItem("artifactId", artifactId); + window.location = "../curation/"; + + + }else{ + const url = parameters.get("url"); + const repo = parameters.get("repo"); + const artifactId = parameters.get("artifactId"); + console.log(url, repo, artifactId); + localStorage.setItem("url", url); + localStorage.setItem("repo", repo); + localStorage.setItem("artifactId", artifactId); + window.location = "../curation/"; - const gitLabProjectId = parameters.get("gitlab_project_id"); - - const get_latest = parameters.get("latest"); - const gitLabPipelineId = parameters.get("gitlab_pipeline_id"); - const gitLabJobId = parameters.get("gitlab_job_id"); - - if(get_latest != 1){ - await registerPipeline(gitLabProjectId, gitLabPipelineId, gitLabJobId); - } - - if (showDebugInformation) { - await new Promise(r => setTimeout(r, 5000)); - } - - const token = localStorage.getItem("gitlab-api-token"); - if (token) { - if(get_latest==1){ - await latest(gitLabProjectId, token); - }else{ - window.location = "../dashboard/"; - } - return; - } else { - alert("Please set up the GitLab connection, then go to the dashboard!"); - window.location = "../gitlab-setup/"; - return; } - - -} - -async function latest(projectId, token) { - const jobResponse = await fetch( - `https://codebase.helmholtz.cloud/api/v4/projects/${projectId}/jobs/`, - { headers: { "Content-Type": "application/json", "PRIVATE-TOKEN": token } } - ); - - if (!jobResponse.ok) { - alert("Fetching pipeline failed"); - return; - } - - const jobData = await jobResponse.json(); - const jobId = jobData[0]["id"]; - const pipelineId = jobData[0]["pipeline"]["id"]; - - window.location = `../callback?gitlab_project_id=${projectId}&gitlab_pipeline_id=${pipelineId}&gitlab_job_id=${jobId}&latest=2`; } diff --git a/public/curation/curation.js b/public/curation/curation.js index 80186cd..baf2450 100644 --- a/public/curation/curation.js +++ b/public/curation/curation.js @@ -5,10 +5,7 @@ import { addToBatch } from "./safe_comments.js"; * Fetches json_document and displays their contents in a table. * @param {Path} json_document - document do fetch data from. */ -export function displayJSON(json_document){ - fetch(json_document) - .then(response => response.json()) - .then(data => { +export function displayJSON(data){ const colorPalette = ["rgb(34, 198, 227)", "purple", "rgb(23, 124, 207)", "rgb(116, 75, 196)", "pink"]; let colorPolicies = {"Curation": "red"}; if(data["policies"]){ @@ -18,10 +15,12 @@ export function displayJSON(json_document){ console.log(colorPolicies); //Get data snippet from url const params = new URLSearchParams(location.search); - if(params.has("id")){ - const id = params.get("id") - data = get_data_snippet(data, "@id", id); - + if(params.size > 0){ + for (const [key, value] of params) { + console.log("search for",key, value); + data = get_data_snippet(data, key, value); + } + //If your seeing a data snippet, create button to go back const back = document.createElement("button"); back.innerText = "Back to Overview"; @@ -43,10 +42,15 @@ export function displayJSON(json_document){ keys.forEach(element => { + // Get a something with Name as p Header if(element.toLowerCase().includes("name")){ + if(!Array.isArray(data[element])){ + document.getElementById("project-name").innerHTML = element.charAt(0).toUpperCase() + element.slice(1) +' '+data[element]+''; + }else{ document.getElementById("project-name").innerHTML = element.charAt(0).toUpperCase() + element.slice(1) +' '+data[element][0]+''; - } + } + } // Apply and fill in the template for Policies if(element=="policies"){ header.style.display = "block"; @@ -107,14 +111,18 @@ export function displayJSON(json_document){ const slcomment = mvalue.querySelector("#single-line-comment"), slcommentPopup = mvalue.querySelector("#single-line-comment-popup"); const input = mvalue.querySelector("#comment"); - mvalue.querySelector('input[type="submit"]').addEventListener("click", () => { - addToBatch(element, data[element], input.value); - }); - slcomment.addEventListener('click', (event)=>{ + slcomment.addEventListener('click', (event)=>{ event.stopPropagation(); - console.log("clicked"); + if (event.target !== slcomment) { + return; + } slcommentPopup.style.visibility = "visible"; }) + mvalue.querySelector('input[type="submit"]').addEventListener("click", () => { + addToBatch(element, data[element], input.value); + slcommentPopup.style.visibility = "hidden"; + }); + document.addEventListener('click', function(e) { if ( slcommentPopup.style.visibility === "visible" && !slcommentPopup.contains(e.target) ) { slcommentPopup.style.visibility = "hidden"; @@ -122,7 +130,7 @@ export function displayJSON(json_document){ }) }) - }) + //Extend Checkbox for metadata source const checkbox = document.querySelector("#extended"); checkbox.addEventListener('change', (event)=>{ @@ -152,9 +160,15 @@ function get_data_snippet(data, skey, svalue){ const obj = stack.pop(); for(let i=0; i { + if(!Array.isArray(e[k]) && typeof e[k] === "string"){ + e[k] = [e[k]]; + } + }) + const text = document.createTextNode(`${e.familyName[0]}, ${e.givenName[0]} `); tooltiptag.appendChild(document.createTextNode("See Details")); tooltiptag.appendChild(document.createElement("br")); @@ -75,6 +81,12 @@ function extract_info(cell, obj, tag, colorPolicies){ if(!Array.isArray(e[k])){ for (let key in e[k]) { const pair_in_list = document.createElement("p"); + if(!Array.isArray(e[k][key]) && typeof e[k][key] === "string"){ + names.push(`${k}:${key}: ${e[k][key]}`); + pair_in_list.appendChild(document.createTextNode(`${k}:${key}: ${e[k][key]}`)); + + } + else{ names.push(`${k}:${key}: ${e[k][key][0]}`); pair_in_list.appendChild(document.createTextNode(`${k}:${key}: ${e[k][key][0]}`)); if(e[k][key][2] && e[k][key][2]["conflict"]){ @@ -82,7 +94,7 @@ function extract_info(cell, obj, tag, colorPolicies){ tooltiptag.style.color = colorPolicies[e[k][key][2]["conflict"]]; hasConfict = true; - } + }} pair.appendChild(pair_in_list); } }else{ @@ -105,7 +117,18 @@ function extract_info(cell, obj, tag, colorPolicies){ } function link_to_person(data){ - window.location.href += `?id=${data["@id"][0]}`; + if(data["@id"]){ + if(!Array.isArray(data["@id"])){ + data["@id"] = [data["@id"]]; + } + window.location.href += `?@id=${data["@id"][0]}`; + }else{ + if(!Array.isArray(data["familyName"])){ + data["familyName"] = [data["familyName"]]; + } + window.location.href += `?familyName=${data["familyName"][0]}`; + } + } export {extract_info}; diff --git a/public/curation/github_artifacts.js b/public/curation/github_artifacts.js new file mode 100644 index 0000000..a5b26e2 --- /dev/null +++ b/public/curation/github_artifacts.js @@ -0,0 +1,70 @@ +import { BlobReader, TextWriter, ZipReader } from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.72/+esm"; +import { Octokit } from "https://esm.sh/@octokit/rest"; +import { displayJSON } from "./curation.js"; + +const showDebugInformation = false; + +async function githubArtifacts() { + const token = localStorage.getItem("git-api-token"); + if (!token) { + alert("Please set up the GitLab connection first"); + window.location = "../"; + return; + } + const owner = localStorage.getItem("owner"); + const repo = localStorage.getItem("repo"); + const artifactId = localStorage.getItem("artifactId"); + + const octokit = new Octokit({ + auth: token +}) + +//https://softwarepub.github.io/software-card/callback/?type=github&owner=softwarepub&repo=software-card-showcase&artifactId=7291062769 +//https://github.com/softwarepub/software-card-showcase/actions/runs/26636754684/artifacts/7290497137 + // --- Job artifacts --- +const artifact = await octokit.request(`GET /repos/${owner}/${repo}/actions/artifacts/${artifactId}/zip`, { + owner: `${owner}`, + repo: `${repo}`, + artifact_id: `${artifactId}`, + archive_format: 'zip', + headers: { + 'X-GitHub-Api-Version': '2026-03-10' + } +}) +if (artifact.status !== 200) { + alert("Fetching artifacts failed"); + } + + +const response = await fetch(artifact.url); + + + // this is a zip file :-( + const artifactsData = await response.blob(); + + + const zipFileReader = new BlobReader(artifactsData); + const zipReader = new ZipReader(zipFileReader); + const fileEntries = await zipReader.getEntries(); + + + do { + var fileEntry = fileEntries.shift(); + if (showDebugInformation) { + console.log(fileEntry); + } + } while (fileEntry["filename"] != "hermes.json"); + + const reportWriter = new TextWriter(); + const reportText = await fileEntry.getData(reportWriter); + await zipReader.close(); + + console.log(reportText); + displayJSON(JSON.parse(reportText)["curate"]); + + //const reportContentsTextArea = document.getElementById("report-contents"); + //reportContentsTextArea.value = reportText; + +}; + +export {githubArtifacts}; \ No newline at end of file diff --git a/public/curation/gitlab_artifacts.js b/public/curation/gitlab_artifacts.js new file mode 100644 index 0000000..d0a6565 --- /dev/null +++ b/public/curation/gitlab_artifacts.js @@ -0,0 +1,57 @@ +import { BlobReader, TextWriter, ZipReader } from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.72/+esm"; +import { displayJSON } from "./curation.js"; + +const showDebugInformation = false; + +async function gitlabArtifacts () { + const token = localStorage.getItem("git-api-token"); + if (!token) { + alert("Please set up the GitLab connection first!"); + window.location = "../"; + return; + } + + const url = localStorage.getItem("url"); + const repo = localStorage.getItem("repo"); + const artifactId = localStorage.getItem("artifactId"); + + //https://softwarepub.github.io/software-card/callback?type=gitlab&url=https://codebase.helmholtz.cloud&repo=21313&artifactId=3159194 + + // --- Job artifacts --- + + const jobArtifactsResponse = await fetch( + `https://codebase.helmholtz.cloud/api/v4/projects/${repo}/jobs/${artifactId}/artifacts`, + { headers: { "Content-Type": "application/json", "PRIVATE-TOKEN": token } } + ); + + if (!jobArtifactsResponse.ok) { + alert("Fetching artifacts failed"); + return; + } + console.log(jobArtifactsResponse); + + // this is a zip file :-( + const artifactsData = await jobArtifactsResponse.blob(); + + const zipFileReader = new BlobReader(artifactsData); + const zipReader = new ZipReader(zipFileReader); + const fileEntries = await zipReader.getEntries(); + + do { + var fileEntry = fileEntries.shift(); + if (showDebugInformation) { + console.log(fileEntry); + } + } while (fileEntry["filename"] != ".hermes/curate/hermes.json"); + + const reportWriter = new TextWriter(); + const reportText = await fileEntry.getData(reportWriter); + await zipReader.close(); + + + console.log(reportText); + displayJSON(JSON.parse(reportText)); + +} + + export {gitlabArtifacts}; \ No newline at end of file diff --git a/public/curation/index.html b/public/curation/index.html index 1e9051e..b6c47ef 100644 --- a/public/curation/index.html +++ b/public/curation/index.html @@ -13,7 +13,7 @@