@@ -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}
0 commit comments