diff --git a/public/callback/main.js b/public/callback/main.js index 0801b5e..21877c2 100644 --- a/public/callback/main.js +++ b/public/callback/main.js @@ -13,10 +13,15 @@ window.onload = async function () { } 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)); @@ -24,11 +29,36 @@ window.onload = async function () { const token = localStorage.getItem("gitlab-api-token"); if (token) { - window.location = "/software-card/dashboard/"; + 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 = "/software-card/gitlab-setup/"; + 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`; + //gitlab_pipeline_id=618554&gitlab_job_id=2513432 } diff --git a/public/dashboard/main.js b/public/dashboard/main.js index 5431e01..07e56c8 100644 --- a/public/dashboard/main.js +++ b/public/dashboard/main.js @@ -7,7 +7,7 @@ window.onload = async function () { const token = localStorage.getItem("gitlab-api-token"); if (!token) { alert("Please set up the GitLab connection first!"); - window.location = "/"; + window.location = "./"; return; } diff --git a/public/gitlab-setup/main.js b/public/gitlab-setup/main.js index bc278c2..9a2f7d7 100644 --- a/public/gitlab-setup/main.js +++ b/public/gitlab-setup/main.js @@ -40,7 +40,7 @@ window.onload = async function () { localStorage.setItem("gitlab-name", userData["name"]); localStorage.setItem("gitlab-api-token", token); - window.location = "./"; + window.location = "../"; return; } }; diff --git a/public/index.html b/public/index.html index 37534ed..11e3a09 100644 --- a/public/index.html +++ b/public/index.html @@ -5,7 +5,7 @@ - + @@ -22,6 +22,8 @@