Skip to content

Commit 3307a94

Browse files
authored
Merge pull request #19 from softwarepub/18-first-prototyp
Get artifacts from github
2 parents e286ae9 + f1819c9 commit 3307a94

17 files changed

Lines changed: 283 additions & 262 deletions

File tree

public/callback/main.js

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { registerPipeline } from '../modules/storage.js'
21

32
const showDebugInformation = false;
43

@@ -11,53 +10,30 @@ window.onload = async function () {
1110
technicalInformationTextArea.value += key + ": " + value + "\n";
1211
});
1312
}
13+
const token = localStorage.getItem("git-api-token");
14+
const instanceType = parameters.get("type");
15+
localStorage.setItem("instance-type", instanceType);
16+
if(instanceType=="github"){
17+
const owner = parameters.get("owner");
18+
const repo = parameters.get("repo");
19+
const artifactId = parameters.get("artifactId");
20+
console.log(owner, repo, artifactId);
21+
localStorage.setItem("owner", owner);
22+
localStorage.setItem("repo", repo);
23+
localStorage.setItem("artifactId", artifactId);
24+
window.location = "../curation/";
25+
26+
27+
}else{
28+
const url = parameters.get("url");
29+
const repo = parameters.get("repo");
30+
const artifactId = parameters.get("artifactId");
31+
console.log(url, repo, artifactId);
32+
localStorage.setItem("url", url);
33+
localStorage.setItem("repo", repo);
34+
localStorage.setItem("artifactId", artifactId);
35+
window.location = "../curation/";
1436

15-
const gitLabProjectId = parameters.get("gitlab_project_id");
16-
17-
const get_latest = parameters.get("latest");
1837

19-
const gitLabPipelineId = parameters.get("gitlab_pipeline_id");
20-
const gitLabJobId = parameters.get("gitlab_job_id");
21-
22-
if(get_latest != 1){
23-
await registerPipeline(gitLabProjectId, gitLabPipelineId, gitLabJobId);
24-
}
25-
26-
if (showDebugInformation) {
27-
await new Promise(r => setTimeout(r, 5000));
28-
}
29-
30-
const token = localStorage.getItem("gitlab-api-token");
31-
if (token) {
32-
if(get_latest==1){
33-
await latest(gitLabProjectId, token);
34-
}else{
35-
window.location = "../dashboard/";
36-
}
37-
return;
38-
} else {
39-
alert("Please set up the GitLab connection, then go to the dashboard!");
40-
window.location = "../gitlab-setup/";
41-
return;
4238
}
43-
44-
45-
}
46-
47-
async function latest(projectId, token) {
48-
const jobResponse = await fetch(
49-
`https://codebase.helmholtz.cloud/api/v4/projects/${projectId}/jobs/`,
50-
{ headers: { "Content-Type": "application/json", "PRIVATE-TOKEN": token } }
51-
);
52-
53-
if (!jobResponse.ok) {
54-
alert("Fetching pipeline failed");
55-
return;
56-
}
57-
58-
const jobData = await jobResponse.json();
59-
const jobId = jobData[0]["id"];
60-
const pipelineId = jobData[0]["pipeline"]["id"];
61-
62-
window.location = `../callback?gitlab_project_id=${projectId}&gitlab_pipeline_id=${pipelineId}&gitlab_job_id=${jobId}&latest=2`;
6339
}

