Skip to content

Commit a6fd3eb

Browse files
committed
Add new categorie to load the latest job
1 parent 3a0b341 commit a6fd3eb

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

public/callback/main.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,52 @@ window.onload = async function () {
1313
}
1414

1515
const gitLabProjectId = parameters.get("gitlab_project_id");
16+
17+
const get_latest = parameters.get("latest");
18+
1619
const gitLabPipelineId = parameters.get("gitlab_pipeline_id");
1720
const gitLabJobId = parameters.get("gitlab_job_id");
1821

22+
if(get_latest != 1){
1923
await registerPipeline(gitLabProjectId, gitLabPipelineId, gitLabJobId);
24+
}
2025

2126
if (showDebugInformation) {
2227
await new Promise(r => setTimeout(r, 5000));
2328
}
2429

2530
const token = localStorage.getItem("gitlab-api-token");
2631
if (token) {
27-
window.location = "/software-card/dashboard/";
32+
if(get_latest==1){
33+
await latest(gitLabProjectId, token);
34+
}else{
35+
window.location = "../dashboard/";
36+
}
2837
return;
2938
} else {
3039
alert("Please set up the GitLab connection, then go to the dashboard!");
31-
window.location = "/software-card/gitlab-setup/";
40+
window.location = "../gitlab-setup/";
3241
return;
3342
}
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`;
63+
//gitlab_pipeline_id=618554&gitlab_job_id=2513432
3464
}

public/gitlab-setup/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ window.onload = async function () {
4040
localStorage.setItem("gitlab-name", userData["name"]);
4141
localStorage.setItem("gitlab-api-token", token);
4242

43-
window.location = "./";
43+
window.location = "../";
4444
return;
4545
}
4646
};

public/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta charset="utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77

8-
<link rel="stylesheet" href="/software-card/style.css">
8+
<link rel="stylesheet" href="./style.css">
99
<link rel="icon" href="./pictures/Logo.png" type="image/icon type">
1010

1111
<script type="module" src="./main.js"></script>
@@ -22,13 +22,16 @@ <h3>Welcome<span id="welcome-username"></span></h3>
2222
<li>Set up the <a href="./gitlab-setup/">connection to your GitLab account</a>.</li>
2323
<li>Load an <a href="./callback?gitlab_project_id=17500&gitlab_pipeline_id=570319&gitlab_job_id=2350529">
2424
example CI pipeline</a>.</li>
25+
<li>Load the <a href="./callback?gitlab_project_id=17500&latest=1">
26+
newest CI pipeline</a>.</li>
2527
<li>See your <a href="./dashboard/">dashboard</a>.</li>
2628
<li>See your <a href="./curation/">curation view</a>.</li>
2729
<li>See your <a href="./reporting/">reporting view</a>.</li>
2830
</ol>
2931
</p>
3032
<hr>
3133
<button id="clear-all-data-button">Clear all data</button>
34+
<button id="clear-pipeline-button">Clear pipeline data</button>
3235
</body>
3336

3437
</html>

0 commit comments

Comments
 (0)