Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions public/callback/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,36 @@ window.onload = async function () {
technicalInformationTextArea.value += key + ": " + value + "\n";
});
}
const token = localStorage.getItem("gitlab-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 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");
Expand All @@ -27,7 +53,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);
Expand All @@ -37,12 +62,14 @@ 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;
}
}*/
}




}

async function latest(projectId, token) {
const jobResponse = await fetch(
Expand Down
46 changes: 30 additions & 16 deletions public/curation/curation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]){
Expand All @@ -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";
Expand All @@ -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) +' <b> '+data[element]+'</b>';
}else{
document.getElementById("project-name").innerHTML = element.charAt(0).toUpperCase() + element.slice(1) +' <b> '+data[element][0]+'</b>';
}
}
}
// Apply and fill in the template for Policies
if(element=="policies"){
header.style.display = "block";
Expand Down Expand Up @@ -107,22 +111,26 @@ 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";
}
})

})
})

//Extend Checkbox for metadata source
const checkbox = document.querySelector("#extended");
checkbox.addEventListener('change', (event)=>{
Expand Down Expand Up @@ -152,9 +160,15 @@ function get_data_snippet(data, skey, svalue){
const obj = stack.pop();
for(let i=0; i<Object.keys(obj).length; i++){
let key = Object.keys(obj)[i];
if(key==skey && obj[key][0]==svalue){
if(!Array.isArray(obj[key])){
if(key==skey && obj[key]==svalue){
return obj;
}
}else{
if(key==skey && obj[key][0]==svalue){
return obj;
}
}
if (typeof obj[key] === 'object' && obj[key] !== null) {
stack.push(obj[key]);
}
Expand Down
27 changes: 25 additions & 2 deletions public/curation/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ function extract_info(cell, obj, tag, colorPolicies){
tooltip.onclick = function(){link_to_person(e)};
const tooltiptext = document.createElement("div");
tooltiptext.classList.add("swc-tooltiptext");
Object.keys(e).forEach(k => {
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"));
Expand All @@ -75,14 +81,20 @@ 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"]){
pair_in_list.style.color = colorPolicies[e[k][key][2]["conflict"]];
tooltiptag.style.color = colorPolicies[e[k][key][2]["conflict"]];
hasConfict = true;

}
}}
pair.appendChild(pair_in_list);
}
}else{
Expand All @@ -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};
70 changes: 70 additions & 0 deletions public/curation/github_artifacts.js
Original file line number Diff line number Diff line change
@@ -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("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;

};

export {githubArtifacts};
57 changes: 57 additions & 0 deletions public/curation/gitlab_artifacts.js
Original file line number Diff line number Diff line change
@@ -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("gitlab-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};
1 change: 1 addition & 0 deletions public/curation/safe_comments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { addComment } from '../modules/storage.js'

export async function addToBatch(value, data, comment){
//TODO: Value is first of string right now
addComment(value, data, comment);
}
15 changes: 13 additions & 2 deletions public/curation/script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {drawHexagon, drawRadar } from "../radar.js";
import { displayJSON } from "./curation.js";

import { githubArtifacts } from "./github_artifacts.js";
import { gitlabArtifacts } from "./gitlab_artifacts.js";

//Draw radar plot
const canvas = document.getElementById('radar');
Expand All @@ -16,4 +17,14 @@ 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");
const type = localStorage.getItem("instance-type");
if(type=="github"){
githubArtifacts();
}else if(type=="gitlab"){
gitlabArtifacts();
}else{
fetch("../.hermes/process/transport.json")
.then(response => response.json())
.then(data => {
displayJSON(data);})
}
Loading