public/curation/curation.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import { addToBatch } from "./safe_comments.js";
55
* Fetches json_document and displays their contents in a table.
66
* @param {Path} json_document - document do fetch data from.
77
*/
8-
export function displayJSON(json_document){
9-
fetch(json_document)
10-
.then(response => response.json())
11-
.then(data => {
8+
export function displayJSON(data){
129
const colorPalette = ["rgb(34, 198, 227)", "purple", "rgb(23, 124, 207)", "rgb(116, 75, 196)", "pink"];
1310
let colorPolicies = {"Curation": "red"};
1411
if(data["policies"]){
@@ -18,10 +15,12 @@ export function displayJSON(json_document){
1815
console.log(colorPolicies);
1916
//Get data snippet from url
2017
const params = new URLSearchParams(location.search);
21-
if(params.has("id")){
22-
const id = params.get("id")
23-
data = get_data_snippet(data, "@id", id);
24-
18+
if(params.size > 0){
19+
for (const [key, value] of params) {
20+
console.log("search for",key, value);
21+
data = get_data_snippet(data, key, value);
22+
}
23+
2524
//If your seeing a data snippet, create button to go back
2625
const back = document.createElement("button");
2726
back.innerText = "Back to Overview";
@@ -43,10 +42,15 @@ export function displayJSON(json_document){
4342

4443

4544
keys.forEach(element => {
45+
4646
// Get a something with Name as p Header
4747
if(element.toLowerCase().includes("name")){
48+
if(!Array.isArray(data[element])){
49+
document.getElementById("project-name").innerHTML = element.charAt(0).toUpperCase() + element.slice(1) +' <b> '+data[element]+'</b>';
50+
}else{
4851
document.getElementById("project-name").innerHTML = element.charAt(0).toUpperCase() + element.slice(1) +' <b> '+data[element][0]+'</b>';
49-
}
52+
}
53+
}
5054
// Apply and fill in the template for Policies
5155
if(element=="policies"){
5256
header.style.display = "block";
@@ -107,22 +111,26 @@ export function displayJSON(json_document){
107111
const slcomment = mvalue.querySelector("#single-line-comment"),
108112
slcommentPopup = mvalue.querySelector("#single-line-comment-popup");
109113
const input = mvalue.querySelector("#comment");
110-
mvalue.querySelector('input[type="submit"]').addEventListener("click", () => {
111-
addToBatch(element, data[element], input.value);
112-
});
113-
slcomment.addEventListener('click', (event)=>{
114+
slcomment.addEventListener('click', (event)=>{
114115
event.stopPropagation();
115-
console.log("clicked");
116+
if (event.target !== slcomment) {
117+
return;
118+
}
116119
slcommentPopup.style.visibility = "visible";
117120
})
121+
mvalue.querySelector('input[type="submit"]').addEventListener("click", () => {
122+
addToBatch(element, data[element], input.value);
123+
slcommentPopup.style.visibility = "hidden";
124+
});
125+
118126
document.addEventListener('click', function(e) {
119127
if ( slcommentPopup.style.visibility === "visible" && !slcommentPopup.contains(e.target) ) {
120128
slcommentPopup.style.visibility = "hidden";
121129
}
122130
})
123131

124132
})
125-
})
133+
126134
//Extend Checkbox for metadata source
127135
const checkbox = document.querySelector("#extended");
128136
checkbox.addEventListener('change', (event)=>{
@@ -152,9 +160,15 @@ function get_data_snippet(data, skey, svalue){
152160
const obj = stack.pop();
153161
for(let i=0; i<Object.keys(obj).length; i++){
154162
let key = Object.keys(obj)[i];
155-
if(key==skey && obj[key][0]==svalue){
163+
if(!Array.isArray(obj[key])){
164+
if(key==skey && obj[key]==svalue){
165+
return obj;
166+
}
167+
}else{
168+
if(key==skey && obj[key][0]==svalue){
156169
return obj;
157170
}
171+
}
158172
if (typeof obj[key] === 'object' && obj[key] !== null) {
159173
stack.push(obj[key]);
160174
}

public/curation/extract.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ function extract_info(cell, obj, tag, colorPolicies){
6262
tooltip.onclick = function(){link_to_person(e)};
6363
const tooltiptext = document.createElement("div");
6464
tooltiptext.classList.add("swc-tooltiptext");
65+
Object.keys(e).forEach(k => {
66+
if(!Array.isArray(e[k]) && typeof e[k] === "string"){
67+
e[k] = [e[k]];
68+
}
69+
})
70+
6571
const text = document.createTextNode(`${e.familyName[0]}, ${e.givenName[0]} `);
6672
tooltiptag.appendChild(document.createTextNode("See Details"));
6773
tooltiptag.appendChild(document.createElement("br"));
@@ -75,14 +81,20 @@ function extract_info(cell, obj, tag, colorPolicies){
7581
if(!Array.isArray(e[k])){
7682
for (let key in e[k]) {
7783
const pair_in_list = document.createElement("p");
84+
if(!Array.isArray(e[k][key]) && typeof e[k][key] === "string"){
85+
names.push(`${k}:${key}: ${e[k][key]}`);
86+
pair_in_list.appendChild(document.createTextNode(`${k}:${key}: ${e[k][key]}`));
87+
88+
}
89+
else{
7890
names.push(`${k}:${key}: ${e[k][key][0]}`);
7991
pair_in_list.appendChild(document.createTextNode(`${k}:${key}: ${e[k][key][0]}`));
8092
if(e[k][key][2] && e[k][key][2]["conflict"]){
8193
pair_in_list.style.color = colorPolicies[e[k][key][2]["conflict"]];
8294
tooltiptag.style.color = colorPolicies[e[k][key][2]["conflict"]];
8395
hasConfict = true;
8496

85-
}
97+
}}
8698
pair.appendChild(pair_in_list);
8799
}
88100
}else{
@@ -105,7 +117,18 @@ function extract_info(cell, obj, tag, colorPolicies){
105117
}
106118

107119
function link_to_person(data){
108-
window.location.href += `?id=${data["@id"][0]}`;
120+
if(data["@id"]){
121+
if(!Array.isArray(data["@id"])){
122+
data["@id"] = [data["@id"]];
123+
}
124+
window.location.href += `?@id=${data["@id"][0]}`;
125+
}else{
126+
if(!Array.isArray(data["familyName"])){
127+
data["familyName"] = [data["familyName"]];
128+
}
129+
window.location.href += `?familyName=${data["familyName"][0]}`;
130+
}
131+
109132
}
110133

111134
export {extract_info};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { BlobReader, TextWriter, ZipReader } from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.72/+esm";
2+
import { Octokit } from "https://esm.sh/@octokit/rest";
3+
import { displayJSON } from "./curation.js";
4+
5+
const showDebugInformation = false;
6+
7+
async function githubArtifacts() {
8+
const token = localStorage.getItem("git-api-token");
9+
if (!token) {
10+
alert("Please set up the GitLab connection first");
11+
window.location = "../";
12+
return;
13+
}
14+
const owner = localStorage.getItem("owner");
15+
const repo = localStorage.getItem("repo");
16+
const artifactId = localStorage.getItem("artifactId");
17+
18+
const octokit = new Octokit({
19+
auth: token
20+
})
21+
22+
//https://softwarepub.github.io/software-card/callback/?type=github&owner=softwarepub&repo=software-card-showcase&artifactId=7291062769
23+
//https://github.com/softwarepub/software-card-showcase/actions/runs/26636754684/artifacts/7290497137
24+
// --- Job artifacts ---
25+
const artifact = await octokit.request(`GET /repos/${owner}/${repo}/actions/artifacts/${artifactId}/zip`, {
26+
owner: `${owner}`,
27+
repo: `${repo}`,
28+
artifact_id: `${artifactId}`,
29+
archive_format: 'zip',
30+
headers: {
31+
'X-GitHub-Api-Version': '2026-03-10'
32+
}
33+
})
34+
if (artifact.status !== 200) {
35+
alert("Fetching artifacts failed");
36+
}
37+
38+
39+
const response = await fetch(artifact.url);
40+
41+
42+
// this is a zip file :-(
43+
const artifactsData = await response.blob();
44+
45+
46+
const zipFileReader = new BlobReader(artifactsData);
47+
const zipReader = new ZipReader(zipFileReader);
48+
const fileEntries = await zipReader.getEntries();
49+
50+
51+
do {
52+
var fileEntry = fileEntries.shift();
53+
if (showDebugInformation) {
54+
console.log(fileEntry);
55+
}
56+
} while (fileEntry["filename"] != "hermes.json");
57+
58+
const reportWriter = new TextWriter();
59+
const reportText = await fileEntry.getData(reportWriter);
60+
await zipReader.close();
61+
62+
console.log(reportText);
63+
displayJSON(JSON.parse(reportText)["curate"]);
64+
65+
//const reportContentsTextArea = document.getElementById("report-contents");
66+
//reportContentsTextArea.value = reportText;
67+
68+
};
69+
70+
export {githubArtifacts};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { BlobReader, TextWriter, ZipReader } from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.72/+esm";
2+
import { displayJSON } from "./curation.js";
3+
4+
const showDebugInformation = false;
5+
6+
async function gitlabArtifacts () {
7+
const token = localStorage.getItem("git-api-token");
8+
if (!token) {
9+
alert("Please set up the GitLab connection first!");
10+
window.location = "../";
11+
return;
12+
}
13+
14+
const url = localStorage.getItem("url");
15+
const repo = localStorage.getItem("repo");
16+
const artifactId = localStorage.getItem("artifactId");
17+
18+
//https://softwarepub.github.io/software-card/callback?type=gitlab&url=https://codebase.helmholtz.cloud&repo=21313&artifactId=3159194
19+
20+
// --- Job artifacts ---
21+
22+
const jobArtifactsResponse = await fetch(
23+
`https://codebase.helmholtz.cloud/api/v4/projects/${repo}/jobs/${artifactId}/artifacts`,
24+
{ headers: { "Content-Type": "application/json", "PRIVATE-TOKEN": token } }
25+
);
26+
27+
if (!jobArtifactsResponse.ok) {
28+
alert("Fetching artifacts failed");
29+
return;
30+
}
31+
console.log(jobArtifactsResponse);
32+
33+
// this is a zip file :-(
34+
const artifactsData = await jobArtifactsResponse.blob();
35+
36+
const zipFileReader = new BlobReader(artifactsData);
37+
const zipReader = new ZipReader(zipFileReader);
38+
const fileEntries = await zipReader.getEntries();
39+
40+
do {
41+
var fileEntry = fileEntries.shift();
42+
if (showDebugInformation) {
43+
console.log(fileEntry);
44+
}
45+
} while (fileEntry["filename"] != ".hermes/curate/hermes.json");
46+
47+
const reportWriter = new TextWriter();
48+
const reportText = await fileEntry.getData(reportWriter);
49+
await zipReader.close();
50+
51+
52+
console.log(reportText);
53+
displayJSON(JSON.parse(reportText));
54+
55+
}
56+
57+
export {gitlabArtifacts};

public/curation/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</head>
1414
<body>
1515
<div id="header">
16-
<h1><a href="../">Software CaRD</a>
16+
<h1><a href="./">Software CaRD</a>
1717
</h1>
1818
<canvas onclick="location.href = '../reporting/';" id="radar" width="80" height="80">
1919
</canvas>

public/curation/safe_comments.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { addComment } from '../modules/storage.js'
22

33
export async function addToBatch(value, data, comment){
4+
//TODO: Value is first of string right now
45
addComment(value, data, comment);
56
}

0 commit comments

Comments
 (0)