diff --git a/public/callback/main.js b/public/callback/main.js index 395b862..faa8186 100644 --- a/public/callback/main.js +++ b/public/callback/main.js @@ -11,10 +11,24 @@ window.onload = async function () { technicalInformationTextArea.value += key + ": " + value + "\n"; }); } + const token = localStorage.getItem("gitlab-api-token"); + + if(parameters.get("type")=="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 = "../dashboard/"; + + + }else{ const gitLabProjectId = parameters.get("gitlab_project_id"); - const get_latest = parameters.get("latest"); + let get_latest = parameters.get("latest"); const gitLabPipelineId = parameters.get("gitlab_pipeline_id"); const gitLabJobId = parameters.get("gitlab_job_id"); @@ -27,7 +41,6 @@ window.onload = async function () { await new Promise(r => setTimeout(r, 5000)); } - const token = localStorage.getItem("gitlab-api-token"); if (token) { if(get_latest==1){ await latest(gitLabProjectId, token); @@ -37,9 +50,12 @@ window.onload = async function () { return; } else { alert("Please set up the GitLab connection, then go to the dashboard!"); - window.location = "../gitlab-setup/"; + window.location = "../git-login/"; return; } +} + + } 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..578dacb --- /dev/null +++ b/public/curation/github_artifacts.js @@ -0,0 +1,68 @@ +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; + +window.onload = async function () { + const token = localStorage.getItem("gitlab-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; + +}; diff --git a/public/curation/index.html b/public/curation/index.html index 1e9051e..3db83ca 100644 --- a/public/curation/index.html +++ b/public/curation/index.html @@ -118,6 +118,7 @@

Policy Report

+ diff --git a/public/curation/script.js b/public/curation/script.js index 41f9d41..34fad8b 100644 --- a/public/curation/script.js +++ b/public/curation/script.js @@ -16,4 +16,9 @@ drawRadar(ctx, canvas.offsetWidth/2,canvas.offsetHeight/2, [15,15,10,15,15,12], drawRadar(ctx, canvas.offsetWidth/2,canvas.offsetHeight/2, [20,20,9,10,20,15], "blue", "rgba(94, 148, 215, 0.34)"); //View for Curation -displayJSON("../.hermes/process/transport.json"); +/* + fetch("../.hermes/process/transport.json") + .then(response => response.json()) + .then(data => { + displayJSON(data); + })*/ \ No newline at end of file diff --git a/public/curation/send_report.js b/public/curation/send_report.js index 1ed4172..8cb9977 100644 --- a/public/curation/send_report.js +++ b/public/curation/send_report.js @@ -56,20 +56,22 @@ const response = await fetch( ); const data = await response.json(); + alert("Send to GitLab"); } async function issueGithub(token, username, message){ + const owner = localStorage.getItem("owner"); + const repo = localStorage.getItem("repo"); //TODO Test for Github const octokit = new Octokit({ auth: token }) try{ - await octokit.request('POST /repos/SKernchen/SoftwareCaRD-Test/issues', { - owner: `${username}`, - repo: 'SoftwareCaRD-test', + await octokit.request(`POST /repos/${owner}/${repo}/issues`, { + owner: `${owner}`, + repo: `${repo}`, title: `Curation Report`, - labels: ['curation'], body: message, headers: { 'X-GitHub-Api-Version': '2022-11-28' diff --git a/public/style.css b/public/style.css index 9449a16..6ef05a8 100644 --- a/public/style.css +++ b/public/style.css @@ -275,10 +275,11 @@ border-color: transparent transparent #555 transparent; position: absolute; visibility: hidden; background-color: #bababa; + color: white; padding: 5px; border-radius: 12px; - top: 17px; - left: -250px; + top: 25px; + left: -300%; z-index: 1; } .single-line-comment-popup::after { @@ -292,6 +293,15 @@ border-width: 5px; border-style: solid; border-color: transparent transparent #bababa transparent; } +.single-line-comment-popup [type=submit] { + top: 100%; + border-radius: 12px; + background-color: rgb(23, 124, 207) ; + color: white; + border-color: white; + padding: 4px; + margin-top: 5px; +} input[type=text]{ width:500px;